Update app.py
Browse files
app.py
CHANGED
@@ -3,9 +3,7 @@ import torch
|
|
3 |
from diffusers import I2VGenXLPipeline
|
4 |
from diffusers.utils import export_to_gif, load_image
|
5 |
import tempfile
|
6 |
-
import spaces
|
7 |
|
8 |
-
@spaces.GPU
|
9 |
def initialize_pipeline(device):
|
10 |
# Initialize the pipeline with CUDA support
|
11 |
pipeline = I2VGenXLPipeline.from_pretrained("ali-vilab/i2vgen-xl", torch_dtype=torch.float16, variant="fp16")
|
@@ -51,25 +49,45 @@ def generate_gif(prompt, image, negative_prompt, num_inference_steps, guidance_s
|
|
51 |
|
52 |
# Create the Gradio interface with tabs
|
53 |
with gr.Blocks() as demo:
|
54 |
-
with gr.
|
55 |
-
with gr.
|
56 |
-
with gr.
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
|
65 |
-
|
66 |
-
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
# Launch the interface
|
75 |
-
demo.launch()
|
|
|
3 |
from diffusers import I2VGenXLPipeline
|
4 |
from diffusers.utils import export_to_gif, load_image
|
5 |
import tempfile
|
|
|
6 |
|
|
|
7 |
def initialize_pipeline(device):
|
8 |
# Initialize the pipeline with CUDA support
|
9 |
pipeline = I2VGenXLPipeline.from_pretrained("ali-vilab/i2vgen-xl", torch_dtype=torch.float16, variant="fp16")
|
|
|
49 |
|
50 |
# Create the Gradio interface with tabs
|
51 |
with gr.Blocks() as demo:
|
52 |
+
with gr.Tabs():
|
53 |
+
with gr.TabItem("Generate from Text"):
|
54 |
+
with gr.Row():
|
55 |
+
with gr.Column():
|
56 |
+
text_prompt = gr.Textbox(lines=2, placeholder="Enter your prompt here...", label="Prompt")
|
57 |
+
text_negative_prompt = gr.Textbox(lines=2, placeholder="Enter your negative prompt here...", label="Negative Prompt")
|
58 |
+
text_num_inference_steps = gr.Slider(1, 100, step=1, value=50, label="Number of Inference Steps")
|
59 |
+
text_guidance_scale = gr.Slider(1, 20, step=0.1, value=9.0, label="Guidance Scale")
|
60 |
+
text_seed = gr.Number(label="Seed", value=8888)
|
61 |
+
text_generate_button = gr.Button("Generate GIF")
|
62 |
|
63 |
+
with gr.Column():
|
64 |
+
text_output_video = gr.Video(label="Generated GIF")
|
65 |
|
66 |
+
text_generate_button.click(
|
67 |
+
fn=generate_gif,
|
68 |
+
inputs=[text_prompt, None, text_negative_prompt, text_num_inference_steps, text_guidance_scale, text_seed],
|
69 |
+
outputs=text_output_video
|
70 |
+
)
|
71 |
+
|
72 |
+
with gr.TabItem("Generate from Image"):
|
73 |
+
with gr.Row():
|
74 |
+
with gr.Column():
|
75 |
+
image_prompt = gr.Textbox(lines=2, placeholder="Enter your prompt here...", label="Prompt")
|
76 |
+
image_input = gr.Image(type="filepath", label="Input Image")
|
77 |
+
image_negative_prompt = gr.Textbox(lines=2, placeholder="Enter your negative prompt here...", label="Negative Prompt")
|
78 |
+
image_num_inference_steps = gr.Slider(1, 100, step=1, value=50, label="Number of Inference Steps")
|
79 |
+
image_guidance_scale = gr.Slider(1, 20, step=0.1, value=9.0, label="Guidance Scale")
|
80 |
+
image_seed = gr.Number(label="Seed", value=8888)
|
81 |
+
image_generate_button = gr.Button("Generate GIF")
|
82 |
+
|
83 |
+
with gr.Column():
|
84 |
+
image_output_video = gr.Video(label="Generated GIF")
|
85 |
+
|
86 |
+
image_generate_button.click(
|
87 |
+
fn=generate_gif,
|
88 |
+
inputs=[image_prompt, image_input, image_negative_prompt, image_num_inference_steps, image_guidance_scale, image_seed],
|
89 |
+
outputs=image_output_video
|
90 |
+
)
|
91 |
|
92 |
# Launch the interface
|
93 |
+
demo.launch()
|