alpha1ct commited on
Commit
f26d5e0
·
verified ·
1 Parent(s): 9f4d1a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -18
app.py CHANGED
@@ -1,28 +1,21 @@
1
  import gradio as gr
2
- from fastapi import FastAPI
3
- from fastapi.responses import HTMLResponse
4
  import os
5
 
6
- # Create a FastAPI app
7
- app = FastAPI()
8
-
9
- # Serve index.html from the current directory
10
- @app.get("/index.html")
11
- async def get_index_html():
12
  file_path = os.path.join(os.path.dirname(__file__), "index.html")
13
  with open(file_path, "r") as f:
14
- content = f.read()
15
- return HTMLResponse(content=content)
16
 
17
- # Create Gradio app with embedded HTML
18
  def embed_html():
19
- return """
20
- <iframe src='/index.html' width='100%' height='600' allow='fullscreen'></iframe>
21
- """
22
 
23
- with gr.Blocks() as gradio_app:
 
24
  with gr.Tab("Index HTML Tab"):
25
- gr.HTML(embed_html())
26
 
27
  with gr.Tab("Second Tab"):
28
  gr.Textbox(value="Content for the second tab", label="Second Tab Content")
@@ -30,5 +23,5 @@ with gr.Blocks() as gradio_app:
30
  with gr.Tab("Third Tab"):
31
  gr.Textbox(value="Content for the third tab", label="Third Tab Content")
32
 
33
- # Mount the Gradio app to FastAPI
34
- app = gr.mount_gradio_app(app, gradio_app, path="/")
 
1
  import gradio as gr
 
 
2
  import os
3
 
4
+ # Function to read the content of index.html
5
+ def get_index_html():
 
 
 
 
6
  file_path = os.path.join(os.path.dirname(__file__), "index.html")
7
  with open(file_path, "r") as f:
8
+ return f.read()
 
9
 
10
+ # Embed the HTML content directly in the Gradio app
11
  def embed_html():
12
+ html_content = get_index_html()
13
+ return f"<div style='height: 600px;'>{html_content}</div>"
 
14
 
15
+ # Create the Gradio interface with tabs
16
+ with gr.Blocks() as app:
17
  with gr.Tab("Index HTML Tab"):
18
+ gr.HTML(embed_html()) # Use gr.HTML to display the HTML content
19
 
20
  with gr.Tab("Second Tab"):
21
  gr.Textbox(value="Content for the second tab", label="Second Tab Content")
 
23
  with gr.Tab("Third Tab"):
24
  gr.Textbox(value="Content for the third tab", label="Third Tab Content")
25
 
26
+ # Launch the Gradio app
27
+ app.launch()