Update app.py
Browse files
app.py
CHANGED
@@ -238,7 +238,7 @@ def video_to_audio(video_path, prompt, negative_prompt="music", seed=0, num_step
|
|
238 |
traceback.print_exc()
|
239 |
return video_path
|
240 |
|
241 |
-
def generate_video_from_image(image, prompt="", length=4.0
|
242 |
if image is None:
|
243 |
return None
|
244 |
|
@@ -248,7 +248,7 @@ def generate_video_from_image(image, prompt="", length=4.0, sound_generation="
|
|
248 |
temp_path = fp.name
|
249 |
Image.fromarray(image).save(temp_path)
|
250 |
|
251 |
-
# API νΈμΆ
|
252 |
client = Client(VIDEO_API_URL)
|
253 |
result = client.predict(
|
254 |
input_image=handle_file(temp_path),
|
@@ -264,40 +264,31 @@ def generate_video_from_image(image, prompt="", length=4.0, sound_generation="
|
|
264 |
|
265 |
if result and len(result) > 0:
|
266 |
video_dict = result[0]
|
267 |
-
|
268 |
-
|
269 |
-
# λΉλμ€ μμ±μ΄ μ±κ³΅ν κ²½μ°μλ§ μ¬μ΄λ μΆκ°
|
270 |
-
if video_path:
|
271 |
-
# μ¬μ΄λ μμ± μ΅μ
μ΄ μ νλ κ²½μ°
|
272 |
-
if sound_generation == "μ¬μ΄λ μμ±" and MMAUDIO_LOADED:
|
273 |
-
try:
|
274 |
-
# μ¬μ΄λ ν둬ννΈκ° λΉμ΄μμΌλ©΄ κΈ°λ³Έκ° μ¬μ©
|
275 |
-
if not sound_prompt:
|
276 |
-
sound_prompt = prompt if prompt else "ambient sound"
|
277 |
-
|
278 |
-
# λΉλμ€μ μ¬μ΄λ μΆκ°
|
279 |
-
video_with_sound = video_to_audio(
|
280 |
-
video_path=video_path,
|
281 |
-
prompt=sound_prompt,
|
282 |
-
negative_prompt=sound_negative_prompt,
|
283 |
-
seed=random.randint(0, 9999999),
|
284 |
-
num_steps=25,
|
285 |
-
cfg_strength=4.5,
|
286 |
-
target_duration=length
|
287 |
-
)
|
288 |
-
return video_with_sound
|
289 |
-
except Exception as e:
|
290 |
-
logging.error(f"Sound generation error: {str(e)}")
|
291 |
-
# μ¬μ΄λ μμ± μ€ν¨ μ μλ³Έ λΉλμ€ λ°ν
|
292 |
-
return video_path
|
293 |
-
|
294 |
-
# μ¬μ΄λ μμ±μ μ ννμ§ μμ κ²½μ° μλ³Έ λΉλμ€ λ°ν
|
295 |
-
return video_path
|
296 |
|
297 |
except Exception as e:
|
298 |
logging.error(f"Video generation error: {str(e)}")
|
299 |
return None
|
300 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
def prepare_image_and_mask(image, width, height, overlap_percentage, alignment):
|
302 |
"""μ΄λ―Έμ§μ λ§μ€ν¬λ₯Ό μ€λΉνλ ν¨μ"""
|
303 |
if image is None:
|
@@ -626,12 +617,22 @@ with demo:
|
|
626 |
[sound_generation],
|
627 |
[sound_options]
|
628 |
)
|
629 |
-
|
|
|
630 |
video_btn.click(
|
631 |
generate_video_from_image,
|
632 |
-
[output_image, video_prompt, video_length,
|
633 |
[output_video]
|
634 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
635 |
|
636 |
# μ΄λ²€νΈ μ°κ²° - λ λ²μ§Έ ν
|
637 |
outpaint_size_preset.change(update_dimensions, [outpaint_size_preset], [outpaint_width, outpaint_height])
|
|
|
238 |
traceback.print_exc()
|
239 |
return video_path
|
240 |
|
241 |
+
def generate_video_from_image(image, prompt="", length=4.0):
|
242 |
if image is None:
|
243 |
return None
|
244 |
|
|
|
248 |
temp_path = fp.name
|
249 |
Image.fromarray(image).save(temp_path)
|
250 |
|
251 |
+
# API νΈμΆ
|
252 |
client = Client(VIDEO_API_URL)
|
253 |
result = client.predict(
|
254 |
input_image=handle_file(temp_path),
|
|
|
264 |
|
265 |
if result and len(result) > 0:
|
266 |
video_dict = result[0]
|
267 |
+
return video_dict.get("video") if isinstance(video_dict, dict) else None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
268 |
|
269 |
except Exception as e:
|
270 |
logging.error(f"Video generation error: {str(e)}")
|
271 |
return None
|
272 |
|
273 |
+
def add_sound_to_video(video_path, sound_prompt, sound_negative_prompt="music"):
|
274 |
+
if not video_path or not MMAUDIO_LOADED:
|
275 |
+
return video_path
|
276 |
+
|
277 |
+
try:
|
278 |
+
return video_to_audio(
|
279 |
+
video_path=video_path,
|
280 |
+
prompt=sound_prompt,
|
281 |
+
negative_prompt=sound_negative_prompt,
|
282 |
+
seed=random.randint(0, 9999999),
|
283 |
+
num_steps=25,
|
284 |
+
cfg_strength=4.5,
|
285 |
+
target_duration=8.0 # κΈ°λ³Έκ° μ¬μ©
|
286 |
+
)
|
287 |
+
except Exception as e:
|
288 |
+
logging.error(f"Sound addition error: {str(e)}")
|
289 |
+
return video_path
|
290 |
+
|
291 |
+
|
292 |
def prepare_image_and_mask(image, width, height, overlap_percentage, alignment):
|
293 |
"""μ΄λ―Έμ§μ λ§μ€ν¬λ₯Ό μ€λΉνλ ν¨μ"""
|
294 |
if image is None:
|
|
|
617 |
[sound_generation],
|
618 |
[sound_options]
|
619 |
)
|
620 |
+
|
621 |
+
|
622 |
video_btn.click(
|
623 |
generate_video_from_image,
|
624 |
+
[output_image, video_prompt, video_length], # μλλλ‘ 3κ° λ§€κ°λ³μλ§
|
625 |
[output_video]
|
626 |
)
|
627 |
+
|
628 |
+
# μ¬μ΄λ μΆκ°λ λ³λ λ²νΌμΌλ‘
|
629 |
+
sound_btn = gr.Button("π λΉλμ€μ μ¬μ΄λ μΆκ°", visible=False)
|
630 |
+
sound_btn.click(
|
631 |
+
add_sound_to_video,
|
632 |
+
[output_video, sound_prompt, sound_negative_prompt],
|
633 |
+
[output_video]
|
634 |
+
)
|
635 |
+
|
636 |
|
637 |
# μ΄λ²€νΈ μ°κ²° - λ λ²μ§Έ ν
|
638 |
outpaint_size_preset.change(update_dimensions, [outpaint_size_preset], [outpaint_width, outpaint_height])
|