Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import gradio as gr
|
3 |
+
from diffusers import DiffusionPipeline
|
4 |
+
|
5 |
+
# Load the pipeline from Hugging Face's model hub
|
6 |
+
pipe = DiffusionPipeline.from_pretrained("THUDM/CogVideoX-2b")
|
7 |
+
|
8 |
+
# Optional: Move the model to GPU for faster processing if available
|
9 |
+
if torch.cuda.is_available():
|
10 |
+
pipe.to("cuda")
|
11 |
+
|
12 |
+
# Define the function that generates the video from the user prompt
|
13 |
+
def generate_video(prompt):
|
14 |
+
# Generate the video
|
15 |
+
video = pipe(prompt).videos[0]
|
16 |
+
# Save the video to a file (Gradio needs a file path to display video)
|
17 |
+
video_path = "generated_video.mp4"
|
18 |
+
video.save(video_path)
|
19 |
+
return video_path
|
20 |
+
|
21 |
+
# Create a Gradio interface with text input for the prompt and video output
|
22 |
+
interface = gr.Interface(
|
23 |
+
fn=generate_video, # The function to generate the video
|
24 |
+
inputs="text", # Text input for the prompt
|
25 |
+
outputs="video", # Video output
|
26 |
+
title="Video Generator", # Title of the Gradio app
|
27 |
+
description="Enter a prompt to generate a video using the diffusion model"
|
28 |
+
)
|
29 |
+
|
30 |
+
# Launch the Gradio app
|
31 |
+
interface.launch()
|