Spaces:
Sleeping
Sleeping
Kevin Maik Jablonka
commited on
Commit
·
b19335d
1
Parent(s):
ff753c0
start
Browse files
app.py
CHANGED
@@ -1,6 +1,8 @@
|
|
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:
|
@@ -12,8 +14,7 @@ def parse_file(filepath):
|
|
12 |
return cleaned_lines
|
13 |
|
14 |
|
15 |
-
data = parse_file(
|
16 |
-
|
17 |
|
18 |
|
19 |
def update_index(direction, current_index, output_text):
|
@@ -26,24 +27,37 @@ def update_index(direction, current_index, output_text):
|
|
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(
|
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(
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
if __name__ == "__main__":
|
49 |
-
demo.launch(debug=True)
|
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
import random
|
4 |
+
|
5 |
+
|
6 |
# Function to parse the file
|
7 |
def parse_file(filepath):
|
8 |
with open(filepath) as f:
|
|
|
14 |
return cleaned_lines
|
15 |
|
16 |
|
17 |
+
data = parse_file("concatenated_quality-control_011223.json")
|
|
|
18 |
|
19 |
|
20 |
def update_index(direction, current_index, output_text):
|
|
|
27 |
output_text = data[int(new_index)]
|
28 |
return new_index, output_text
|
29 |
|
30 |
+
|
31 |
with gr.Blocks() as demo:
|
32 |
gr.Markdown("# Navigate through the contents of different files")
|
33 |
+
output_text = gr.Textbox(label="File Content", value=data[0], show_copy_button=True)
|
34 |
btn_previous = gr.Button(value="Previous")
|
35 |
btn_next = gr.Button(value="Next")
|
36 |
btn_random = gr.Button(value="Random index")
|
37 |
|
38 |
# Initialize the state
|
39 |
+
current_index = gr.State(1)
|
40 |
|
41 |
# Invisible Number components to pass direction
|
42 |
direction_previous = gr.Number(-1, visible=False)
|
43 |
direction_next = gr.Number(1, visible=False)
|
44 |
random_number = gr.Number(0, label="Random Number", visible=False)
|
45 |
|
46 |
+
btn_previous.click(
|
47 |
+
update_index,
|
48 |
+
inputs=[direction_previous, current_index, output_text],
|
49 |
+
outputs=[current_index, output_text],
|
50 |
+
)
|
51 |
+
btn_next.click(
|
52 |
+
update_index,
|
53 |
+
inputs=[direction_next, current_index, output_text],
|
54 |
+
outputs=[current_index, output_text],
|
55 |
+
)
|
56 |
+
btn_random.click(
|
57 |
+
update_index,
|
58 |
+
inputs=[random_number, current_index, output_text],
|
59 |
+
outputs=[current_index, output_text],
|
60 |
+
)
|
61 |
|
62 |
if __name__ == "__main__":
|
63 |
+
demo.launch(debug=True)
|