Spaces:
Sleeping
Sleeping
Kevin Maik Jablonka
commited on
Commit
·
ff753c0
1
Parent(s):
538c757
initial commit
Browse files- app.py +49 -0
- concatenated_quality-control_011223.json +0 -0
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import json
|
3 |
+
import random
|
4 |
+
# Function to parse the file
|
5 |
+
def parse_file(filepath):
|
6 |
+
with open(filepath) as f:
|
7 |
+
lines = f.readlines()
|
8 |
+
cleaned_lines = []
|
9 |
+
for line in lines:
|
10 |
+
if len(line) > 1:
|
11 |
+
cleaned_lines.append(line)
|
12 |
+
return cleaned_lines
|
13 |
+
|
14 |
+
|
15 |
+
data = parse_file('concatenated_quality-control_011223.json')
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
def update_index(direction, current_index, output_text):
|
20 |
+
if direction == 0:
|
21 |
+
# Random number
|
22 |
+
new_index = random.randint(0, len(data) - 1)
|
23 |
+
new_index = current_index + direction
|
24 |
+
# Ensure the new index is within bounds
|
25 |
+
new_index = max(0, min(new_index, len(data) - 1))
|
26 |
+
output_text = data[int(new_index)]
|
27 |
+
return new_index, output_text
|
28 |
+
|
29 |
+
with gr.Blocks() as demo:
|
30 |
+
gr.Markdown("# Navigate through the contents of different files")
|
31 |
+
output_text = gr.Textbox(label="File Content", value=data[0])
|
32 |
+
btn_previous = gr.Button(value="Previous")
|
33 |
+
btn_next = gr.Button(value="Next")
|
34 |
+
btn_random = gr.Button(value="Random index")
|
35 |
+
|
36 |
+
# Initialize the state
|
37 |
+
current_index = gr.State(0)
|
38 |
+
|
39 |
+
# Invisible Number components to pass direction
|
40 |
+
direction_previous = gr.Number(-1, visible=False)
|
41 |
+
direction_next = gr.Number(1, visible=False)
|
42 |
+
random_number = gr.Number(0, label="Random Number", visible=False)
|
43 |
+
|
44 |
+
btn_previous.click(update_index, inputs=[direction_previous, current_index, output_text], outputs=[current_index, output_text])
|
45 |
+
btn_next.click(update_index, inputs=[direction_next, current_index, output_text], outputs=[current_index, output_text])
|
46 |
+
btn_random.click(update_index, inputs=[random_number, current_index, output_text], outputs=[current_index, output_text])
|
47 |
+
|
48 |
+
if __name__ == "__main__":
|
49 |
+
demo.launch(debug=True)
|
concatenated_quality-control_011223.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|