Trying to make a demo, does this work?
#1
by
meg
HF staff
- opened
app.py
CHANGED
@@ -1,52 +1,17 @@
|
|
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.
|
|
|
|
|
|
|
13 |
|
14 |
-
|
|
|
15 |
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
templates = Jinja2Templates(directory="templates")
|
20 |
-
|
21 |
-
names = sorted(os.listdir("./demos"))
|
22 |
-
|
23 |
-
|
24 |
-
@app.get("/")
|
25 |
-
def index(request: Request):
|
26 |
-
names = [[p[0], p[2]] for p in all_demos]
|
27 |
-
return templates.TemplateResponse("index.html", {"request": request, "names": names,
|
28 |
-
"initial_demo": names[0][0], "is_space": get_space()})
|
29 |
-
|
30 |
-
|
31 |
-
all_demos = []
|
32 |
-
demo_module = None
|
33 |
-
for p in sorted(os.listdir("./demos")):
|
34 |
-
old_path = copy.deepcopy(sys.path)
|
35 |
-
sys.path = [os.path.join(demo_dir, p)] + sys.path
|
36 |
-
try: # Some demos may not be runnable because of 429 timeouts, etc.
|
37 |
-
if demo_module is None:
|
38 |
-
demo_module = importlib.import_module(f"run")
|
39 |
-
else:
|
40 |
-
demo_module = importlib.reload(demo_module)
|
41 |
-
all_demos.append((p, demo_module.demo.queue(), False))
|
42 |
-
except Exception as e:
|
43 |
-
with gr.Blocks() as demo:
|
44 |
-
gr.Markdown(f"Error loading demo: {e}")
|
45 |
-
all_demos.append((p, demo, True))
|
46 |
-
|
47 |
-
for demo_name, demo, _ in all_demos:
|
48 |
-
app = gr.mount_gradio_app(app, demo, f"/demo/{demo_name}")
|
49 |
-
|
50 |
|
51 |
if __name__ == "__main__":
|
52 |
-
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
a = os.path.join(os.path.dirname(__file__), "files/a.mp4") # Video
|
5 |
+
b = os.path.join(os.path.dirname(__file__), "files/b.mp4") # Video
|
6 |
+
w1 = os.path.join(os.path.dirname(__file__), "files/w1.jpg") # Watermark
|
7 |
+
w2 = os.path.join(os.path.dirname(__file__), "files/w2.png") # Watermark
|
8 |
|
9 |
+
def generate_video(original_video, watermark_file):
|
10 |
+
return gr.Video(a, watermark_file=watermark_file)
|
11 |
|
12 |
|
13 |
+
demo = gr.Interface(generate_video, [gr.Textbox(), gr.File()], gr.Video(),
|
14 |
+
examples=[[a, w1], [b, w2]])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
if __name__ == "__main__":
|
17 |
+
demo.launch()
|