Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import DiffusionPipeline
|
4 |
+
|
5 |
+
# Load the model and move to GPU if available
|
6 |
+
model_name = "ByteDance/AnimateDiff-Lightning"
|
7 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
+
pipe = DiffusionPipeline.from_pretrained(model_name)
|
9 |
+
pipe = pipe.to(device)
|
10 |
+
|
11 |
+
def generate_video(prompt):
|
12 |
+
# Generate video (replace with actual method for your model)
|
13 |
+
result = pipe(prompt)
|
14 |
+
# Assuming the model returns a list of videos or a video object
|
15 |
+
# Adjust this based on the actual output
|
16 |
+
video = result.videos[0] # or result['videos'][0]
|
17 |
+
# Save video to file
|
18 |
+
video_path = "generated_video.mp4"
|
19 |
+
video.save(video_path)
|
20 |
+
return video_path
|
21 |
+
|
22 |
+
with gr.Blocks() as demo:
|
23 |
+
gr.Markdown("# Text to Video Generation")
|
24 |
+
prompt_input = gr.Textbox(label="Enter your prompt", lines=2, placeholder="A spaceship in space, neon colors")
|
25 |
+
generate_button = gr.Button("Generate Video")
|
26 |
+
video_output = gr.Video(label="Generated Video")
|
27 |
+
|
28 |
+
generate_button.click(
|
29 |
+
fn=generate_video,
|
30 |
+
inputs=prompt_input,
|
31 |
+
outputs=video_output
|
32 |
+
)
|
33 |
+
|
34 |
+
demo.launch()
|