lovodkin93 commited on
Commit
281253d
·
verified ·
1 Parent(s): 089df08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -43
app.py CHANGED
@@ -1,48 +1,42 @@
1
- import math
2
- import os
3
  import gradio as gr
4
 
5
- # Path to the directory containing HTML files
6
- html_files_path = os.path.join("html_files", "test")
7
- html_files = [f for f in os.listdir(html_files_path) if f.endswith('.html')]
8
-
9
-
10
- batch_size = 3
11
-
12
- # Function to read HTML file content
13
- def read_html(file_path):
14
- with open(file_path, 'r', encoding='utf-8') as file:
15
- return file.read()
16
-
17
- # Function to show three HTML files based on slider value
18
- def show_htmls(index):
19
- # Calculate the index for the HTML files to show
20
- start_index = index * batch_size
21
- end_index = start_index + batch_size
22
- selected_files = html_files[start_index:end_index]
23
-
24
- # Read and concatenate the content of the selected HTML files
25
- html_content = ""
26
- for file_name in selected_files:
27
- file_path = os.path.join(html_files_path, file_name)
28
- html_content += read_html(file_path) + "<hr>" # Adding a horizontal line between HTML contents
29
-
30
- return html_content
31
-
32
- # Calculate the maximum value for the slider based on the number of HTML files
33
- max_slider_value = len(html_files) // 3 - 1 if len(html_files) % 3 == 0 else len(html_files) // 3
34
-
35
- # Create a slider for selecting the group of HTML files
36
- num_batches = math.ceil(len(html_files) / batch_size)
37
- slider = gr.Slider(minimum=0, maximum=num_batches, step=1, label=f'Page (out of {num_batches})')
38
-
39
- # Create an Interface
40
- iface = gr.Interface(fn=show_htmls,
41
  inputs=slider,
42
  outputs=gr.HTML(),
43
- title="HTML Files Viewer",
44
- description="Slide to view different groups of HTML files.",
45
- live=True) # Use live mode to automatically update the output
46
 
47
- if __name__ == "__main__":
48
- iface.launch()
 
 
 
1
  import gradio as gr
2
 
3
+ # List of HTML files
4
+ html_files = [
5
+ '182.html', '141.html', '116.html', '100.html', '157.html', '120.html',
6
+ '177.html', '161.html', '136.html', '15.html', '14.html', '137.html',
7
+ '160.html', '176.html', '121.html', '156.html', '101.html', '117.html',
8
+ '140.html', '18.html', '183.html', '126.html', '171.html', '167.html',
9
+ '188.html', '130.html', '13.html', '184.html', '147.html', '110.html',
10
+ '106.html', '151.html', '150.html', '107.html', '111.html', '146.html',
11
+ '185.html', '12.html', '131.html', '166.html', '170.html', '127.html',
12
+ '108.html', '11.html', '149.html', '1.html', '132.html', '165.html',
13
+ '173.html', '124.html', '153.html', '104.html', '112.html', '145.html',
14
+ '186.html', '169.html', '128.html', '129.html', '187.html', '168.html',
15
+ '144.html', '113.html', '105.html', '152.html', '125.html', '172.html',
16
+ '164.html', '0.html', '133.html', '10.html', '148.html', '109.html',
17
+ '155.html', '102.html', '114.html', '143.html', '138.html', '180.html',
18
+ '179.html', '159.html', '118.html', '17.html', '134.html', '163.html',
19
+ '175.html', '122.html', '123.html', '174.html', '162.html', '135.html',
20
+ '16.html', '119.html', '158.html', '178.html', '181.html', '139.html',
21
+ '142.html', '115.html', '103.html', '154.html'
22
+ ]
23
+
24
+ # Function to show HTML content using an iframe
25
+ def show_html_in_iframe(page_idx):
26
+ # Construct the URL using the selected index
27
+ url = f'https://wmtis.s3.eu-west-1.amazonaws.com/test/{html_files[page_idx]}'
28
+ iframe_html = f'<iframe src="{url}" width="100%" height="2000"></iframe>'
29
+ return iframe_html
30
+
31
+ # Create a slider component to select the HTML page
32
+ slider = gr.Slider(minimum=0, maximum=len(html_files)-1, step=1, label='Page')
33
+
34
+ # Create the Gradio interface
35
+ iface = gr.Interface(fn=show_html_in_iframe,
 
 
 
36
  inputs=slider,
37
  outputs=gr.HTML(),
38
+ title="HTML Viewer with Event Listeners",
39
+ description="Displays HTML content with JavaScript event listeners via an iframe.")
 
40
 
41
+ # Display the interface
42
+ iface.launch()