Spaces:
Running
on
Zero
Running
on
Zero
<fix> fix some bugs.
Browse files
app.py
CHANGED
@@ -47,7 +47,9 @@ The corresponding condition images will be automatically extracted.
|
|
47 |
|
48 |
|
49 |
def init_basemodel():
|
50 |
-
global transformer, scheduler, vae, text_encoder, text_encoder_2, tokenizer, tokenizer_2, image_processor
|
|
|
|
|
51 |
|
52 |
# init models
|
53 |
scheduler = diffusers.FlowMatchEulerDiscreteScheduler()
|
@@ -77,8 +79,12 @@ def init_basemodel():
|
|
77 |
@spaces.GPU
|
78 |
def process_image_and_text(condition_image, target_prompt, condition_image_prompt, task, random_seed, inpainting, fill_x1, fill_x2, fill_y1, fill_y2):
|
79 |
# set up the model
|
|
|
80 |
if pipe is None or current_task != task:
|
|
|
|
|
81 |
# init transformer
|
|
|
82 |
transformer = HunyuanVideoTransformer3DModel.from_pretrained('hunyuanvideo-community/HunyuanVideo-I2V',
|
83 |
subfolder="transformer",
|
84 |
inference_subject_driven=task in ['subject_driven'])
|
@@ -181,7 +187,6 @@ def process_image_and_text(condition_image, target_prompt, condition_image_promp
|
|
181 |
img_gray = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY)
|
182 |
edges = cv2.Canny(img_gray, 100, 200)
|
183 |
edges_tmp = Image.fromarray(edges).convert("RGB")
|
184 |
-
edges_tmp.save(os.path.join(save_dir, f"edges.png"))
|
185 |
edges[edges == 0] = 128
|
186 |
return Image.fromarray(edges).convert("RGB")
|
187 |
c_img = get_canny_edge(c_img)
|
@@ -210,7 +215,6 @@ def process_image_and_text(condition_image, target_prompt, condition_image_promp
|
|
210 |
)
|
211 |
return depth_pipe(img)["depth"].convert("RGB").resize((512, 512))
|
212 |
c_img = get_depth_map(c_img)
|
213 |
-
c_img.save(os.path.join(save_dir, f"depth.png"))
|
214 |
k = (255 - 128) / 255
|
215 |
b = 128
|
216 |
c_img = c_img.point(lambda x: k * x + b)
|
@@ -230,7 +234,6 @@ def process_image_and_text(condition_image, target_prompt, condition_image_promp
|
|
230 |
Image.new("RGB", (512, 512), (255, 255, 255)),
|
231 |
mask
|
232 |
)
|
233 |
-
c_img.save(os.path.join(save_dir, f"mask.png"))
|
234 |
c_img = Image.composite(
|
235 |
c_img,
|
236 |
Image.new("RGB", (512, 512), (128, 128, 128)),
|
@@ -238,9 +241,7 @@ def process_image_and_text(condition_image, target_prompt, condition_image_promp
|
|
238 |
)
|
239 |
elif task == "sr":
|
240 |
c_img = c_img.resize((int(512 / 4), int(512 / 4))).convert("RGB")
|
241 |
-
c_img.save(os.path.join(save_dir, f"low_resolution.png"))
|
242 |
c_img = c_img.resize((512, 512))
|
243 |
-
c_img.save(os.path.join(save_dir, f"low_to_high.png"))
|
244 |
|
245 |
gen_img = pipe(
|
246 |
image=c_img,
|
@@ -318,8 +319,5 @@ def create_app():
|
|
318 |
|
319 |
|
320 |
if __name__ == "__main__":
|
321 |
-
global pipe, current_task
|
322 |
-
pipe = None
|
323 |
-
current_task = None
|
324 |
init_basemodel()
|
325 |
create_app().launch(debug=True, ssr_mode=False)
|
|
|
47 |
|
48 |
|
49 |
def init_basemodel():
|
50 |
+
global transformer, scheduler, vae, text_encoder, text_encoder_2, tokenizer, tokenizer_2, image_processor, pipe, current_task
|
51 |
+
pipe = None
|
52 |
+
current_task = None
|
53 |
|
54 |
# init models
|
55 |
scheduler = diffusers.FlowMatchEulerDiscreteScheduler()
|
|
|
79 |
@spaces.GPU
|
80 |
def process_image_and_text(condition_image, target_prompt, condition_image_prompt, task, random_seed, inpainting, fill_x1, fill_x2, fill_y1, fill_y2):
|
81 |
# set up the model
|
82 |
+
global pipe, current_task
|
83 |
if pipe is None or current_task != task:
|
84 |
+
current_task = task
|
85 |
+
|
86 |
# init transformer
|
87 |
+
global transformer
|
88 |
transformer = HunyuanVideoTransformer3DModel.from_pretrained('hunyuanvideo-community/HunyuanVideo-I2V',
|
89 |
subfolder="transformer",
|
90 |
inference_subject_driven=task in ['subject_driven'])
|
|
|
187 |
img_gray = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY)
|
188 |
edges = cv2.Canny(img_gray, 100, 200)
|
189 |
edges_tmp = Image.fromarray(edges).convert("RGB")
|
|
|
190 |
edges[edges == 0] = 128
|
191 |
return Image.fromarray(edges).convert("RGB")
|
192 |
c_img = get_canny_edge(c_img)
|
|
|
215 |
)
|
216 |
return depth_pipe(img)["depth"].convert("RGB").resize((512, 512))
|
217 |
c_img = get_depth_map(c_img)
|
|
|
218 |
k = (255 - 128) / 255
|
219 |
b = 128
|
220 |
c_img = c_img.point(lambda x: k * x + b)
|
|
|
234 |
Image.new("RGB", (512, 512), (255, 255, 255)),
|
235 |
mask
|
236 |
)
|
|
|
237 |
c_img = Image.composite(
|
238 |
c_img,
|
239 |
Image.new("RGB", (512, 512), (128, 128, 128)),
|
|
|
241 |
)
|
242 |
elif task == "sr":
|
243 |
c_img = c_img.resize((int(512 / 4), int(512 / 4))).convert("RGB")
|
|
|
244 |
c_img = c_img.resize((512, 512))
|
|
|
245 |
|
246 |
gen_img = pipe(
|
247 |
image=c_img,
|
|
|
319 |
|
320 |
|
321 |
if __name__ == "__main__":
|
|
|
|
|
|
|
322 |
init_basemodel()
|
323 |
create_app().launch(debug=True, ssr_mode=False)
|