Spaces:
Runtime error
Runtime error
aakash0563
commited on
Commit
·
81c5e3c
1
Parent(s):
d8c2b48
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from diffusers import DiffusionPipeline
|
3 |
+
from diffusers.schedulers import DPMSolverMultistepScheduler
|
4 |
+
import torch
|
5 |
+
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
6 |
+
from diffusers.utils import export_to_video
|
7 |
+
from base64 import b64encode
|
8 |
+
|
9 |
+
# Load pipeline (outside the function for efficiency)
|
10 |
+
pipe = DiffusionPipeline.from_pretrained("damo-vilab/text-to-video-ms-1.7b", torch_dtype=torch.float16, variant="fp16")
|
11 |
+
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
12 |
+
pipe.enable_model_cpu_offload()
|
13 |
+
pipe.enable_vae_slicing()
|
14 |
+
|
15 |
+
def Generate_video(prompt, video_duration_seconds):
|
16 |
+
num_frames = video_duration_seconds * 10
|
17 |
+
video_frames = pipe(prompt=prompt, negative_prompt="low quality",
|
18 |
+
num_inference_steps=25, num_frames=num_frames).frames
|
19 |
+
video_path = export_to_video(video_frames) # Assuming you have this function defined
|
20 |
+
return video_path
|
21 |
+
|
22 |
+
# Create Gradio interface
|
23 |
+
iface = gr.Interface(
|
24 |
+
fn=Generate_video,
|
25 |
+
inputs=[
|
26 |
+
gr.Textbox(lines=5, label="Prompt"),
|
27 |
+
gr.Number(label="Video Duration (seconds)", value=3),
|
28 |
+
],
|
29 |
+
outputs=gr.Video(label="Generated Video"),
|
30 |
+
)
|
31 |
+
|
32 |
+
# Launch the app
|
33 |
+
iface.launch()
|