mandyvarel commited on
Commit
d0b790b
1 Parent(s): bc152d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -24
app.py CHANGED
@@ -1,24 +1,13 @@
1
  from pathlib import Path
2
- from fastapi import FastAPI
3
- from fastapi.staticfiles import StaticFiles
4
- import uvicorn
5
  import gradio as gr
6
  from datetime import datetime
7
  import sys
8
 
9
 
10
- # create a FastAPI app
11
- app = FastAPI()
12
-
13
  # create a static directory to store the static files
14
  static_dir = Path('./static')
15
  static_dir.mkdir(parents=True, exist_ok=True)
16
 
17
- # mount FastAPI StaticFiles server
18
- app.mount("/static", StaticFiles(directory=static_dir), name="static")
19
-
20
- # Gradio stuff
21
-
22
 
23
  def predict(text_input):
24
  file_name = f"{datetime.utcnow().strftime('%s')}.html"
@@ -33,8 +22,8 @@ def predict(text_input):
33
  </h1>
34
  <h3>Filename: {file_name}</h3>
35
  """)
36
- iframe = f"""<iframe src="/static/{file_name}" width="100%" height="500px"></iframe>"""
37
- link = f'<a href="/static/{file_name}" target="_blank">{file_name}</a>'
38
  return link, iframe
39
 
40
 
@@ -54,14 +43,4 @@ The Gradio app generates dynamic HTML files and stores them in a static director
54
 
55
  new_btn.click(fn=predict, inputs=[text_input], outputs=[markdown, html])
56
 
57
- # mount Gradio app to FastAPI app
58
- app = gr.mount_gradio_app(app, block, path="/")
59
-
60
- # serve the app
61
- if __name__ == "__main__":
62
- uvicorn.run(app, host="0.0.0.0", port=7860)
63
-
64
- # run the app with
65
- # python app.py
66
- # or
67
- # uvicorn "app:app" --host "0.0.0.0" --port 7860 --reload
 
1
  from pathlib import Path
 
 
 
2
  import gradio as gr
3
  from datetime import datetime
4
  import sys
5
 
6
 
 
 
 
7
  # create a static directory to store the static files
8
  static_dir = Path('./static')
9
  static_dir.mkdir(parents=True, exist_ok=True)
10
 
 
 
 
 
 
11
 
12
  def predict(text_input):
13
  file_name = f"{datetime.utcnow().strftime('%s')}.html"
 
22
  </h1>
23
  <h3>Filename: {file_name}</h3>
24
  """)
25
+ iframe = f"""<iframe src="file={file_path}" width="100%" height="500px"></iframe>"""
26
+ link = f'<a href="file={file_path}" target="_blank">{file_name}</a>'
27
  return link, iframe
28
 
29
 
 
43
 
44
  new_btn.click(fn=predict, inputs=[text_input], outputs=[markdown, html])
45
 
46
+ block.launch(debug=True, share=True)