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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -24
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
- # html_files = get_html_files_list(curr_split)
7
- # Construct the URL using the selected index
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
- # Example lists of HTML files for 'test' and 'dev' instances
13
- # train_html_files = [f for f in os.listdir(os.path.join("html_files", "train")) if f.endswith('.html')]
14
- # dev_html_files = [f for f in os.listdir(os.path.join("html_files", "dev")) if f.endswith('.html')]
15
- html_files = [f for f in os.listdir(os.path.join("html_files", "test")) if f.endswith('.html')]
16
-
17
- # Function to return the appropriate list based on instance type
18
- def get_html_files_list(instance_type):
19
- if instance_type == 'train':
20
- return train_html_files
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
- slider = gr.Slider(minimum=0, maximum=len(html_files)-1, step=1, label='Data Instance')
29
-
30
- # Create the Gradio interface
31
- slider.release(show_html_in_iframe, inputs=[slider], outputs=[gr.HTML()], api_name="HTML Viewer with Event Listeners")
32
-
33
- # Display the interface
34
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
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()