Commit ·
bb8682e
1
Parent(s): d2d78c7
Initial Commit
Browse files- app.py +33 -26
- requirements.txt +2 -3
app.py
CHANGED
|
@@ -1,31 +1,38 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from diffusers import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
#
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
fn=generate_video,
|
| 23 |
-
inputs=
|
| 24 |
-
outputs=
|
| 25 |
title="Text-to-Video Generator",
|
| 26 |
-
description="
|
| 27 |
)
|
| 28 |
|
| 29 |
-
# Launch the app
|
| 30 |
-
|
| 31 |
-
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from diffusers import CogVideoXPipeline # Import the appropriate text-to-video pipeline
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Load your text-to-video model (replace with the actual model)
|
| 6 |
+
model_name = "THUDM/CogVideoX-2b" # Example model name
|
| 7 |
+
device = "cuda" if torch.cuda.is_available() else "cpu" # Check for GPU availability
|
| 8 |
+
|
| 9 |
+
# Load the model
|
| 10 |
+
text_video_pipe = CogVideoXPipeline.from_pretrained(
|
| 11 |
+
model_name,
|
| 12 |
+
torch_dtype=torch.float16
|
| 13 |
+
).to(device)
|
| 14 |
+
|
| 15 |
+
# Define the function for generating video from text
|
| 16 |
+
def generate_video(text_prompt):
|
| 17 |
+
# Generate the video using the text prompt
|
| 18 |
+
video = text_video_pipe(text_prompt, num_inference_steps=50, guidance_scale=7.5).videos
|
| 19 |
+
|
| 20 |
+
# Define the video file path to save the generated video
|
| 21 |
+
video_path = "generated_video.mp4"
|
| 22 |
+
|
| 23 |
+
# Save the video (you may need to adjust this depending on your pipeline's output)
|
| 24 |
+
video[0].save(video_path) # Assuming the output is a list of videos
|
| 25 |
+
|
| 26 |
+
return video_path
|
| 27 |
+
|
| 28 |
+
# Gradio Interface
|
| 29 |
+
iface = gr.Interface(
|
| 30 |
fn=generate_video,
|
| 31 |
+
inputs="text",
|
| 32 |
+
outputs="video",
|
| 33 |
title="Text-to-Video Generator",
|
| 34 |
+
description="Enter a prompt to generate a video."
|
| 35 |
)
|
| 36 |
|
| 37 |
+
# Launch the Gradio app
|
| 38 |
+
iface.launch()
|
|
|
requirements.txt
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
diffusers
|
| 2 |
gradio
|
| 3 |
-
torch
|
| 4 |
transformers
|
| 5 |
-
|
|
|
|
|
|
|
|
|
| 1 |
gradio
|
|
|
|
| 2 |
transformers
|
| 3 |
+
torch
|
| 4 |
+
diffusers
|