mrcuddle commited on
Commit
4dc94b9
·
verified ·
1 Parent(s): 7a5c202

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -5,6 +5,19 @@ from diffusers.utils import export_to_gif, load_image
5
  import tempfile
6
  import spaces
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  @spaces.GPU
9
  def initialize_pipeline():
10
  # Initialize the pipeline without CUDA support
@@ -19,7 +32,7 @@ def generate_gif(prompt, image, negative_prompt, num_inference_steps, guidance_s
19
  generator = torch.Generator().manual_seed(seed)
20
 
21
  # Check if an image is provided
22
- if image is not None:
23
  image = load_image(image).convert("RGB")
24
  frames = pipeline(
25
  prompt=prompt,
@@ -61,10 +74,10 @@ with gr.Blocks() as demo:
61
  with gr.Column():
62
  text_output_video = gr.Video(label="Generated GIF")
63
 
64
- # Fix: Do not use `None` in the inputs, instead pass an empty input for image
65
  text_generate_button.click(
66
  fn=generate_gif,
67
- inputs=[text_prompt, None, text_negative_prompt, text_num_inference_steps, text_guidance_scale, text_seed],
68
  outputs=text_output_video
69
  )
70
 
@@ -89,4 +102,4 @@ with gr.Blocks() as demo:
89
  )
90
 
91
  # Launch the interface
92
- demo.launch()
 
5
  import tempfile
6
  import spaces
7
 
8
+ @spaces.GPU
9
+ def initialize_pipeline():
10
+ # Initialize the pipeline without CUDA support
11
+ pipeline = I2VGenXLPipeline.from_pretrained("ali-vilab/i2vgen-xl", torch_dtype=torch.float16, variant="fp16")
12
+ return pipeline
13
+
14
+ import gradio as gr
15
+ import torch
16
+ from diffusers import I2VGenXLPipeline
17
+ from diffusers.utils import export_to_gif, load_image
18
+ import tempfile
19
+ import spaces
20
+
21
  @spaces.GPU
22
  def initialize_pipeline():
23
  # Initialize the pipeline without CUDA support
 
32
  generator = torch.Generator().manual_seed(seed)
33
 
34
  # Check if an image is provided
35
+ if image is not None and image != "": # Ensure image is not empty
36
  image = load_image(image).convert("RGB")
37
  frames = pipeline(
38
  prompt=prompt,
 
74
  with gr.Column():
75
  text_output_video = gr.Video(label="Generated GIF")
76
 
77
+ # When generating from text, pass an empty string as the image input
78
  text_generate_button.click(
79
  fn=generate_gif,
80
+ inputs=[text_prompt, "", text_negative_prompt, text_num_inference_steps, text_guidance_scale, text_seed],
81
  outputs=text_output_video
82
  )
83
 
 
102
  )
103
 
104
  # Launch the interface
105
+ demo.launch()