Spaces:
Running
on
L40S
Running
on
L40S
Update app.py
Browse files
app.py
CHANGED
@@ -491,6 +491,74 @@ def create_advanced_options():
|
|
491 |
num_frames_slider,
|
492 |
]
|
493 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
494 |
# Gradio Interface Definition
|
495 |
with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
496 |
with gr.Tabs():
|
@@ -518,14 +586,12 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
518 |
visible=False
|
519 |
)
|
520 |
|
521 |
-
|
522 |
txt2vid_preset = gr.Dropdown(
|
523 |
choices=[p["label"] for p in preset_options],
|
524 |
-
value="[16:9] 512x320, 10.3μ΄",
|
525 |
label="Step 2: ν΄μλ ν리μ
μ ν",
|
526 |
)
|
527 |
|
528 |
-
|
529 |
txt2vid_frame_rate = gr.Slider(
|
530 |
label="Step 3: νλ μ λ μ΄νΈ",
|
531 |
minimum=21,
|
@@ -573,14 +639,11 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
573 |
visible=False
|
574 |
)
|
575 |
|
576 |
-
|
577 |
img2vid_preset = gr.Dropdown(
|
578 |
choices=[p["label"] for p in preset_options],
|
579 |
-
value="[16:9] 512x320, 10.3μ΄",
|
580 |
label="Step 3: ν΄μλ ν리μ
μ ν",
|
581 |
-
)
|
582 |
-
|
583 |
-
|
584 |
|
585 |
img2vid_frame_rate = gr.Slider(
|
586 |
label="Step 4: νλ μ λ μ΄νΈ",
|
@@ -601,6 +664,72 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
601 |
with gr.Column():
|
602 |
img2vid_output = gr.Video(label="μμ±λ λΉλμ€")
|
603 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
604 |
txt2vid_preset.change(
|
605 |
fn=preset_changed,
|
606 |
inputs=[txt2vid_preset],
|
@@ -610,16 +739,14 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
610 |
txt2vid_current_num_frames,
|
611 |
*txt2vid_advanced[3:]
|
612 |
]
|
613 |
-
)
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
|
618 |
txt2vid_enhance_toggle.change(
|
619 |
fn=update_prompt_t2v,
|
620 |
inputs=[txt2vid_prompt, txt2vid_enhance_toggle],
|
621 |
outputs=txt2vid_prompt
|
622 |
)
|
|
|
623 |
txt2vid_generate.click(
|
624 |
fn=generate_video_from_text,
|
625 |
inputs=[
|
@@ -627,11 +754,11 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
627 |
txt2vid_enhance_toggle,
|
628 |
txt2vid_negative_prompt,
|
629 |
txt2vid_frame_rate,
|
630 |
-
*txt2vid_advanced[:3],
|
631 |
-
txt2vid_current_height,
|
632 |
-
txt2vid_current_width,
|
633 |
-
txt2vid_current_num_frames,
|
634 |
-
|
635 |
outputs=txt2vid_output,
|
636 |
concurrency_limit=1,
|
637 |
concurrency_id="generate_video",
|
@@ -663,7 +790,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
663 |
img2vid_enhance_toggle,
|
664 |
img2vid_negative_prompt,
|
665 |
img2vid_frame_rate,
|
666 |
-
*img2vid_advanced[:3],
|
667 |
img2vid_current_height,
|
668 |
img2vid_current_width,
|
669 |
img2vid_current_num_frames,
|
@@ -674,6 +801,46 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
674 |
queue=True,
|
675 |
)
|
676 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
677 |
if __name__ == "__main__":
|
678 |
iface.queue(max_size=64, default_concurrency_limit=1, api_open=False).launch(
|
679 |
share=True, show_api=False
|
|
|
491 |
num_frames_slider,
|
492 |
]
|
493 |
|
494 |
+
|
495 |
+
# μλλ¦¬μ€ λΆμ λ° ν둬ννΈ μμ±μ μν μμ€ν
ν둬ννΈ
|
496 |
+
system_prompt_scenario = """λΉμ μ μμ μλ리μ€λ₯Ό 5κ°μ μΉμ
μΌλ‘ λλκ³ κ°κ°μ λν λΉλμ€ μμ± ν둬ννΈλ₯Ό μμ±νλ μ λ¬Έκ°μ
λλ€.
|
497 |
+
μ£Όμ΄μ§ μλ리μ€λ₯Ό λ€μ 5κ° μΉμ
μΌλ‘ λλμ΄ κ°κ°μ ν둬ννΈλ₯Ό μμ±ν΄μ£ΌμΈμ:
|
498 |
+
|
499 |
+
1. λ°°κ²½ λ° νμμ±: μ£Όμ μ λ°°κ²½κ³Ό μ€μμ±μ μκ°μ μΌλ‘ νν
|
500 |
+
2. λ¬Έμ μ κΈ° λ° ν₯λ―Έ μ λ°: ν΅μ¬ λ¬Έμ λ ν₯λ―Έλ‘μ΄ ν¬μΈνΈλ₯Ό λλΌλ§ν±νκ² νν
|
501 |
+
3. ν΄κ²°μ±
μ μ: μ£Όμ ν΄κ²°λ°©μμ΄λ μ κ·Όλ²μ μκ°μ μΌλ‘ μ μ
|
502 |
+
4. λ³Έλ‘ : ν΅μ¬ λ΄μ©μ μμΈν μ€λͺ
νλ μκ°μ νν
|
503 |
+
5. κ²°λ‘ λ° κ°μ‘°: μ£Όμ ν¬μΈνΈλ₯Ό λ€μ νλ² κ°μ‘°νκ³ λ§λ¬΄λ¦¬
|
504 |
+
|
505 |
+
κ° μΉμ
μ ν둬ννΈλ λ€μ μμλ₯Ό ν¬ν¨ν΄μΌ ν©λλ€:
|
506 |
+
- μ£Όμ μκ°μ μμμ λμ
|
507 |
+
- μΉ΄λ©λΌ μμ§μκ³Ό μ΅κΈ
|
508 |
+
- μ₯λ©΄ μ νκ³Ό ν¨κ³Ό
|
509 |
+
- λΆμκΈ°μ ν€
|
510 |
+
- λ±μ₯ μμλ€μ μΈλΆ λ¬μ¬
|
511 |
+
|
512 |
+
κ° μΉμ
μ 10μ΄ λΆλμ μμμ μμ±ν μ μλλ‘ κ΅¬μ²΄μ μ΄κ³ μκ°μ μΈ μ€λͺ
μ ν¬ν¨ν΄μΌ ν©λλ€."""
|
513 |
+
|
514 |
+
def analyze_scenario(scenario):
|
515 |
+
"""μλ리μ€λ₯Ό λΆμνμ¬ 5κ°μ μΉμ
μΌλ‘ λλκ³ κ°κ°μ ν둬ννΈλ₯Ό μμ±"""
|
516 |
+
messages = [
|
517 |
+
{"role": "system", "content": system_prompt_scenario},
|
518 |
+
{"role": "user", "content": scenario},
|
519 |
+
]
|
520 |
+
|
521 |
+
try:
|
522 |
+
response = client.chat.completions.create(
|
523 |
+
model="gpt-4-1106-preview",
|
524 |
+
messages=messages,
|
525 |
+
max_tokens=2000,
|
526 |
+
)
|
527 |
+
prompts = response.choices[0].message.content.strip().split("\n\n")
|
528 |
+
|
529 |
+
# 5κ°μ μΉμ
μΌλ‘ μ 리
|
530 |
+
section_prompts = []
|
531 |
+
current_section = ""
|
532 |
+
for line in prompts:
|
533 |
+
if line.strip():
|
534 |
+
if any(section in line for section in ["1.", "2.", "3.", "4.", "5."]):
|
535 |
+
if current_section:
|
536 |
+
section_prompts.append(current_section)
|
537 |
+
current_section = line
|
538 |
+
else:
|
539 |
+
current_section += "\n" + line
|
540 |
+
if current_section:
|
541 |
+
section_prompts.append(current_section)
|
542 |
+
|
543 |
+
# μ νν 5κ°μ μΉμ
μ΄ λλλ‘ μ‘°μ
|
544 |
+
while len(section_prompts) < 5:
|
545 |
+
section_prompts.append("μΆκ° μΉμ
μ΄ νμν©λλ€.")
|
546 |
+
return section_prompts[:5]
|
547 |
+
except Exception as e:
|
548 |
+
print(f"Error during scenario analysis: {e}")
|
549 |
+
return ["Error occurred during analysis"] * 5
|
550 |
+
|
551 |
+
def generate_section_video(prompt, preset, progress=gr.Progress()):
|
552 |
+
"""κ° μΉμ
μ λΉλμ€ μμ±"""
|
553 |
+
selected = next(item for item in preset_options if item["label"] == preset)
|
554 |
+
return generate_video_from_text(
|
555 |
+
prompt=prompt,
|
556 |
+
height=selected["height"],
|
557 |
+
width=selected["width"],
|
558 |
+
num_frames=selected["num_frames"],
|
559 |
+
progress=progress
|
560 |
+
)
|
561 |
+
|
562 |
# Gradio Interface Definition
|
563 |
with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
564 |
with gr.Tabs():
|
|
|
586 |
visible=False
|
587 |
)
|
588 |
|
|
|
589 |
txt2vid_preset = gr.Dropdown(
|
590 |
choices=[p["label"] for p in preset_options],
|
591 |
+
value="[16:9] 512x320, 10.3μ΄",
|
592 |
label="Step 2: ν΄μλ ν리μ
μ ν",
|
593 |
)
|
594 |
|
|
|
595 |
txt2vid_frame_rate = gr.Slider(
|
596 |
label="Step 3: νλ μ λ μ΄νΈ",
|
597 |
minimum=21,
|
|
|
639 |
visible=False
|
640 |
)
|
641 |
|
|
|
642 |
img2vid_preset = gr.Dropdown(
|
643 |
choices=[p["label"] for p in preset_options],
|
644 |
+
value="[16:9] 512x320, 10.3μ΄",
|
645 |
label="Step 3: ν΄μλ ν리μ
μ ν",
|
646 |
+
)
|
|
|
|
|
647 |
|
648 |
img2vid_frame_rate = gr.Slider(
|
649 |
label="Step 4: νλ μ λ μ΄νΈ",
|
|
|
664 |
with gr.Column():
|
665 |
img2vid_output = gr.Video(label="μμ±λ λΉλμ€")
|
666 |
|
667 |
+
# Scenario to Video Tab (New)
|
668 |
+
with gr.TabItem("μλ리μ€λ‘ λΉλμ€ λ§λ€κΈ°(μνΌ)"):
|
669 |
+
with gr.Row():
|
670 |
+
with gr.Column(scale=1):
|
671 |
+
scenario_input = gr.Textbox(
|
672 |
+
label="μμ μ€ν¬λ¦½νΈ μ
λ ₯",
|
673 |
+
placeholder="μ 체 μλ리μ€λ₯Ό μ
λ ₯νμΈμ...",
|
674 |
+
lines=10
|
675 |
+
)
|
676 |
+
scenario_preset = gr.Dropdown(
|
677 |
+
choices=[p["label"] for p in preset_options],
|
678 |
+
value="[16:9] 512x320, 10.3μ΄",
|
679 |
+
label="νλ©΄ ν¬κΈ° μ ν"
|
680 |
+
)
|
681 |
+
analyze_btn = gr.Button("μλλ¦¬μ€ λΆμ λ° ν둬ννΈ μμ±", variant="primary")
|
682 |
+
|
683 |
+
with gr.Column(scale=2):
|
684 |
+
with gr.Row():
|
685 |
+
# μΉμ
1
|
686 |
+
with gr.Column():
|
687 |
+
section1_prompt = gr.Textbox(
|
688 |
+
label="1. λ°°κ²½ λ° νμμ±",
|
689 |
+
lines=4
|
690 |
+
)
|
691 |
+
section1_generate = gr.Button("μμ±")
|
692 |
+
section1_video = gr.Video(label="μΉμ
1 μμ")
|
693 |
+
|
694 |
+
# μΉμ
2
|
695 |
+
with gr.Column():
|
696 |
+
section2_prompt = gr.Textbox(
|
697 |
+
label="2. λ¬Έμ μ κΈ° λ° ν₯λ―Έ μ λ°",
|
698 |
+
lines=4
|
699 |
+
)
|
700 |
+
section2_generate = gr.Button("μμ±")
|
701 |
+
section2_video = gr.Video(label="μΉμ
2 μμ")
|
702 |
+
|
703 |
+
with gr.Row():
|
704 |
+
# μΉμ
3
|
705 |
+
with gr.Column():
|
706 |
+
section3_prompt = gr.Textbox(
|
707 |
+
label="3. ν΄κ²°μ±
μ μ",
|
708 |
+
lines=4
|
709 |
+
)
|
710 |
+
section3_generate = gr.Button("μμ±")
|
711 |
+
section3_video = gr.Video(label="μΉμ
3 μμ")
|
712 |
+
|
713 |
+
# μΉμ
4
|
714 |
+
with gr.Column():
|
715 |
+
section4_prompt = gr.Textbox(
|
716 |
+
label="4. λ³Έλ‘ ",
|
717 |
+
lines=4
|
718 |
+
)
|
719 |
+
section4_generate = gr.Button("μμ±")
|
720 |
+
section4_video = gr.Video(label="μΉμ
4 μμ")
|
721 |
+
|
722 |
+
with gr.Row():
|
723 |
+
# μΉμ
5
|
724 |
+
with gr.Column():
|
725 |
+
section5_prompt = gr.Textbox(
|
726 |
+
label="5. κ²°λ‘ λ° κ°μ‘°",
|
727 |
+
lines=4
|
728 |
+
)
|
729 |
+
section5_generate = gr.Button("μμ±")
|
730 |
+
section5_video = gr.Video(label="μΉμ
5 μμ")
|
731 |
+
|
732 |
+
# Event handlers
|
733 |
txt2vid_preset.change(
|
734 |
fn=preset_changed,
|
735 |
inputs=[txt2vid_preset],
|
|
|
739 |
txt2vid_current_num_frames,
|
740 |
*txt2vid_advanced[3:]
|
741 |
]
|
742 |
+
)
|
|
|
|
|
|
|
743 |
|
744 |
txt2vid_enhance_toggle.change(
|
745 |
fn=update_prompt_t2v,
|
746 |
inputs=[txt2vid_prompt, txt2vid_enhance_toggle],
|
747 |
outputs=txt2vid_prompt
|
748 |
)
|
749 |
+
|
750 |
txt2vid_generate.click(
|
751 |
fn=generate_video_from_text,
|
752 |
inputs=[
|
|
|
754 |
txt2vid_enhance_toggle,
|
755 |
txt2vid_negative_prompt,
|
756 |
txt2vid_frame_rate,
|
757 |
+
*txt2vid_advanced[:3],
|
758 |
+
txt2vid_current_height,
|
759 |
+
txt2vid_current_width,
|
760 |
+
txt2vid_current_num_frames,
|
761 |
+
],
|
762 |
outputs=txt2vid_output,
|
763 |
concurrency_limit=1,
|
764 |
concurrency_id="generate_video",
|
|
|
790 |
img2vid_enhance_toggle,
|
791 |
img2vid_negative_prompt,
|
792 |
img2vid_frame_rate,
|
793 |
+
*img2vid_advanced[:3],
|
794 |
img2vid_current_height,
|
795 |
img2vid_current_width,
|
796 |
img2vid_current_num_frames,
|
|
|
801 |
queue=True,
|
802 |
)
|
803 |
|
804 |
+
# Scenario tab event handlers
|
805 |
+
analyze_btn.click(
|
806 |
+
fn=analyze_scenario,
|
807 |
+
inputs=[scenario_input],
|
808 |
+
outputs=[
|
809 |
+
section1_prompt, section2_prompt, section3_prompt,
|
810 |
+
section4_prompt, section5_prompt
|
811 |
+
]
|
812 |
+
)
|
813 |
+
|
814 |
+
section1_generate.click(
|
815 |
+
fn=generate_section_video,
|
816 |
+
inputs=[section1_prompt, scenario_preset],
|
817 |
+
outputs=section1_video
|
818 |
+
)
|
819 |
+
|
820 |
+
section2_generate.click(
|
821 |
+
fn=generate_section_video,
|
822 |
+
inputs=[section2_prompt, scenario_preset],
|
823 |
+
outputs=section2_video
|
824 |
+
)
|
825 |
+
|
826 |
+
section3_generate.click(
|
827 |
+
fn=generate_section_video,
|
828 |
+
inputs=[section3_prompt, scenario_preset],
|
829 |
+
outputs=section3_video
|
830 |
+
)
|
831 |
+
|
832 |
+
section4_generate.click(
|
833 |
+
fn=generate_section_video,
|
834 |
+
inputs=[section4_prompt, scenario_preset],
|
835 |
+
outputs=section4_video
|
836 |
+
)
|
837 |
+
|
838 |
+
section5_generate.click(
|
839 |
+
fn=generate_section_video,
|
840 |
+
inputs=[section5_prompt, scenario_preset],
|
841 |
+
outputs=section5_video
|
842 |
+
)
|
843 |
+
|
844 |
if __name__ == "__main__":
|
845 |
iface.queue(max_size=64, default_concurrency_limit=1, api_open=False).launch(
|
846 |
share=True, show_api=False
|