Commit 3: Add 35 file(s)
Browse files- requirements.txt +2 -2
- run.py +54 -33
requirements.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
gradio-client @ git+https://github.com/gradio-app/gradio@
|
2 |
-
https://gradio-pypi-previews.s3.amazonaws.com/
|
3 |
pypistats==1.1.0
|
4 |
plotly
|
5 |
matplotlib
|
|
|
1 |
+
gradio-client @ git+https://github.com/gradio-app/gradio@9e2a6225c0bedc17e9dc1a2e41caa1fba49f42ba#subdirectory=client/python
|
2 |
+
https://gradio-pypi-previews.s3.amazonaws.com/9e2a6225c0bedc17e9dc1a2e41caa1fba49f42ba/gradio-5.14.0-py3-none-any.whl
|
3 |
pypistats==1.1.0
|
4 |
plotly
|
5 |
matplotlib
|
run.py
CHANGED
@@ -1,36 +1,57 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
if __name__ == "__main__":
|
36 |
-
|
|
|
1 |
+
import importlib
|
2 |
import gradio as gr
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
import copy
|
6 |
+
import pathlib
|
7 |
+
from fastapi import FastAPI, Request
|
8 |
+
from fastapi.templating import Jinja2Templates
|
9 |
+
import uvicorn
|
10 |
+
from gradio.utils import get_space
|
11 |
+
|
12 |
+
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
13 |
+
|
14 |
+
demo_dir = pathlib.Path(__file__).parent / "demos"
|
15 |
+
|
16 |
+
app = FastAPI()
|
17 |
+
|
18 |
+
templates = Jinja2Templates(directory="templates")
|
19 |
+
|
20 |
+
names = sorted(os.listdir("./demos"))
|
21 |
+
|
22 |
+
|
23 |
+
@app.get("/")
|
24 |
+
def index(request: Request):
|
25 |
+
names = [[p[0], p[2]] for p in all_demos]
|
26 |
+
return templates.TemplateResponse(
|
27 |
+
"index.html",
|
28 |
+
{
|
29 |
+
"request": request,
|
30 |
+
"names": names,
|
31 |
+
"initial_demo": names[0][0],
|
32 |
+
"is_space": get_space(),
|
33 |
+
},
|
34 |
+
)
|
35 |
+
|
36 |
+
|
37 |
+
all_demos = []
|
38 |
+
demo_module = None
|
39 |
+
for p in sorted(os.listdir("./demos")):
|
40 |
+
old_path = copy.deepcopy(sys.path)
|
41 |
+
sys.path = [os.path.join(demo_dir, p)] + sys.path
|
42 |
+
try: # Some demos may not be runnable because of 429 timeouts, etc.
|
43 |
+
if demo_module is None:
|
44 |
+
demo_module = importlib.import_module("run")
|
45 |
+
else:
|
46 |
+
demo_module = importlib.reload(demo_module)
|
47 |
+
all_demos.append((p, demo_module.demo, False))
|
48 |
+
except Exception as e:
|
49 |
+
with gr.Blocks() as demo:
|
50 |
+
gr.Markdown(f"Error loading demo: {e}")
|
51 |
+
all_demos.append((p, demo, True))
|
52 |
+
|
53 |
+
for demo_name, demo, _ in all_demos:
|
54 |
+
app = gr.mount_gradio_app(app, demo, f"/demo/{demo_name}")
|
55 |
|
56 |
if __name__ == "__main__":
|
57 |
+
uvicorn.run(app, port=7860, host="0.0.0.0")
|