Spaces:
Running
Running
Commit
·
72d1162
1
Parent(s):
de48036
created application
Browse files- app.py +54 -0
- requirments.txt +4 -0
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import I2VGenXLPipeline
|
4 |
+
from diffusers.utils import export_to_gif, load_image
|
5 |
+
|
6 |
+
def generate_video(prompt, image_url, negative_prompt, num_inference_steps, guidance_scale, seed):
|
7 |
+
try:
|
8 |
+
# Load pipeline
|
9 |
+
pipeline = I2VGenXLPipeline.from_pretrained("ali-vilab/i2vgen-xl", torch_dtype=torch.float16, variant="fp16")
|
10 |
+
pipeline.enable_model_cpu_offload()
|
11 |
+
|
12 |
+
# Load image
|
13 |
+
image = load_image(image_url).convert("RGB")
|
14 |
+
|
15 |
+
# Set random seed
|
16 |
+
generator = None if seed == -1 else torch.manual_seed(seed)
|
17 |
+
|
18 |
+
# Generate frames
|
19 |
+
result = pipeline(
|
20 |
+
prompt=prompt,
|
21 |
+
image=image,
|
22 |
+
num_inference_steps=num_inference_steps,
|
23 |
+
negative_prompt=negative_prompt,
|
24 |
+
guidance_scale=guidance_scale,
|
25 |
+
generator=generator,
|
26 |
+
).frames[0]
|
27 |
+
|
28 |
+
# Export to GIF
|
29 |
+
gif_path = "i2v_output.gif"
|
30 |
+
export_to_gif(result, gif_path)
|
31 |
+
|
32 |
+
return gif_path
|
33 |
+
except Exception as e:
|
34 |
+
return f"An error occurred: {e}"
|
35 |
+
|
36 |
+
# Gradio Interface
|
37 |
+
interface = gr.Interface(
|
38 |
+
fn=generate_video,
|
39 |
+
inputs=[
|
40 |
+
gr.Textbox(label="Enter your prompt", lines=2, placeholder="Describe your desired video."),
|
41 |
+
gr.Textbox(label="Enter image URL", placeholder="Paste the URL of the input image."),
|
42 |
+
gr.Textbox(label="Enter negative prompt (optional)", placeholder="Describe undesired aspects (e.g., blurry, distorted)."),
|
43 |
+
gr.Slider(label="Number of Inference Steps", minimum=10, maximum=100, value=50, step=1),
|
44 |
+
gr.Slider(label="Guidance Scale", minimum=1.0, maximum=20.0, value=9.0, step=0.1),
|
45 |
+
gr.Number(label="Seed (set to -1 for random)", value=8888),
|
46 |
+
],
|
47 |
+
outputs=gr.Image(label="Generated Video (GIF)", type="filepath"),
|
48 |
+
title="Image-to-Video Generator",
|
49 |
+
description="Generate videos from text prompts and input images using AI.",
|
50 |
+
article="Made by: Mostafa Hazem, Daiee Elchazly, Mohamed Mostafa, Noreen Hamdy"
|
51 |
+
)
|
52 |
+
|
53 |
+
if __name__ == "__main__":
|
54 |
+
interface.launch()
|
requirments.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
diffusers
|
3 |
+
streamlit
|
4 |
+
torch
|