caohy666 commited on
Commit
8851fb5
·
1 Parent(s): 63c048f

<fix> seperate model init and inference.

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -46,9 +46,9 @@ The corresponding condition images will be automatically extracted.
46
  """
47
 
48
 
 
 
49
 
50
- @spaces.GPU
51
- def process_image_and_text(condition_image, target_prompt, condition_image_prompt, task):
52
  # init models
53
  transformer = HunyuanVideoTransformer3DModel.from_pretrained('hunyuanvideo-community/HunyuanVideo-I2V',
54
  subfolder="transformer",
@@ -162,6 +162,10 @@ def process_image_and_text(condition_image, target_prompt, condition_image_promp
162
  image_processor=image_processor,
163
  )
164
 
 
 
 
 
165
  # start generation
166
  c_txt = None if condition_image_prompt == "" else condition_image_prompt
167
  c_img = condition_image.resize((512, 512))
@@ -235,6 +239,9 @@ def process_image_and_text(condition_image, target_prompt, condition_image_promp
235
  c_img = c_img.resize((args.img_size, args.img_size))
236
  c_img.save(os.path.join(save_dir, f"low_to_high.png"))
237
 
 
 
 
238
  gen_img = pipe(
239
  image=c_img,
240
  prompt=[t_txt.strip()],
 
46
  """
47
 
48
 
49
+ def init_pipeline():
50
+ global pipe
51
 
 
 
52
  # init models
53
  transformer = HunyuanVideoTransformer3DModel.from_pretrained('hunyuanvideo-community/HunyuanVideo-I2V',
54
  subfolder="transformer",
 
162
  image_processor=image_processor,
163
  )
164
 
165
+
166
+ @spaces.GPU
167
+ def process_image_and_text(condition_image, target_prompt, condition_image_prompt, task):
168
+
169
  # start generation
170
  c_txt = None if condition_image_prompt == "" else condition_image_prompt
171
  c_img = condition_image.resize((512, 512))
 
239
  c_img = c_img.resize((args.img_size, args.img_size))
240
  c_img.save(os.path.join(save_dir, f"low_to_high.png"))
241
 
242
+ if pipe is None:
243
+ init_pipeline()
244
+
245
  gen_img = pipe(
246
  image=c_img,
247
  prompt=[t_txt.strip()],