Spaces:
Sleeping
Sleeping
Commit
•
6703d60
1
Parent(s):
33d5737
Update app.py
Browse files
app.py
CHANGED
@@ -2,33 +2,41 @@ import gradio as gr
|
|
2 |
import os
|
3 |
|
4 |
# Function to show HTML content using an iframe
|
5 |
-
def show_html_in_iframe(page_idx):
|
6 |
-
#
|
7 |
-
|
8 |
-
url = f'https://wmtis.s3.eu-west-1.amazonaws.com/test/{html_files[page_idx]}'
|
9 |
iframe_html = f'<iframe src="{url}" width="100%" height="1000"></iframe>'
|
10 |
return iframe_html
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
|
15 |
-
html_files =
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
elif instance_type == 'dev':
|
22 |
-
return dev_html_files
|
23 |
-
elif instance_type == 'test':
|
24 |
-
return test_html_files
|
25 |
|
|
|
26 |
|
27 |
with gr.Blocks() as demo:
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import os
|
3 |
|
4 |
# Function to show HTML content using an iframe
|
5 |
+
def show_html_in_iframe(mode, page_idx):
|
6 |
+
# Update the URL based on the selected mode
|
7 |
+
url = f'https://wmtis.s3.eu-west-1.amazonaws.com/{mode}/{html_files[mode][page_idx]}'
|
|
|
8 |
iframe_html = f'<iframe src="{url}" width="100%" height="1000"></iframe>'
|
9 |
return iframe_html
|
10 |
|
11 |
+
# Load HTML files for both "dev" and "train" directories
|
12 |
+
def load_html_files():
|
13 |
+
modes = ["dev", "train"]
|
14 |
+
html_files = {}
|
15 |
+
for mode in modes:
|
16 |
+
html_files_path = os.path.join("html_files", mode)
|
17 |
+
files = [f for f in os.listdir(html_files_path) if f.endswith('.html')]
|
18 |
+
html_files[mode] = files
|
19 |
+
return html_files
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
html_files = load_html_files()
|
22 |
|
23 |
with gr.Blocks() as demo:
|
24 |
+
# Create a dropdown to choose between "dev" and "train"
|
25 |
+
mode_dropdown = gr.Dropdown(choices=["dev", "train"], label="Mode")
|
26 |
+
|
27 |
+
# Slider for selecting the HTML page; its maximum value is dynamically set based on the selected mode
|
28 |
+
slider = gr.Slider(minimum=0, maximum=1, step=1, label='Data Instance') # Temporary maximum value, will update dynamically
|
29 |
+
|
30 |
+
# Dynamically update the slider's maximum value based on the mode selected
|
31 |
+
def update_slider_options(mode):
|
32 |
+
max_value = len(html_files[mode]) - 1
|
33 |
+
slider.update(maximum=max_value) # Update the slider's maximum value based on the selected mode
|
34 |
+
return max_value # Return the new maximum value for the slider
|
35 |
+
|
36 |
+
mode_dropdown.change(update_slider_options, inputs=[mode_dropdown], outputs=[slider])
|
37 |
+
|
38 |
+
# Update the Gradio interface to include both the mode dropdown and the slider
|
39 |
+
gr.Interface(fn=show_html_in_iframe,
|
40 |
+
inputs=[mode_dropdown, slider],
|
41 |
+
outputs=[gr.HTML()],
|
42 |
+
api_name="HTML Viewer with Mode and Event Listeners").launch()
|