Commit ·
c4da1f7
1
Parent(s): 89b4758
Initial Commit
Browse files- app.py +27 -2
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
|
|
| 1 |
from diffusers import DiffusionPipeline
|
| 2 |
|
|
|
|
| 3 |
pipe = DiffusionPipeline.from_pretrained("THUDM/CogVideoX-5b")
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
from diffusers import DiffusionPipeline
|
| 3 |
|
| 4 |
+
# Load the text-to-video model from Hugging Face (CogVideoX-5b)
|
| 5 |
pipe = DiffusionPipeline.from_pretrained("THUDM/CogVideoX-5b")
|
| 6 |
|
| 7 |
+
# Define a function that generates a video based on the input prompt
|
| 8 |
+
def generate_video(prompt):
|
| 9 |
+
# Generate video frames (or single image) based on the prompt
|
| 10 |
+
result = pipe(prompt)
|
| 11 |
+
if hasattr(result, "videos"):
|
| 12 |
+
video = result.videos[0] # Access the first generated video if available
|
| 13 |
+
return video
|
| 14 |
+
elif hasattr(result, "images"):
|
| 15 |
+
image = result.images[0] # Fallback to first generated image if video is not available
|
| 16 |
+
return image
|
| 17 |
+
else:
|
| 18 |
+
return None
|
| 19 |
+
|
| 20 |
+
# Create a Gradio Interface
|
| 21 |
+
interface = gr.Interface(
|
| 22 |
+
fn=generate_video,
|
| 23 |
+
inputs=gr.Textbox(label="Enter a prompt for video generation", placeholder="Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"),
|
| 24 |
+
outputs=gr.Video(label="Generated Video") if hasattr(pipe, "videos") else gr.Image(label="Generated Image"),
|
| 25 |
+
title="Text-to-Video Generator",
|
| 26 |
+
description="Generate a short video or image based on a textual prompt using Hugging Face's CogVideo model."
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# Launch the app
|
| 30 |
+
if __name__ == "__main__":
|
| 31 |
+
interface.launch()
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
|
|
|
|
|
|
| 1 |
+
diffusers
|
| 2 |
+
gradio
|