lovodkin93 commited on
Commit
c695947
1 Parent(s): 6703d60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -33
app.py CHANGED
@@ -2,41 +2,22 @@ import gradio as gr
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()
 
2
  import os
3
 
4
  # Function to show HTML content using an iframe
5
+ def show_html_in_iframe(page_idx):
6
+ # Construct the URL using the selected index
7
+ url = f'https://wmtis.s3.eu-west-1.amazonaws.com/train/{html_files[page_idx]}'
8
  iframe_html = f'<iframe src="{url}" width="100%" height="1000"></iframe>'
9
  return iframe_html
10
 
11
+ # Path to the directory containing HTML files
12
+ html_files_path = os.path.join("html_files", "train")
13
+ html_files = [f for f in os.listdir(html_files_path) if f.endswith('.html')]
 
 
 
 
 
 
 
 
14
 
15
  with gr.Blocks() as demo:
16
+ # Create a slider component to select the HTML page
17
+ slider = gr.Slider(minimum=0, maximum=len(html_files)-1, step=1, label='Data Instance')
18
+
19
+ # Create the Gradio interface
20
+ slider.release(show_html_in_iframe, inputs=[slider], outputs=[gr.HTML()], api_name="HTML Viewer with Event Listeners")
21
+
22
+ # Display the interface
23
+ demo.launch()