freddyaboulton HF staff commited on
Commit
adf4dc2
1 Parent(s): 8d0c3d5

Commit 3: Add 30 file(s)

Browse files
Files changed (2) hide show
  1. requirements.txt +2 -2
  2. run.py +48 -0
requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
- gradio-client @ git+https://github.com/gradio-app/gradio@0c52deb60390646fa8a09bddb86aaab6caccf967#subdirectory=client/python
2
- https://gradio-pypi-previews.s3.amazonaws.com/0c52deb60390646fa8a09bddb86aaab6caccf967/gradio-4.44.0-py3-none-any.whl
3
  pypistats==1.1.0
4
  plotly
5
  altair
 
1
+ gradio-client @ git+https://github.com/gradio-app/gradio@9a59f854f94cddf7a160f46734e1860668f4535a#subdirectory=client/python
2
+ https://gradio-pypi-previews.s3.amazonaws.com/9a59f854f94cddf7a160f46734e1860668f4535a/gradio-4.44.0-py3-none-any.whl
3
  pypistats==1.1.0
4
  plotly
5
  altair
run.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ @app.get("/")
23
+ def index(request: Request):
24
+ names = [[p[0], p[2]] for p in all_demos]
25
+ return templates.TemplateResponse("index.html", {"request": request, "names": names,
26
+ "initial_demo": names[0][0], "is_space": get_space()})
27
+
28
+ all_demos = []
29
+ demo_module = None
30
+ for p in sorted(os.listdir("./demos")):
31
+ old_path = copy.deepcopy(sys.path)
32
+ sys.path = [os.path.join(demo_dir, p)] + sys.path
33
+ try: # Some demos may not be runnable because of 429 timeouts, etc.
34
+ if demo_module is None:
35
+ demo_module = importlib.import_module("run")
36
+ else:
37
+ demo_module = importlib.reload(demo_module)
38
+ all_demos.append((p, demo_module.demo, False))
39
+ except Exception as e:
40
+ with gr.Blocks() as demo:
41
+ gr.Markdown(f"Error loading demo: {e}")
42
+ all_demos.append((p, demo, True))
43
+
44
+ for demo_name, demo, _ in all_demos:
45
+ app = gr.mount_gradio_app(app, demo, f"/demo/{demo_name}")
46
+
47
+ if __name__ == "__main__":
48
+ uvicorn.run(app, port=7860, host="0.0.0.0")