eggman-poff commited on
Commit
caf4acf
·
verified ·
1 Parent(s): c0adad8
Files changed (1) hide show
  1. app.py +41 -4
app.py CHANGED
@@ -1,7 +1,44 @@
1
  import gradio as gr
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import torch
3
+ import tempfile
4
+ from diffusers import StableVideoDiffusionPipeline
5
+ from diffusers.utils import export_to_video
6
 
7
+ # Use the official SVD-XT img2vid-xt model
8
+ MODEL = "stabilityai/stable-video-diffusion-img2vid-xt"
9
 
10
+ # Load pipeline in half-precision on GPU
11
+ pipe = StableVideoDiffusionPipeline.from_pretrained(
12
+ MODEL, torch_dtype=torch.float16
13
+ ).to("cuda")
14
+
15
+ def infer(first_image, last_image, prompt, guidance=7.5, frames=25):
16
+ # Generate the in-between frames
17
+ video = pipe(
18
+ image=first_image,
19
+ last_image=last_image,
20
+ prompt=prompt,
21
+ guidance_scale=guidance,
22
+ num_frames=frames
23
+ ).frames
24
+ # Export as MP4 to a temp file
25
+ mp4_path = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name
26
+ export_to_video(video, mp4_path, fps=15)
27
+ return mp4_path # Gradio will auto-encode this to base64 for the API
28
+
29
+ # Build a minimal Gradio interface
30
+ demo = gr.Interface(
31
+ fn=infer,
32
+ inputs=[
33
+ gr.Image(type="pil", label="Start frame"),
34
+ gr.Image(type="pil", label="End frame"),
35
+ gr.Textbox(placeholder="Prompt (optional)"),
36
+ gr.Slider(0, 12, 7.5, label="Guidance scale"),
37
+ gr.Slider(8, 48, 25, step=1, label="Num frames"),
38
+ ],
39
+ outputs="video",
40
+ title="Eggman – 2-Frame SVD API"
41
+ )
42
+
43
+ # Enable the REST API
44
+ demo.queue(concurrency_count=1).launch(show_api=True)