app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from diffusers import StableDiffusionPipeline
|
| 3 |
+
import ffmpeg
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
# Retrieve the token from Hugging Face secrets
|
| 7 |
+
token = os.getenv("HUGGINGFACE_TOKEN")
|
| 8 |
+
|
| 9 |
+
print(f"Using Hugging Face Token: {os.getenv('HUGGINGFACE_TOKEN')}")
|
| 10 |
+
|
| 11 |
+
model = StableDiffusionPipeline.from_pretrained(
|
| 12 |
+
"runwayml/stable-diffusion-v1-5"
|
| 13 |
+
)
|
| 14 |
+
model.to("cpu") # Use CPU since GPU is not available
|
| 15 |
+
|
| 16 |
+
def generate_video(prompt):
|
| 17 |
+
# Generate frames
|
| 18 |
+
frames = []
|
| 19 |
+
for i in range(5): # Adjust the number of frames for your video
|
| 20 |
+
image = model(prompt).images[0]
|
| 21 |
+
frame_path = f"frame_{i}.png"
|
| 22 |
+
image.save(frame_path)
|
| 23 |
+
frames.append(frame_path)
|
| 24 |
+
|
| 25 |
+
# Combine frames into a video
|
| 26 |
+
output_video = "output.mp4"
|
| 27 |
+
(
|
| 28 |
+
ffmpeg
|
| 29 |
+
.input("frame_%d.png", framerate=1) # Adjust framerate
|
| 30 |
+
.output(output_video)
|
| 31 |
+
.run(overwrite_output=True)
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
# Clean up frames
|
| 35 |
+
for frame in frames:
|
| 36 |
+
os.remove(frame)
|
| 37 |
+
|
| 38 |
+
return output_video # Path to the generated video
|
| 39 |
+
|
| 40 |
+
# Gradio interface
|
| 41 |
+
with gr.Blocks() as demo:
|
| 42 |
+
gr.Markdown("# AI Video Generator")
|
| 43 |
+
prompt_input = gr.Textbox(label="Enter your video prompt", placeholder="Type something creative...")
|
| 44 |
+
video_output = gr.File(label="Download Your Video")
|
| 45 |
+
generate_button = gr.Button("Generate Video")
|
| 46 |
+
|
| 47 |
+
generate_button.click(fn=generate_video, inputs=prompt_input, outputs=video_output)
|
| 48 |
+
|
| 49 |
+
demo.launch()
|