hmb HF Staff commited on
Commit
2acfccd
·
verified ·
1 Parent(s): 4d831c0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import tempfile
5
+
6
+ import gradio as gr
7
+ from gradio.data_classes import FileData
8
+
9
+ # Placeholder "video" so the runtime MIME-upgrade path has something to render.
10
+ # The bytes don't need to be a valid mp4 — the workflow decides "this is video"
11
+ # from mime_type. If you want a real playable video, replace this with a real .mp4.
12
+ SAMPLE_PATH = os.path.join(tempfile.gettempdir(), "gr_api_any_repro.mp4")
13
+ if not os.path.exists(SAMPLE_PATH):
14
+ with open(SAMPLE_PATH, "wb") as f:
15
+ f.write(b"\x00" * 1024)
16
+
17
+
18
+ def generate(
19
+ prompt: str,
20
+ seed: float = 42,
21
+ steps: int = 6,
22
+ ) -> tuple[FileData, str, str]:
23
+ return (
24
+ FileData(path=SAMPLE_PATH, mime_type="video/mp4"),
25
+ f"Report: prompt={prompt!r} seed={int(seed)} steps={steps}",
26
+ f"{prompt} (refined)",
27
+ )
28
+
29
+
30
+ with gr.Blocks() as demo:
31
+ gr.api(generate, api_name="generate")
32
+
33
+
34
+ if __name__ == "__main__":
35
+ demo.launch()