Spaces:
Running
Running
Update app-backup1.py
Browse files- app-backup1.py +567 -483
app-backup1.py
CHANGED
@@ -22,7 +22,7 @@ import os
|
|
22 |
import gc
|
23 |
from openai import OpenAI
|
24 |
import re
|
25 |
-
|
26 |
# Load system prompts
|
27 |
system_prompt_t2v = """λΉμ μ λΉλμ€ μμ±μ μν ν둬ννΈ μ λ¬Έκ°μ
λλ€.
|
28 |
μ£Όμ΄μ§ ν둬ννΈλ₯Ό λ€μ ꡬ쑰μ λ§κ² κ°μ ν΄μ£ΌμΈμ:
|
@@ -239,14 +239,7 @@ pipeline = XoraVideoPipeline(
|
|
239 |
vae=vae,
|
240 |
).to(device)
|
241 |
|
242 |
-
# State λ³μλ€μ μ΄κΈ°ν μμ
|
243 |
-
txt2vid_current_height = gr.State(value=320)
|
244 |
-
txt2vid_current_width = gr.State(value=512)
|
245 |
-
txt2vid_current_num_frames = gr.State(value=257)
|
246 |
|
247 |
-
img2vid_current_height = gr.State(value=320)
|
248 |
-
img2vid_current_width = gr.State(value=512)
|
249 |
-
img2vid_current_num_frames = gr.State(value=257)
|
250 |
|
251 |
# Preset options for resolution and frame configuration
|
252 |
# Convert frames to seconds assuming 25 FPS
|
@@ -279,27 +272,29 @@ preset_options = [
|
|
279 |
]
|
280 |
|
281 |
def preset_changed(preset):
|
282 |
-
selected = next(item for item in preset_options if item["label"] == preset)
|
|
|
|
|
283 |
return [
|
284 |
-
selected["height"],
|
285 |
-
selected["width"],
|
286 |
-
selected["num_frames"],
|
287 |
gr.update(visible=False),
|
288 |
gr.update(visible=False),
|
289 |
gr.update(visible=False),
|
290 |
-
]
|
291 |
-
|
292 |
def generate_video_from_text(
|
293 |
-
prompt
|
294 |
-
enhance_prompt_toggle
|
295 |
-
negative_prompt
|
296 |
-
frame_rate
|
297 |
-
seed
|
298 |
-
num_inference_steps
|
299 |
-
guidance_scale
|
300 |
-
height
|
301 |
-
width
|
302 |
-
num_frames
|
303 |
progress=gr.Progress(),
|
304 |
):
|
305 |
if len(prompt.strip()) < 50:
|
@@ -308,10 +303,23 @@ def generate_video_from_text(
|
|
308 |
duration=5,
|
309 |
)
|
310 |
|
|
|
|
|
|
|
|
|
311 |
# Translate Korean prompts to English
|
312 |
prompt = translate_korean_prompt(prompt)
|
313 |
negative_prompt = translate_korean_prompt(negative_prompt)
|
314 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
sample = {
|
316 |
"prompt": prompt,
|
317 |
"prompt_attention_mask": None,
|
@@ -354,7 +362,6 @@ def generate_video_from_text(
|
|
354 |
gc.collect()
|
355 |
|
356 |
output_path = tempfile.mktemp(suffix=".mp4")
|
357 |
-
print(images.shape)
|
358 |
video_np = images.squeeze(0).permute(1, 2, 3, 0).cpu().float().numpy()
|
359 |
video_np = (video_np * 255).astype(np.uint8)
|
360 |
height, width = video_np.shape[1:3]
|
@@ -371,21 +378,20 @@ def generate_video_from_text(
|
|
371 |
|
372 |
def generate_video_from_image(
|
373 |
image_path,
|
374 |
-
prompt
|
375 |
-
enhance_prompt_toggle
|
376 |
-
negative_prompt
|
377 |
-
frame_rate
|
378 |
-
seed
|
379 |
-
num_inference_steps
|
380 |
-
guidance_scale
|
381 |
-
height
|
382 |
-
width
|
383 |
-
num_frames
|
384 |
progress=gr.Progress(),
|
385 |
):
|
386 |
-
|
387 |
-
|
388 |
-
print("Num Frames: ", num_frames)
|
389 |
|
390 |
if len(prompt.strip()) < 50:
|
391 |
raise gr.Error(
|
@@ -393,13 +399,24 @@ def generate_video_from_image(
|
|
393 |
duration=5,
|
394 |
)
|
395 |
|
396 |
-
|
397 |
-
|
|
|
398 |
|
399 |
# Translate Korean prompts to English
|
400 |
prompt = translate_korean_prompt(prompt)
|
401 |
negative_prompt = translate_korean_prompt(negative_prompt)
|
402 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
403 |
media_items = (
|
404 |
load_image_to_tensor_with_resize(image_path, height, width).to(device).detach()
|
405 |
)
|
@@ -447,6 +464,7 @@ def generate_video_from_image(
|
|
447 |
for frame in video_np[..., ::-1]:
|
448 |
out.write(frame)
|
449 |
out.release()
|
|
|
450 |
except Exception as e:
|
451 |
raise gr.Error(
|
452 |
f"λΉλμ€ μμ± μ€ μ€λ₯κ° λ°μνμ΅λλ€. λ€μ μλν΄μ£ΌμΈμ. μ€λ₯: {e}",
|
@@ -456,6 +474,12 @@ def generate_video_from_image(
|
|
456 |
finally:
|
457 |
torch.cuda.empty_cache()
|
458 |
gc.collect()
|
|
|
|
|
|
|
|
|
|
|
|
|
459 |
|
460 |
return output_path
|
461 |
|
@@ -551,99 +575,95 @@ system_prompt_scenario = """λΉμ μ μμ μ€ν¬λ¦½νΈμ λ§λ λ°°κ²½ μ
|
|
551 |
|
552 |
|
553 |
def analyze_scenario(scenario):
|
554 |
-
"""μλ리μ€λ₯Ό λΆμνμ¬ λ°°κ²½ μμμ© ν둬ννΈ μμ±"""
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
λͺ¨λ μΉμ
μ΄ μΌκ΄λ μ€νμΌκ³Ό ν€μ μ μ§νλ©΄μλ μμ°μ€λ½κ² μ΄μ΄μ§λλ‘ κ΅¬μ±νμΈμ.
|
575 |
-
|
576 |
-
κ° μΉμ
μ ν둬ννΈ μμ±μ λ°λμ λ€μ ꡬ쑰μ λ§κ² κ°μ ν΄μ£ΌμΈμ:
|
577 |
-
1. μ£Όμ λμμ λͺ
νν ν λ¬Έμ₯μΌλ‘ μμ
|
578 |
-
2. ꡬ체μ μΈ λμκ³Ό μ μ€μ²λ₯Ό μκ° μμλλ‘ μ€λͺ
|
579 |
-
3. μΊλ¦ν°/κ°μ²΄μ μΈλͺ¨λ₯Ό μμΈν λ¬μ¬
|
580 |
-
4. λ°°κ²½κ³Ό νκ²½ μΈλΆ μ¬νμ ꡬ체μ μΌλ‘ ν¬ν¨
|
581 |
-
5. μΉ΄λ©λΌ κ°λμ μμ§μμ λͺ
μ
|
582 |
-
6. μ‘°λͺ
κ³Ό μμμ μμΈν μ€λͺ
|
583 |
-
7. λ³νλ κ°μμ€λ¬μ΄ μ¬κ±΄μ μμ°μ€λ½κ² ν¬ν¨
|
584 |
-
λͺ¨λ μ€λͺ
μ νλμ μμ°μ€λ¬μ΄ λ¬Έλ¨μΌλ‘ μμ±νκ³ ,
|
585 |
-
촬μ κ°λ
μ΄ μ΄¬μ λͺ©λ‘μ μ€λͺ
νλ κ²μ²λΌ ꡬ체μ μ΄κ³ μκ°μ μΌλ‘ μμ±νμΈμ.
|
586 |
-
200λ¨μ΄λ₯Ό λμ§ μλλ‘ νλ, μ΅λν μμΈνκ² μμ±νμΈμ.
|
587 |
|
|
|
588 |
{scenario}
|
589 |
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
current_section = line
|
609 |
-
else:
|
610 |
-
current_section += "\n" + line
|
611 |
-
|
612 |
-
if current_section:
|
613 |
-
sections.append(current_section.strip())
|
614 |
|
615 |
-
|
616 |
-
|
617 |
-
sections.append("μΆκ° μΉμ
μ΄ νμν©λλ€.")
|
618 |
|
619 |
-
|
|
|
|
|
|
|
620 |
|
621 |
except Exception as e:
|
622 |
print(f"Error during scenario analysis: {e}")
|
623 |
return ["Error occurred during analysis"] * 5
|
624 |
|
625 |
def generate_section_video(prompt, preset, section_number=1, base_seed=171198, progress=gr.Progress()):
|
626 |
-
"""κ° μΉμ
μ λΉλμ€ μμ±
|
627 |
try:
|
628 |
if not prompt or len(prompt.strip()) < 50:
|
629 |
raise gr.Error("ν둬ννΈλ μ΅μ 50μ μ΄μμ΄μ΄μΌ ν©λλ€.")
|
630 |
|
631 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
632 |
section_seed = base_seed + section_number
|
633 |
|
634 |
return generate_video_from_text(
|
635 |
prompt=prompt,
|
|
|
|
|
|
|
|
|
|
|
|
|
636 |
height=selected["height"],
|
637 |
width=selected["width"],
|
638 |
num_frames=selected["num_frames"],
|
639 |
-
seed=section_seed,
|
640 |
progress=progress
|
641 |
)
|
642 |
except Exception as e:
|
643 |
print(f"Error in section {section_number}: {e}")
|
644 |
raise gr.Error(f"μΉμ
{section_number} μμ± μ€ μ€λ₯: {str(e)}")
|
|
|
|
|
|
|
645 |
|
646 |
-
# κ°λ³ μΉμ
ν둬ννΈ μμ± ν¨μ μΆκ°
|
647 |
def generate_single_section_prompt(scenario, section_number):
|
648 |
"""κ°λ³ μΉμ
μ λν ν둬ννΈ μμ±"""
|
649 |
section_descriptions = {
|
@@ -658,23 +678,35 @@ def generate_single_section_prompt(scenario, section_number):
|
|
658 |
{"role": "system", "content": system_prompt_scenario},
|
659 |
{"role": "user", "content": f"""
|
660 |
λ€μ μ€ν¬λ¦½νΈμ {section_number}λ²μ§Έ μΉμ
({section_descriptions[section_number]})μ λν
|
661 |
-
λ°°κ²½ μμ
|
662 |
|
|
|
663 |
{scenario}
|
664 |
|
665 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
666 |
]
|
667 |
|
668 |
try:
|
669 |
response = client.chat.completions.create(
|
670 |
model="gpt-4-1106-preview",
|
671 |
messages=messages,
|
672 |
-
max_tokens=
|
|
|
673 |
)
|
674 |
-
|
|
|
675 |
except Exception as e:
|
676 |
-
print(f"Error during prompt generation: {e}")
|
677 |
-
return "Error occurred during prompt generation"
|
678 |
|
679 |
|
680 |
# λΉλμ€ κ²°ν© ν¨μ μΆκ°
|
@@ -716,11 +748,23 @@ def merge_section_videos(section1, section2, section3, section4, section5):
|
|
716 |
videos = []
|
717 |
|
718 |
# κ° μΉμ
λΉλμ€ νμΈ λ° μ²λ¦¬
|
719 |
-
for i,
|
720 |
-
if
|
721 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
722 |
else:
|
723 |
-
raise gr.Error(f"μΉμ
{i}μ μμμ΄
|
724 |
|
725 |
if not videos:
|
726 |
raise gr.Error("κ²°ν©ν μμμ΄ μμ΅λλ€.")
|
@@ -746,388 +790,428 @@ def merge_section_videos(section1, section2, section3, section4, section5):
|
|
746 |
ret, frame = cap.read()
|
747 |
if not ret:
|
748 |
break
|
749 |
-
#
|
750 |
if frame.shape[:2] != (height, width):
|
751 |
frame = cv2.resize(frame, (width, height))
|
752 |
out.write(frame)
|
753 |
cap.release()
|
754 |
|
755 |
out.release()
|
|
|
756 |
return output_path
|
757 |
|
758 |
except Exception as e:
|
759 |
raise gr.Error(f"λΉλμ€ κ²°ν© μ€ μ€λ₯ λ°μ: {e}")
|
760 |
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
# Text to Video Tab
|
766 |
-
with gr.TabItem("ν
μ€νΈλ‘ λΉλμ€ λ§λ€κΈ°"):
|
767 |
-
with gr.Row():
|
768 |
-
with gr.Column():
|
769 |
-
txt2vid_prompt = gr.Textbox(
|
770 |
-
label="Step 1: ν둬ννΈ μ
λ ₯",
|
771 |
-
placeholder="μμ±νκ³ μΆμ λΉλμ€λ₯Ό μ€λͺ
νμΈμ (μ΅μ 50μ)...",
|
772 |
-
value="κ·μ¬μ΄ κ³ μμ΄",
|
773 |
-
lines=5,
|
774 |
-
)
|
775 |
-
txt2vid_enhance_toggle = Toggle(
|
776 |
-
label="ν둬ννΈ κ°μ ",
|
777 |
-
value=False,
|
778 |
-
interactive=True,
|
779 |
-
)
|
780 |
-
|
781 |
-
txt2vid_negative_prompt = gr.Textbox(
|
782 |
-
label="Step 2: λ€κ±°ν°λΈ ν둬ννΈ μ
λ ₯",
|
783 |
-
placeholder="λΉλμ€μμ μνμ§ μλ μμλ₯Ό μ€λͺ
νμΈμ...",
|
784 |
-
value="low quality, worst quality, deformed, distorted, warped, motion smear, motion artifacts, fused fingers, incorrect anatomy, strange hands, unattractive",
|
785 |
-
lines=2,
|
786 |
-
visible=False
|
787 |
-
)
|
788 |
-
|
789 |
-
txt2vid_preset = gr.Dropdown(
|
790 |
-
choices=[p["label"] for p in preset_options],
|
791 |
-
value="[16:9] 512x320, 10.3μ΄",
|
792 |
-
label="Step 2: ν΄μλ ν리μ
μ ν",
|
793 |
-
)
|
794 |
-
|
795 |
-
txt2vid_frame_rate = gr.Slider(
|
796 |
-
label="Step 3: νλ μ λ μ΄νΈ",
|
797 |
-
minimum=21,
|
798 |
-
maximum=30,
|
799 |
-
step=1,
|
800 |
-
value=25,
|
801 |
-
visible=False
|
802 |
-
)
|
803 |
-
|
804 |
-
txt2vid_advanced = create_advanced_options()
|
805 |
-
txt2vid_generate = gr.Button(
|
806 |
-
"Step 3: λΉλμ€ μμ±",
|
807 |
-
variant="primary",
|
808 |
-
size="lg",
|
809 |
-
)
|
810 |
-
|
811 |
-
with gr.Column():
|
812 |
-
txt2vid_output = gr.Video(label="μμ±λ λΉλμ€")
|
813 |
-
|
814 |
-
# Image to Video Tab
|
815 |
-
with gr.TabItem("μ΄λ―Έμ§λ‘ λΉλμ€ λ§λ€κΈ°"):
|
816 |
-
with gr.Row():
|
817 |
-
with gr.Column():
|
818 |
-
img2vid_image = gr.Image(
|
819 |
-
type="filepath",
|
820 |
-
label="Step 1: μ
λ ₯ μ΄λ―Έμ§ μ
λ‘λ",
|
821 |
-
elem_id="image_upload",
|
822 |
-
)
|
823 |
-
img2vid_prompt = gr.Textbox(
|
824 |
-
label="Step 2: ν둬ννΈ μ
λ ₯",
|
825 |
-
placeholder="μ΄λ―Έμ§λ₯Ό μ΄λ»κ² μ λλ©μ΄μ
νν μ§ μ€λͺ
νμΈμ (μ΅μ 50μ)...",
|
826 |
-
value="κ·μ¬μ΄ κ³ μμ΄",
|
827 |
-
lines=5,
|
828 |
-
)
|
829 |
-
img2vid_enhance_toggle = Toggle(
|
830 |
-
label="ν둬ννΈ μ¦κ°",
|
831 |
-
value=False,
|
832 |
-
interactive=True,
|
833 |
-
)
|
834 |
-
img2vid_negative_prompt = gr.Textbox(
|
835 |
-
label="Step 3: λ€κ±°ν°λΈ ν둬ννΈ μ
λ ₯",
|
836 |
-
placeholder="λΉλμ€μμ μνμ§ μλ μμλ₯Ό μ€λͺ
νμΈμ...",
|
837 |
-
value="low quality, worst quality, deformed, distorted, warped, motion smear, motion artifacts, fused fingers, incorrect anatomy, strange hands, unattractive",
|
838 |
-
lines=2,
|
839 |
-
visible=False
|
840 |
-
)
|
841 |
-
|
842 |
-
img2vid_preset = gr.Dropdown(
|
843 |
-
choices=[p["label"] for p in preset_options],
|
844 |
-
value="[16:9] 512x320, 10.3μ΄",
|
845 |
-
label="Step 3: ν΄μλ ν리μ
μ ν",
|
846 |
-
)
|
847 |
-
|
848 |
-
img2vid_frame_rate = gr.Slider(
|
849 |
-
label="Step 4: νλ μ λ μ΄νΈ",
|
850 |
-
minimum=21,
|
851 |
-
maximum=30,
|
852 |
-
step=1,
|
853 |
-
value=25,
|
854 |
-
visible=False
|
855 |
-
)
|
856 |
-
|
857 |
-
img2vid_advanced = create_advanced_options()
|
858 |
-
img2vid_generate = gr.Button(
|
859 |
-
"Step 4: λΉλμ€ μμ±",
|
860 |
-
variant="primary",
|
861 |
-
size="lg",
|
862 |
-
)
|
863 |
-
|
864 |
-
with gr.Column():
|
865 |
-
img2vid_output = gr.Video(label="μμ±λ λΉλμ€")
|
866 |
-
|
867 |
-
|
868 |
-
# Scenario to Video Tab (Modified)
|
869 |
-
with gr.TabItem("μλ리μ€λ‘ λΉλμ€ λ§λ€κΈ°(μνΌ)"):
|
870 |
-
with gr.Row():
|
871 |
-
with gr.Column(scale=1):
|
872 |
-
scenario_input = gr.Textbox(
|
873 |
-
label="μμ μ€ν¬λ¦½νΈ μ
λ ₯",
|
874 |
-
placeholder="μ 체 μλ리μ€λ₯Ό μ
λ ₯νμΈμ...",
|
875 |
-
lines=10
|
876 |
-
)
|
877 |
-
scenario_preset = gr.Dropdown(
|
878 |
-
choices=[p["label"] for p in preset_options],
|
879 |
-
value="[16:9] 512x320, 10.3μ΄",
|
880 |
-
label="νλ©΄ ν¬κΈ° μ ν"
|
881 |
-
)
|
882 |
-
analyze_btn = gr.Button("μλλ¦¬μ€ λΆμ λ° ν둬ννΈ μμ±", variant="primary")
|
883 |
-
|
884 |
-
with gr.Column(scale=2):
|
885 |
-
with gr.Row():
|
886 |
-
# μΉμ
1
|
887 |
-
with gr.Column():
|
888 |
-
section1_prompt = gr.Textbox(
|
889 |
-
label="1. λ°°κ²½ λ° νμμ±",
|
890 |
-
lines=4
|
891 |
-
)
|
892 |
-
with gr.Row():
|
893 |
-
section1_regenerate = gr.Button("π ν둬ννΈ μμ±")
|
894 |
-
section1_generate = gr.Button("π μμ μμ±")
|
895 |
-
section1_video = gr.Video(label="μΉμ
1 μμ")
|
896 |
-
|
897 |
-
# μΉμ
2
|
898 |
-
with gr.Column():
|
899 |
-
section2_prompt = gr.Textbox(
|
900 |
-
label="2. ν₯λ―Έ μ λ°",
|
901 |
-
lines=4
|
902 |
-
)
|
903 |
-
with gr.Row():
|
904 |
-
section2_regenerate = gr.Button("π ν둬ννΈ μμ±")
|
905 |
-
section2_generate = gr.Button("π μμ μμ±")
|
906 |
-
section2_video = gr.Video(label="μΉμ
2 μμ")
|
907 |
-
|
908 |
-
with gr.Row():
|
909 |
-
# μΉμ
3
|
910 |
-
with gr.Column():
|
911 |
-
section3_prompt = gr.Textbox(
|
912 |
-
label="3. ν΄κ²°μ±
μ μ",
|
913 |
-
lines=4
|
914 |
-
)
|
915 |
-
with gr.Row():
|
916 |
-
section3_regenerate = gr.Button("π ν둬ννΈ μμ±")
|
917 |
-
section3_generate = gr.Button("π μμ μμ±")
|
918 |
-
section3_video = gr.Video(label="μΉμ
3 μμ")
|
919 |
-
|
920 |
-
# μΉμ
4
|
921 |
-
with gr.Column():
|
922 |
-
section4_prompt = gr.Textbox(
|
923 |
-
label="4. λ³Έλ‘ ",
|
924 |
-
lines=4
|
925 |
-
)
|
926 |
-
with gr.Row():
|
927 |
-
section4_regenerate = gr.Button("π ν둬ννΈ μμ±")
|
928 |
-
section4_generate = gr.Button("π μμ μμ±")
|
929 |
-
section4_video = gr.Video(label="μΉμ
4 μμ")
|
930 |
-
|
931 |
-
with gr.Row():
|
932 |
-
# μΉμ
5
|
933 |
-
with gr.Column():
|
934 |
-
section5_prompt = gr.Textbox(
|
935 |
-
label="5. κ²°λ‘ λ° κ°μ‘°",
|
936 |
-
lines=4
|
937 |
-
)
|
938 |
-
with gr.Row():
|
939 |
-
section5_regenerate = gr.Button("π ν둬ννΈ μμ±")
|
940 |
-
section5_generate = gr.Button("π μμ μμ±")
|
941 |
-
section5_video = gr.Video(label="μΉμ
5 μμ")
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
# ν΅ν© μμ μΉμ
μΆκ°
|
946 |
-
with gr.Row():
|
947 |
-
with gr.Column(scale=1):
|
948 |
-
# κΈ°μ‘΄μ scenario_inputκ³Ό analyze_btn μ μ§
|
949 |
-
merge_videos_btn = gr.Button("ν΅ν© μμ μμ±", variant="primary", size="lg")
|
950 |
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
txt2vid_current_height,
|
967 |
-
txt2vid_current_width,
|
968 |
-
txt2vid_current_num_frames,
|
969 |
-
*txt2vid_advanced[3:]
|
970 |
-
]
|
971 |
-
)
|
972 |
-
|
973 |
-
txt2vid_enhance_toggle.change(
|
974 |
-
fn=update_prompt_t2v,
|
975 |
-
inputs=[txt2vid_prompt, txt2vid_enhance_toggle],
|
976 |
-
outputs=txt2vid_prompt
|
977 |
-
)
|
978 |
-
|
979 |
-
txt2vid_generate.click(
|
980 |
-
fn=generate_video_from_text,
|
981 |
-
inputs=[
|
982 |
-
txt2vid_prompt,
|
983 |
-
txt2vid_enhance_toggle,
|
984 |
-
txt2vid_negative_prompt,
|
985 |
-
txt2vid_frame_rate,
|
986 |
-
*txt2vid_advanced[:3],
|
987 |
-
txt2vid_current_height,
|
988 |
-
txt2vid_current_width,
|
989 |
-
txt2vid_current_num_frames,
|
990 |
-
],
|
991 |
-
outputs=txt2vid_output,
|
992 |
-
concurrency_limit=1,
|
993 |
-
concurrency_id="generate_video",
|
994 |
-
queue=True,
|
995 |
-
)
|
996 |
-
|
997 |
-
img2vid_preset.change(
|
998 |
-
fn=preset_changed,
|
999 |
-
inputs=[img2vid_preset],
|
1000 |
-
outputs=[
|
1001 |
-
img2vid_current_height,
|
1002 |
-
img2vid_current_width,
|
1003 |
-
img2vid_current_num_frames,
|
1004 |
-
*img2vid_advanced[3:]
|
1005 |
-
]
|
1006 |
-
)
|
1007 |
-
|
1008 |
-
img2vid_enhance_toggle.change(
|
1009 |
-
fn=update_prompt_i2v,
|
1010 |
-
inputs=[img2vid_prompt, img2vid_enhance_toggle],
|
1011 |
-
outputs=img2vid_prompt
|
1012 |
-
)
|
1013 |
-
|
1014 |
-
img2vid_generate.click(
|
1015 |
-
fn=generate_video_from_image,
|
1016 |
-
inputs=[
|
1017 |
-
img2vid_image,
|
1018 |
-
img2vid_prompt,
|
1019 |
-
img2vid_enhance_toggle,
|
1020 |
-
img2vid_negative_prompt,
|
1021 |
-
img2vid_frame_rate,
|
1022 |
-
*img2vid_advanced[:3],
|
1023 |
-
img2vid_current_height,
|
1024 |
-
img2vid_current_width,
|
1025 |
-
img2vid_current_num_frames,
|
1026 |
-
],
|
1027 |
-
outputs=img2vid_output,
|
1028 |
-
concurrency_limit=1,
|
1029 |
-
concurrency_id="generate_video",
|
1030 |
-
queue=True,
|
1031 |
-
)
|
1032 |
-
|
1033 |
-
# Scenario tab event handlers
|
1034 |
-
analyze_btn.click(
|
1035 |
-
fn=analyze_scenario,
|
1036 |
-
inputs=[scenario_input],
|
1037 |
-
outputs=[
|
1038 |
-
section1_prompt, section2_prompt, section3_prompt,
|
1039 |
-
section4_prompt, section5_prompt
|
1040 |
-
]
|
1041 |
-
)
|
1042 |
-
|
1043 |
-
|
1044 |
-
# κ° μΉμ
μ ν둬ννΈ μ¬μμ± μ΄λ²€νΈ νΈλ€λ¬ μΆκ°
|
1045 |
-
section1_regenerate.click(
|
1046 |
-
fn=lambda x: generate_single_section_prompt(x, 1),
|
1047 |
-
inputs=[scenario_input],
|
1048 |
-
outputs=section1_prompt
|
1049 |
-
)
|
1050 |
-
|
1051 |
-
section2_regenerate.click(
|
1052 |
-
fn=lambda x: generate_single_section_prompt(x, 2),
|
1053 |
-
inputs=[scenario_input],
|
1054 |
-
outputs=section2_prompt
|
1055 |
-
)
|
1056 |
-
|
1057 |
-
section3_regenerate.click(
|
1058 |
-
fn=lambda x: generate_single_section_prompt(x, 3),
|
1059 |
-
inputs=[scenario_input],
|
1060 |
-
outputs=section3_prompt
|
1061 |
-
)
|
1062 |
-
|
1063 |
-
section4_regenerate.click(
|
1064 |
-
fn=lambda x: generate_single_section_prompt(x, 4),
|
1065 |
-
inputs=[scenario_input],
|
1066 |
-
outputs=section4_prompt
|
1067 |
-
)
|
1068 |
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
outputs=section1_video,
|
1081 |
-
api_name=f"generate_section1"
|
1082 |
-
)
|
1083 |
-
|
1084 |
-
section2_generate.click(
|
1085 |
-
fn=lambda p, pr: generate_section_video(p, pr, 2),
|
1086 |
-
inputs=[section2_prompt, scenario_preset],
|
1087 |
-
outputs=section2_video,
|
1088 |
-
api_name=f"generate_section2"
|
1089 |
-
)
|
1090 |
-
|
1091 |
-
section3_generate.click(
|
1092 |
-
fn=lambda p, pr: generate_section_video(p, pr, 3),
|
1093 |
-
inputs=[section3_prompt, scenario_preset],
|
1094 |
-
outputs=section3_video,
|
1095 |
-
api_name=f"generate_section3"
|
1096 |
-
)
|
1097 |
-
|
1098 |
-
section4_generate.click(
|
1099 |
-
fn=lambda p, pr: generate_section_video(p, pr, 4),
|
1100 |
-
inputs=[section4_prompt, scenario_preset],
|
1101 |
-
outputs=section4_video,
|
1102 |
-
api_name=f"generate_section4"
|
1103 |
-
)
|
1104 |
-
|
1105 |
-
section5_generate.click(
|
1106 |
-
fn=lambda p, pr: generate_section_video(p, pr, 5),
|
1107 |
-
inputs=[section5_prompt, scenario_preset],
|
1108 |
-
outputs=section5_video,
|
1109 |
-
api_name=f"generate_section5"
|
1110 |
-
)
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
|
1115 |
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1128 |
|
1129 |
-
|
1130 |
if __name__ == "__main__":
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
|
|
|
22 |
import gc
|
23 |
from openai import OpenAI
|
24 |
import re
|
25 |
+
import time
|
26 |
# Load system prompts
|
27 |
system_prompt_t2v = """λΉμ μ λΉλμ€ μμ±μ μν ν둬ννΈ μ λ¬Έκ°μ
λλ€.
|
28 |
μ£Όμ΄μ§ ν둬ννΈλ₯Ό λ€μ ꡬ쑰μ λ§κ² κ°μ ν΄μ£ΌμΈμ:
|
|
|
239 |
vae=vae,
|
240 |
).to(device)
|
241 |
|
|
|
|
|
|
|
|
|
242 |
|
|
|
|
|
|
|
243 |
|
244 |
# Preset options for resolution and frame configuration
|
245 |
# Convert frames to seconds assuming 25 FPS
|
|
|
272 |
]
|
273 |
|
274 |
def preset_changed(preset):
|
275 |
+
selected = next((item for item in preset_options if item["label"] == preset), None)
|
276 |
+
if selected is None:
|
277 |
+
raise gr.Error("Invalid preset selected")
|
278 |
return [
|
279 |
+
gr.State(value=selected["height"]),
|
280 |
+
gr.State(value=selected["width"]),
|
281 |
+
gr.State(value=selected["num_frames"]),
|
282 |
gr.update(visible=False),
|
283 |
gr.update(visible=False),
|
284 |
gr.update(visible=False),
|
285 |
+
]
|
286 |
+
|
287 |
def generate_video_from_text(
|
288 |
+
prompt,
|
289 |
+
enhance_prompt_toggle,
|
290 |
+
negative_prompt,
|
291 |
+
frame_rate,
|
292 |
+
seed,
|
293 |
+
num_inference_steps,
|
294 |
+
guidance_scale,
|
295 |
+
height,
|
296 |
+
width,
|
297 |
+
num_frames,
|
298 |
progress=gr.Progress(),
|
299 |
):
|
300 |
if len(prompt.strip()) < 50:
|
|
|
303 |
duration=5,
|
304 |
)
|
305 |
|
306 |
+
# ν둬ννΈ κ°μ μ΄ νμ±νλ κ²½μ°
|
307 |
+
if enhance_prompt_toggle:
|
308 |
+
prompt = enhance_prompt(prompt, "t2v")
|
309 |
+
|
310 |
# Translate Korean prompts to English
|
311 |
prompt = translate_korean_prompt(prompt)
|
312 |
negative_prompt = translate_korean_prompt(negative_prompt)
|
313 |
|
314 |
+
# κΈ°λ³Έκ° μ€μ
|
315 |
+
height = height or 320
|
316 |
+
width = width or 512
|
317 |
+
num_frames = num_frames or 257
|
318 |
+
frame_rate = frame_rate or 25
|
319 |
+
seed = seed or 171198
|
320 |
+
num_inference_steps = num_inference_steps or 41
|
321 |
+
guidance_scale = guidance_scale or 4.0
|
322 |
+
|
323 |
sample = {
|
324 |
"prompt": prompt,
|
325 |
"prompt_attention_mask": None,
|
|
|
362 |
gc.collect()
|
363 |
|
364 |
output_path = tempfile.mktemp(suffix=".mp4")
|
|
|
365 |
video_np = images.squeeze(0).permute(1, 2, 3, 0).cpu().float().numpy()
|
366 |
video_np = (video_np * 255).astype(np.uint8)
|
367 |
height, width = video_np.shape[1:3]
|
|
|
378 |
|
379 |
def generate_video_from_image(
|
380 |
image_path,
|
381 |
+
prompt,
|
382 |
+
enhance_prompt_toggle,
|
383 |
+
negative_prompt,
|
384 |
+
frame_rate,
|
385 |
+
seed,
|
386 |
+
num_inference_steps,
|
387 |
+
guidance_scale,
|
388 |
+
height,
|
389 |
+
width,
|
390 |
+
num_frames,
|
391 |
progress=gr.Progress(),
|
392 |
):
|
393 |
+
if not image_path:
|
394 |
+
raise gr.Error("μ
λ ₯ μ΄λ―Έμ§λ₯Ό μ 곡ν΄μ£ΌμΈμ.", duration=5)
|
|
|
395 |
|
396 |
if len(prompt.strip()) < 50:
|
397 |
raise gr.Error(
|
|
|
399 |
duration=5,
|
400 |
)
|
401 |
|
402 |
+
# ν둬ννΈ κ°μ μ΄ νμ±νλ κ²½μ°
|
403 |
+
if enhance_prompt_toggle:
|
404 |
+
prompt = enhance_prompt(prompt, "i2v")
|
405 |
|
406 |
# Translate Korean prompts to English
|
407 |
prompt = translate_korean_prompt(prompt)
|
408 |
negative_prompt = translate_korean_prompt(negative_prompt)
|
409 |
|
410 |
+
# κΈ°λ³Έκ° μ€μ
|
411 |
+
height = height or 320
|
412 |
+
width = width or 512
|
413 |
+
num_frames = num_frames or 257
|
414 |
+
frame_rate = frame_rate or 25
|
415 |
+
seed = seed or 171198
|
416 |
+
num_inference_steps = num_inference_steps or 41
|
417 |
+
guidance_scale = guidance_scale or 4.0
|
418 |
+
|
419 |
+
# μ΄λ―Έμ§ λ‘λ λ° μ μ²λ¦¬
|
420 |
media_items = (
|
421 |
load_image_to_tensor_with_resize(image_path, height, width).to(device).detach()
|
422 |
)
|
|
|
464 |
for frame in video_np[..., ::-1]:
|
465 |
out.write(frame)
|
466 |
out.release()
|
467 |
+
|
468 |
except Exception as e:
|
469 |
raise gr.Error(
|
470 |
f"λΉλμ€ μμ± μ€ μ€λ₯κ° λ°μνμ΅λλ€. λ€μ μλν΄μ£ΌμΈμ. μ€λ₯: {e}",
|
|
|
474 |
finally:
|
475 |
torch.cuda.empty_cache()
|
476 |
gc.collect()
|
477 |
+
if 'images' in locals():
|
478 |
+
del images
|
479 |
+
if 'video_np' in locals():
|
480 |
+
del video_np
|
481 |
+
if 'media_items' in locals():
|
482 |
+
del media_items
|
483 |
|
484 |
return output_path
|
485 |
|
|
|
575 |
|
576 |
|
577 |
def analyze_scenario(scenario):
|
578 |
+
"""μλ리μ€λ₯Ό λΆμνμ¬ κ° μΉμ
λ³ λ°°κ²½ μμμ© ν둬ννΈ μμ±"""
|
579 |
+
try:
|
580 |
+
# κ° μΉμ
λ³ ν둬ννΈ μμ±μ μν λ©μμ§ κ΅¬μ±
|
581 |
+
section_prompts = []
|
582 |
+
|
583 |
+
for section_num in range(1, 6):
|
584 |
+
section_descriptions = {
|
585 |
+
1: "λ°°κ²½ λ° νμμ±: μ£Όμ μ μ λ°μ μΈ λΆμκΈ°λ₯Ό νννλ λ°°κ²½ μ¬",
|
586 |
+
2: "ν₯λ―Έ μ λ°: κΈ΄μ₯κ°μ΄λ κ°λ±μ μμνλ λΆμκΈ° μλ λ°°κ²½",
|
587 |
+
3: "ν΄κ²°μ±
μ μ: ν¬λ§μ μ΄κ³ λ°μ ν€μ λ°°κ²½ μ ν",
|
588 |
+
4: "λ³Έλ‘ : μμ κ° μκ³ μ λ’°λλ₯Ό λμ΄λ λ°°κ²½",
|
589 |
+
5: "κ²°λ‘ : μν©νΈ μλ λ§λ¬΄λ¦¬λ₯Ό μν μλμ μΈ λ°°κ²½"
|
590 |
+
}
|
591 |
+
|
592 |
+
messages = [
|
593 |
+
{"role": "system", "content": system_prompt_scenario},
|
594 |
+
{"role": "user", "content": f"""
|
595 |
+
λ€μ μ€ν¬λ¦½νΈμ {section_num}λ²μ§Έ μΉμ
({section_descriptions[section_num]})μ λν
|
596 |
+
λ°°κ²½ μμ ν둬ννΈλ₯Ό μμ±ν΄μ£ΌμΈμ.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
597 |
|
598 |
+
μ€ν¬λ¦½νΈ:
|
599 |
{scenario}
|
600 |
|
601 |
+
μ£Όμμ¬ν:
|
602 |
+
1. ν΄λΉ μΉμ
μ νΉμ±({section_descriptions[section_num]})μ λ§λ λΆμκΈ°μ ν€μ λ°μνμΈμ.
|
603 |
+
2. μ§μ μ μΈ μ ν/μλΉμ€ λ¬μ¬λ νΌνκ³ , κ°μ±μ μ΄κ³ μμ μ μΈ λ°°κ²½ μμμ μ§μ€νμΈμ.
|
604 |
+
3. λ€μ ꡬ쑰λ₯Ό λ°λμ ν¬ν¨νμΈμ:
|
605 |
+
- μ£Όμ λμμ λͺ
νν ν λ¬Έμ₯μΌλ‘ μμ
|
606 |
+
- ꡬ체μ μΈ λμκ³Ό οΏ½οΏ½οΏ½μ€μ²λ₯Ό μκ° μμλλ‘ μ€λͺ
|
607 |
+
- λ°°κ²½κ³Ό νκ²½ μΈλΆ μ¬νμ ꡬ체μ μΌλ‘ ν¬ν¨
|
608 |
+
- μΉ΄λ©λΌ κ°λμ μμ§μμ λͺ
μ
|
609 |
+
- μ‘°λͺ
κ³Ό μμμ μμΈν μ€λͺ
|
610 |
+
- λ³νλ κ°μμ€λ¬μ΄ μ¬κ±΄μ μμ°μ€λ½κ² ν¬ν¨"""}
|
611 |
+
]
|
612 |
+
|
613 |
+
response = client.chat.completions.create(
|
614 |
+
model="gpt-4-1106-preview",
|
615 |
+
messages=messages,
|
616 |
+
max_tokens=1000,
|
617 |
+
temperature=0.7
|
618 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
619 |
|
620 |
+
section_prompt = response.choices[0].message.content.strip()
|
621 |
+
section_prompts.append(f"{section_num}. {section_prompt}")
|
|
|
622 |
|
623 |
+
# API μμ² μ¬μ΄μ 짧μ λλ μ΄ μΆκ°
|
624 |
+
time.sleep(1)
|
625 |
+
|
626 |
+
return section_prompts
|
627 |
|
628 |
except Exception as e:
|
629 |
print(f"Error during scenario analysis: {e}")
|
630 |
return ["Error occurred during analysis"] * 5
|
631 |
|
632 |
def generate_section_video(prompt, preset, section_number=1, base_seed=171198, progress=gr.Progress()):
|
633 |
+
"""κ° μΉμ
μ λΉλμ€ μμ±"""
|
634 |
try:
|
635 |
if not prompt or len(prompt.strip()) < 50:
|
636 |
raise gr.Error("ν둬ννΈλ μ΅μ 50μ μ΄μμ΄μ΄μΌ ν©λλ€.")
|
637 |
|
638 |
+
if not preset:
|
639 |
+
raise gr.Error("ν΄μλ ν리μ
μ μ νν΄μ£ΌμΈμ.")
|
640 |
+
|
641 |
+
selected = next((item for item in preset_options if item["label"] == preset), None)
|
642 |
+
if not selected:
|
643 |
+
raise gr.Error("μ¬λ°λ₯΄μ§ μμ ν리μ
μ
λλ€.")
|
644 |
+
|
645 |
section_seed = base_seed + section_number
|
646 |
|
647 |
return generate_video_from_text(
|
648 |
prompt=prompt,
|
649 |
+
enhance_prompt_toggle=False, # μΉμ
μμ±μλ ν둬ννΈ μ¦κ° λΉνμ±ν
|
650 |
+
negative_prompt="low quality, worst quality, deformed, distorted, warped",
|
651 |
+
frame_rate=25,
|
652 |
+
seed=section_seed,
|
653 |
+
num_inference_steps=41,
|
654 |
+
guidance_scale=4.0,
|
655 |
height=selected["height"],
|
656 |
width=selected["width"],
|
657 |
num_frames=selected["num_frames"],
|
|
|
658 |
progress=progress
|
659 |
)
|
660 |
except Exception as e:
|
661 |
print(f"Error in section {section_number}: {e}")
|
662 |
raise gr.Error(f"μΉμ
{section_number} μμ± μ€ μ€λ₯: {str(e)}")
|
663 |
+
finally:
|
664 |
+
torch.cuda.empty_cache()
|
665 |
+
gc.collect()
|
666 |
|
|
|
667 |
def generate_single_section_prompt(scenario, section_number):
|
668 |
"""κ°λ³ μΉμ
μ λν ν둬ννΈ μμ±"""
|
669 |
section_descriptions = {
|
|
|
678 |
{"role": "system", "content": system_prompt_scenario},
|
679 |
{"role": "user", "content": f"""
|
680 |
λ€μ μ€ν¬λ¦½νΈμ {section_number}λ²μ§Έ μΉμ
({section_descriptions[section_number]})μ λν
|
681 |
+
λ°°κ²½ μμ ν둬ννΈλ₯Ό μμ±ν΄μ£ΌμΈμ.
|
682 |
|
683 |
+
μ€ν¬λ¦½νΈ:
|
684 |
{scenario}
|
685 |
|
686 |
+
μ£Όμμ¬ν:
|
687 |
+
1. ν΄λΉ μΉμ
μ νΉμ±({section_descriptions[section_number]})μ λ§λ λΆμκΈ°μ ν€μ λ°μνμΈμ.
|
688 |
+
2. μ§μ μ μΈ μ ν/μλΉμ€ λ¬μ¬λ νΌνκ³ , κ°μ±μ μ΄κ³ μμ μ μΈ λ°°κ²½ μμμ μ§μ€νμΈμ.
|
689 |
+
3. λ€μ ꡬ쑰λ₯Ό λ°λμ ν¬ν¨νμΈμ:
|
690 |
+
- μ£Όμ λμμ λͺ
νν ν λ¬Έμ₯μΌλ‘ μμ
|
691 |
+
- ꡬ체μ μΈ λμκ³Ό μ μ€μ²λ₯Ό μκ° μμλλ‘ μ€λͺ
|
692 |
+
- λ°°κ²½κ³Ό νκ²½ μΈλΆ μ¬νμ ꡬ체μ μΌλ‘ ν¬ν¨
|
693 |
+
- μΉ΄λ©λΌ κ°λμ μμ§μμ λͺ
μ
|
694 |
+
- μ‘°λͺ
κ³Ό μμμ μμΈν μ€λͺ
|
695 |
+
- λ³νλ κ°μμ€λ¬μ΄ μ¬κ±΄μ μμ°μ€λ½κ² ν¬ν¨"""}
|
696 |
]
|
697 |
|
698 |
try:
|
699 |
response = client.chat.completions.create(
|
700 |
model="gpt-4-1106-preview",
|
701 |
messages=messages,
|
702 |
+
max_tokens=1000, # ν ν° μ μ¦κ°
|
703 |
+
temperature=0.7
|
704 |
)
|
705 |
+
generated_prompt = response.choices[0].message.content.strip()
|
706 |
+
return f"{section_number}. {generated_prompt}"
|
707 |
except Exception as e:
|
708 |
+
print(f"Error during prompt generation for section {section_number}: {e}")
|
709 |
+
return f"Error occurred during prompt generation for section {section_number}"
|
710 |
|
711 |
|
712 |
# λΉλμ€ κ²°ν© ν¨μ μΆκ°
|
|
|
748 |
videos = []
|
749 |
|
750 |
# κ° μΉμ
λΉλμ€ νμΈ λ° μ²λ¦¬
|
751 |
+
for i, video_path in enumerate([section1, section2, section3, section4, section5], 1):
|
752 |
+
if video_path:
|
753 |
+
if os.path.exists(video_path):
|
754 |
+
try:
|
755 |
+
# λΉλμ€ νμΌ κ²μ¦
|
756 |
+
cap = cv2.VideoCapture(video_path)
|
757 |
+
if cap.isOpened():
|
758 |
+
videos.append(video_path)
|
759 |
+
cap.release()
|
760 |
+
else:
|
761 |
+
raise gr.Error(f"μΉμ
{i}μ μμ νμΌμ΄ μμλμκ±°λ μ½μ μ μμ΅λλ€.")
|
762 |
+
except Exception as e:
|
763 |
+
raise gr.Error(f"μΉμ
{i} μμ μ²λ¦¬ μ€ μ€λ₯: {str(e)}")
|
764 |
+
else:
|
765 |
+
raise gr.Error(f"μΉμ
{i}μ μμ νμΌμ μ°Ύμ μ μμ΅λλ€.")
|
766 |
else:
|
767 |
+
raise gr.Error(f"μΉμ
{i}μ μμμ΄ μμ΅λλ€.")
|
768 |
|
769 |
if not videos:
|
770 |
raise gr.Error("κ²°ν©ν μμμ΄ μμ΅λλ€.")
|
|
|
790 |
ret, frame = cap.read()
|
791 |
if not ret:
|
792 |
break
|
793 |
+
# νλ μ ν¬κΈ°κ° λ€λ₯Έ κ²½μ° λ¦¬μ¬μ΄μ¦
|
794 |
if frame.shape[:2] != (height, width):
|
795 |
frame = cv2.resize(frame, (width, height))
|
796 |
out.write(frame)
|
797 |
cap.release()
|
798 |
|
799 |
out.release()
|
800 |
+
print(f"Successfully merged {len(videos)} videos")
|
801 |
return output_path
|
802 |
|
803 |
except Exception as e:
|
804 |
raise gr.Error(f"λΉλμ€ κ²°ν© μ€ μ€λ₯ λ°μ: {e}")
|
805 |
|
806 |
+
def generate_script(topic):
|
807 |
+
"""μ£Όμ μ λ§λ μ€ν¬λ¦½νΈ μμ±"""
|
808 |
+
if not topic:
|
809 |
+
return "μ£Όμ λ₯Ό μ
λ ₯ν΄μ£ΌμΈμ."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
810 |
|
811 |
+
messages = [
|
812 |
+
{"role": "system", "content": """λΉμ μ μμ μ€ν¬λ¦½νΈ μμ± μ λ¬Έκ°μ
λλ€.
|
813 |
+
μ£Όμ΄μ§ μ£Όμ λ‘ λ€μ ꡬ쑰μ λ§λ 5κ° μΉμ
μ μ€ν¬λ¦½νΈλ₯Ό μμ±ν΄μ£ΌμΈμ:
|
814 |
+
|
815 |
+
1. λ°°κ²½ λ° νμμ±: μ£Όμ μκ°μ μμ²μμ ν₯λ―Έ μ λ°
|
816 |
+
2. ν₯λ―Έ μ λ°: ꡬ체μ μΈ λ΄μ© μ κ°μ νΈκΈ°μ¬ μκ·Ή
|
817 |
+
3. ν΄κ²°μ±
μ μ: ν΅μ¬ λ΄μ©κ³Ό ν΄κ²°λ°©μ μ μ
|
818 |
+
4. λ³Έλ‘ : μμΈν μ€λͺ
κ³Ό μ₯μ λΆκ°
|
819 |
+
5. κ²°λ‘ : ν΅μ¬ λ©μμ§ κ°μ‘°μ νλ μ λ
|
820 |
+
|
821 |
+
κ° μΉμ
μ μμ°μ€λ½κ² μ°κ²°λμ΄μΌ νλ©°,
|
822 |
+
μ 체μ μΌλ‘ μΌκ΄λ ν€κ³Ό λΆμκΈ°λ₯Ό μ μ§νλ©΄μλ
|
823 |
+
μμ²μμ κ΄μ¬μ λκΉμ§ μ μ§ν μ μλλ‘ μμ±ν΄μ£ΌμΈμ."""},
|
824 |
+
{"role": "user", "content": f"λ€μ μ£Όμ λ‘ μμ μ€ν¬λ¦½νΈλ₯Ό μμ±ν΄μ£ΌμΈμ: {topic}"}
|
825 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
826 |
|
827 |
+
try:
|
828 |
+
response = client.chat.completions.create(
|
829 |
+
model="gpt-4-1106-preview",
|
830 |
+
messages=messages,
|
831 |
+
max_tokens=2000,
|
832 |
+
temperature=0.7
|
833 |
+
)
|
834 |
+
return response.choices[0].message.content.strip()
|
835 |
+
except Exception as e:
|
836 |
+
print(f"Error during script generation: {e}")
|
837 |
+
return "μ€ν¬λ¦½νΈ μμ± μ€ μ€λ₯κ° λ°μνμ΅λλ€."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
838 |
|
839 |
|
840 |
+
def cleanup():
|
841 |
+
"""λ©λͺ¨λ¦¬ μ 리 ν¨μ"""
|
842 |
+
torch.cuda.empty_cache()
|
843 |
+
gc.collect()
|
844 |
+
|
845 |
+
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange") as iface:
|
846 |
+
# State λ³μλ€μ μ΄κΈ°ν
|
847 |
+
txt2vid_current_height = gr.State(value=320)
|
848 |
+
txt2vid_current_width = gr.State(value=512)
|
849 |
+
txt2vid_current_num_frames = gr.State(value=257)
|
850 |
+
|
851 |
+
img2vid_current_height = gr.State(value=320)
|
852 |
+
img2vid_current_width = gr.State(value=512)
|
853 |
+
img2vid_current_num_frames = gr.State(value=257)
|
854 |
+
|
855 |
+
with gr.Tabs():
|
856 |
+
# Text to Video Tab
|
857 |
+
with gr.TabItem("ν
μ€νΈλ‘ λΉλμ€ λ§λ€κΈ°"):
|
858 |
+
with gr.Row():
|
859 |
+
with gr.Column():
|
860 |
+
txt2vid_prompt = gr.Textbox(
|
861 |
+
label="Step 1: ν둬ννΈ μ
λ ₯",
|
862 |
+
placeholder="μμ±νκ³ μΆμ λΉλμ€λ₯Ό μ€λͺ
νμΈμ (μ΅μ 50μ)...",
|
863 |
+
value="κ·μ¬μ΄ κ³ μμ΄",
|
864 |
+
lines=5,
|
865 |
+
)
|
866 |
+
txt2vid_enhance_toggle = Toggle(
|
867 |
+
label="ν둬ννΈ μ¦κ°",
|
868 |
+
value=False,
|
869 |
+
interactive=True,
|
870 |
+
)
|
871 |
+
txt2vid_negative_prompt = gr.Textbox(
|
872 |
+
label="Step 2: λ€κ±°ν°λΈ ν둬ννΈ μ
λ ₯",
|
873 |
+
placeholder="λΉλμ€μμ μνμ§ μλ μμλ₯Ό μ€λͺ
νμΈμ...",
|
874 |
+
value="low quality, worst quality, deformed, distorted, warped, motion smear, motion artifacts, fused fingers, incorrect anatomy, strange hands, unattractive",
|
875 |
+
lines=2,
|
876 |
+
visible=False
|
877 |
+
)
|
878 |
+
txt2vid_preset = gr.Dropdown(
|
879 |
+
choices=[p["label"] for p in preset_options],
|
880 |
+
value="[16:9] 512x320, 10.3μ΄",
|
881 |
+
label="Step 2: ν΄μλ ν리μ
μ ν",
|
882 |
+
)
|
883 |
+
txt2vid_frame_rate = gr.Slider(
|
884 |
+
label="Step 3: νλ μ λ μ΄νΈ",
|
885 |
+
minimum=21,
|
886 |
+
maximum=30,
|
887 |
+
step=1,
|
888 |
+
value=25,
|
889 |
+
visible=False
|
890 |
+
)
|
891 |
+
txt2vid_advanced = create_advanced_options()
|
892 |
+
txt2vid_generate = gr.Button(
|
893 |
+
"Step 3: λΉλμ€ μμ±",
|
894 |
+
variant="primary",
|
895 |
+
size="lg",
|
896 |
+
)
|
897 |
+
with gr.Column():
|
898 |
+
txt2vid_output = gr.Video(label="μμ±λ λΉλμ€")
|
899 |
+
|
900 |
+
|
901 |
+
# Image to Video Tab
|
902 |
+
with gr.TabItem("μ΄λ―Έμ§λ‘ λΉλμ€ λ§λ€κΈ°"):
|
903 |
+
with gr.Row():
|
904 |
+
with gr.Column():
|
905 |
+
img2vid_image = gr.Image(
|
906 |
+
type="filepath",
|
907 |
+
label="Step 1: μ
λ ₯ μ΄λ―Έμ§ μ
λ‘λ",
|
908 |
+
elem_id="image_upload",
|
909 |
+
)
|
910 |
+
img2vid_prompt = gr.Textbox(
|
911 |
+
label="Step 2: ν둬ννΈ μ
λ ₯",
|
912 |
+
placeholder="μ΄λ―Έμ§λ₯Ό μ΄λ»κ² μ λλ©μ΄μ
νν μ§ μ€λͺ
νμΈμ (μ΅μ 50μ)...",
|
913 |
+
value="κ·μ¬μ΄ κ³ μμ΄",
|
914 |
+
lines=5,
|
915 |
+
)
|
916 |
+
img2vid_enhance_toggle = Toggle(
|
917 |
+
label="ν둬ννΈ μ¦κ°",
|
918 |
+
value=False,
|
919 |
+
interactive=True,
|
920 |
+
)
|
921 |
+
img2vid_negative_prompt = gr.Textbox(
|
922 |
+
label="Step 3: λ€κ±°ν°λΈ ν둬ννΈ μ
λ ₯",
|
923 |
+
placeholder="λΉλμ€μμ μνμ§ μλ μμλ₯Ό μ€λͺ
νμΈμ...",
|
924 |
+
value="low quality, worst quality, deformed, distorted, warped, motion smear, motion artifacts, fused fingers, incorrect anatomy, strange hands, unattractive",
|
925 |
+
lines=2,
|
926 |
+
visible=False
|
927 |
+
)
|
928 |
+
img2vid_preset = gr.Dropdown(
|
929 |
+
choices=[p["label"] for p in preset_options],
|
930 |
+
value="[16:9] 512x320, 10.3μ΄",
|
931 |
+
label="Step 3: ν΄μλ ν리μ
μ ν",
|
932 |
+
)
|
933 |
+
img2vid_frame_rate = gr.Slider(
|
934 |
+
label="Step 4: νλ μ λ μ΄νΈ",
|
935 |
+
minimum=21,
|
936 |
+
maximum=30,
|
937 |
+
step=1,
|
938 |
+
value=25,
|
939 |
+
visible=False
|
940 |
+
)
|
941 |
+
img2vid_advanced = create_advanced_options()
|
942 |
+
img2vid_generate = gr.Button(
|
943 |
+
"Step 4: λΉλμ€ μμ±",
|
944 |
+
variant="primary",
|
945 |
+
size="lg",
|
946 |
+
)
|
947 |
+
with gr.Column():
|
948 |
+
img2vid_output = gr.Video(label="μμ±λ λΉλμ€")
|
949 |
+
|
950 |
+
|
951 |
+
# Scenario Tab
|
952 |
+
with gr.TabItem("μλ리μ€λ‘ λΉλμ€ λ§λ€κΈ°(μνΌ)"):
|
953 |
+
with gr.Row():
|
954 |
+
with gr.Column(scale=1):
|
955 |
+
script_topic = gr.Textbox(
|
956 |
+
label="μ€ν¬λ¦½νΈ μμ±",
|
957 |
+
placeholder="κ²¨μΈ μΌλ³Έ μ¨μ² μ¬νμ μ£Όμ λ‘ λ°μ λλμΌλ‘ μ€ν¬λ¦½νΈ μμ±νλΌ",
|
958 |
+
lines=2
|
959 |
+
)
|
960 |
+
generate_script_btn = gr.Button("μ€ν¬λ¦½νΈ μμ±", variant="primary")
|
961 |
+
|
962 |
+
scenario_input = gr.Textbox(
|
963 |
+
label="μμ μ€ν¬λ¦½νΈ μ
λ ₯",
|
964 |
+
placeholder="μ 체 μλ리μ€λ₯Ό μ
λ ₯νμΈμ...",
|
965 |
+
lines=10
|
966 |
+
)
|
967 |
+
scenario_preset = gr.Dropdown(
|
968 |
+
choices=[p["label"] for p in preset_options],
|
969 |
+
value="[16:9] 512x320, 10.3μ΄",
|
970 |
+
label="νλ©΄ ν¬κΈ° μ ν"
|
971 |
+
)
|
972 |
+
analyze_btn = gr.Button("μλλ¦¬μ€ λΆμ λ° ν둬ννΈ μμ±", variant="primary")
|
973 |
+
|
974 |
+
with gr.Column(scale=2):
|
975 |
+
with gr.Row():
|
976 |
+
# μΉμ
1
|
977 |
+
with gr.Column():
|
978 |
+
section1_prompt = gr.Textbox(
|
979 |
+
label="1. λ°°κ²½ λ° νμμ±",
|
980 |
+
lines=4
|
981 |
+
)
|
982 |
+
with gr.Row():
|
983 |
+
section1_regenerate = gr.Button("π ν둬ννΈ μμ±")
|
984 |
+
section1_generate = gr.Button("π μμ μμ±")
|
985 |
+
section1_video = gr.Video(label="μΉμ
1 μμ")
|
986 |
+
|
987 |
+
# μΉμ
2
|
988 |
+
with gr.Column():
|
989 |
+
section2_prompt = gr.Textbox(
|
990 |
+
label="2. ν₯λ―Έ μ λ°",
|
991 |
+
lines=4
|
992 |
+
)
|
993 |
+
with gr.Row():
|
994 |
+
section2_regenerate = gr.Button("π ν둬ννΈ μμ±")
|
995 |
+
section2_generate = gr.Button("π μμ μμ±")
|
996 |
+
section2_video = gr.Video(label="μΉμ
2 μμ")
|
997 |
+
|
998 |
+
|
999 |
+
|
1000 |
+
with gr.Row():
|
1001 |
+
# μΉμ
3
|
1002 |
+
with gr.Column():
|
1003 |
+
section3_prompt = gr.Textbox(
|
1004 |
+
label="3. ν΄κ²°μ±
μ μ",
|
1005 |
+
lines=4
|
1006 |
+
)
|
1007 |
+
with gr.Row():
|
1008 |
+
section3_regenerate = gr.Button("π ν둬ννΈ μμ±")
|
1009 |
+
section3_generate = gr.Button("π μμ μμ±")
|
1010 |
+
section3_video = gr.Video(label="μΉμ
3 μμ")
|
1011 |
+
|
1012 |
+
# μΉμ
4
|
1013 |
+
with gr.Column():
|
1014 |
+
section4_prompt = gr.Textbox(
|
1015 |
+
label="4. λ³Έλ‘ ",
|
1016 |
+
lines=4
|
1017 |
+
)
|
1018 |
+
with gr.Row():
|
1019 |
+
section4_regenerate = gr.Button("π ν둬ννΈ μμ±")
|
1020 |
+
section4_generate = gr.Button("π μμ μμ±")
|
1021 |
+
section4_video = gr.Video(label="μΉμ
4 μμ")
|
1022 |
+
|
1023 |
+
with gr.Row():
|
1024 |
+
# μΉμ
5
|
1025 |
+
with gr.Column():
|
1026 |
+
section5_prompt = gr.Textbox(
|
1027 |
+
label="5. κ²°λ‘ λ° κ°μ‘°",
|
1028 |
+
lines=4
|
1029 |
+
)
|
1030 |
+
with gr.Row():
|
1031 |
+
section5_regenerate = gr.Button("π ν둬ννΈ μμ±")
|
1032 |
+
section5_generate = gr.Button("π μμ μμ±")
|
1033 |
+
section5_video = gr.Video(label="μΉμ
5 μμ")
|
1034 |
+
|
1035 |
+
# ν΅ν© μμ μΉμ
|
1036 |
+
with gr.Row():
|
1037 |
+
with gr.Column(scale=1):
|
1038 |
+
merge_videos_btn = gr.Button("ν΅ν© μμ μμ±", variant="primary", size="lg")
|
1039 |
+
|
1040 |
+
with gr.Column(scale=2):
|
1041 |
+
with gr.Row():
|
1042 |
+
merged_video_output = gr.Video(label="ν΅ν© μμ")
|
1043 |
+
|
1044 |
+
|
1045 |
+
# Text to Video Tab handlers
|
1046 |
+
txt2vid_preset.change(
|
1047 |
+
fn=preset_changed,
|
1048 |
+
inputs=[txt2vid_preset],
|
1049 |
+
outputs=[
|
1050 |
+
txt2vid_current_height,
|
1051 |
+
txt2vid_current_width,
|
1052 |
+
txt2vid_current_num_frames,
|
1053 |
+
txt2vid_advanced[3], # height_slider
|
1054 |
+
txt2vid_advanced[4], # width_slider
|
1055 |
+
txt2vid_advanced[5], # num_frames_slider
|
1056 |
+
]
|
1057 |
+
)
|
1058 |
+
|
1059 |
+
txt2vid_enhance_toggle.change(
|
1060 |
+
fn=update_prompt_t2v,
|
1061 |
+
inputs=[txt2vid_prompt, txt2vid_enhance_toggle],
|
1062 |
+
outputs=txt2vid_prompt
|
1063 |
+
)
|
1064 |
+
|
1065 |
+
txt2vid_generate.click(
|
1066 |
+
fn=generate_video_from_text,
|
1067 |
+
inputs=[
|
1068 |
+
txt2vid_prompt,
|
1069 |
+
txt2vid_enhance_toggle,
|
1070 |
+
txt2vid_negative_prompt,
|
1071 |
+
txt2vid_frame_rate,
|
1072 |
+
txt2vid_advanced[0], # seed
|
1073 |
+
txt2vid_advanced[1], # inference_steps
|
1074 |
+
txt2vid_advanced[2], # guidance_scale
|
1075 |
+
txt2vid_current_height,
|
1076 |
+
txt2vid_current_width,
|
1077 |
+
txt2vid_current_num_frames,
|
1078 |
+
],
|
1079 |
+
outputs=txt2vid_output,
|
1080 |
+
)
|
1081 |
+
|
1082 |
+
# Image to Video Tab handlers
|
1083 |
+
img2vid_preset.change(
|
1084 |
+
fn=preset_changed,
|
1085 |
+
inputs=[img2vid_preset],
|
1086 |
+
outputs=[
|
1087 |
+
img2vid_current_height,
|
1088 |
+
img2vid_current_width,
|
1089 |
+
img2vid_current_num_frames,
|
1090 |
+
img2vid_advanced[3], # height_slider
|
1091 |
+
img2vid_advanced[4], # width_slider
|
1092 |
+
img2vid_advanced[5], # num_frames_slider
|
1093 |
+
]
|
1094 |
+
)
|
1095 |
+
|
1096 |
+
img2vid_enhance_toggle.change(
|
1097 |
+
fn=update_prompt_i2v,
|
1098 |
+
inputs=[img2vid_prompt, img2vid_enhance_toggle],
|
1099 |
+
outputs=img2vid_prompt
|
1100 |
+
)
|
1101 |
+
|
1102 |
+
img2vid_generate.click(
|
1103 |
+
fn=generate_video_from_image,
|
1104 |
+
inputs=[
|
1105 |
+
img2vid_image,
|
1106 |
+
img2vid_prompt,
|
1107 |
+
img2vid_enhance_toggle,
|
1108 |
+
img2vid_negative_prompt,
|
1109 |
+
img2vid_frame_rate,
|
1110 |
+
img2vid_advanced[0], # seed
|
1111 |
+
img2vid_advanced[1], # inference_steps
|
1112 |
+
img2vid_advanced[2], # guidance_scale
|
1113 |
+
img2vid_current_height,
|
1114 |
+
img2vid_current_width,
|
1115 |
+
img2vid_current_num_frames,
|
1116 |
+
],
|
1117 |
+
outputs=img2vid_output,
|
1118 |
+
)
|
1119 |
+
|
1120 |
+
|
1121 |
+
|
1122 |
+
# Scenario Tab handlers
|
1123 |
+
generate_script_btn.click(
|
1124 |
+
fn=generate_script,
|
1125 |
+
inputs=[script_topic],
|
1126 |
+
outputs=[scenario_input]
|
1127 |
+
)
|
1128 |
+
|
1129 |
+
analyze_btn.click(
|
1130 |
+
fn=analyze_scenario,
|
1131 |
+
inputs=[scenario_input],
|
1132 |
+
outputs=[
|
1133 |
+
section1_prompt, section2_prompt, section3_prompt,
|
1134 |
+
section4_prompt, section5_prompt
|
1135 |
+
]
|
1136 |
+
)
|
1137 |
+
|
1138 |
+
# μΉμ
λ³ ν둬ννΈ μ¬μμ± νΈλ€λ¬
|
1139 |
+
section1_regenerate.click(
|
1140 |
+
fn=lambda x: generate_single_section_prompt(x, 1),
|
1141 |
+
inputs=[scenario_input],
|
1142 |
+
outputs=section1_prompt
|
1143 |
+
)
|
1144 |
+
|
1145 |
+
section2_regenerate.click(
|
1146 |
+
fn=lambda x: generate_single_section_prompt(x, 2),
|
1147 |
+
inputs=[scenario_input],
|
1148 |
+
outputs=section2_prompt
|
1149 |
+
)
|
1150 |
+
|
1151 |
+
section3_regenerate.click(
|
1152 |
+
fn=lambda x: generate_single_section_prompt(x, 3),
|
1153 |
+
inputs=[scenario_input],
|
1154 |
+
outputs=section3_prompt
|
1155 |
+
)
|
1156 |
+
|
1157 |
+
section4_regenerate.click(
|
1158 |
+
fn=lambda x: generate_single_section_prompt(x, 4),
|
1159 |
+
inputs=[scenario_input],
|
1160 |
+
outputs=section4_prompt
|
1161 |
+
)
|
1162 |
+
|
1163 |
+
section5_regenerate.click(
|
1164 |
+
fn=lambda x: generate_single_section_prompt(x, 5),
|
1165 |
+
inputs=[scenario_input],
|
1166 |
+
outputs=section5_prompt
|
1167 |
+
)
|
1168 |
+
|
1169 |
+
# μΉμ
λ³ λΉλμ€ μμ± νΈλ€λ¬
|
1170 |
+
section1_generate.click(
|
1171 |
+
fn=lambda p, pr: generate_section_video(p, pr, 1),
|
1172 |
+
inputs=[section1_prompt, scenario_preset],
|
1173 |
+
outputs=section1_video
|
1174 |
+
)
|
1175 |
+
|
1176 |
+
section2_generate.click(
|
1177 |
+
fn=lambda p, pr: generate_section_video(p, pr, 2),
|
1178 |
+
inputs=[section2_prompt, scenario_preset],
|
1179 |
+
outputs=section2_video
|
1180 |
+
)
|
1181 |
+
|
1182 |
+
section3_generate.click(
|
1183 |
+
fn=lambda p, pr: generate_section_video(p, pr, 3),
|
1184 |
+
inputs=[section3_prompt, scenario_preset],
|
1185 |
+
outputs=section3_video
|
1186 |
+
)
|
1187 |
+
|
1188 |
+
section4_generate.click(
|
1189 |
+
fn=lambda p, pr: generate_section_video(p, pr, 4),
|
1190 |
+
inputs=[section4_prompt, scenario_preset],
|
1191 |
+
outputs=section4_video
|
1192 |
+
)
|
1193 |
+
|
1194 |
+
section5_generate.click(
|
1195 |
+
fn=lambda p, pr: generate_section_video(p, pr, 5),
|
1196 |
+
inputs=[section5_prompt, scenario_preset],
|
1197 |
+
outputs=section5_video
|
1198 |
+
)
|
1199 |
+
|
1200 |
+
# ν΅ν© μμ μμ± νΈλ€λ¬
|
1201 |
+
merge_videos_btn.click(
|
1202 |
+
fn=merge_section_videos,
|
1203 |
+
inputs=[
|
1204 |
+
section1_video,
|
1205 |
+
section2_video,
|
1206 |
+
section3_video,
|
1207 |
+
section4_video,
|
1208 |
+
section5_video
|
1209 |
+
],
|
1210 |
+
outputs=merged_video_output
|
1211 |
+
)
|
1212 |
|
|
|
1213 |
if __name__ == "__main__":
|
1214 |
+
iface.queue(max_size=64, default_concurrency_limit=1, api_open=False).launch(
|
1215 |
+
share=True,
|
1216 |
+
show_api=False
|
1217 |
+
)
|