openfree commited on
Commit
00f24f4
β€’
1 Parent(s): 0e0a395

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +185 -18
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], # seed, inference_steps, guidance_scale
631
- txt2vid_current_height, # State λ³€μˆ˜ μ°Έμ‘°
632
- txt2vid_current_width, # State λ³€μˆ˜ μ°Έμ‘°
633
- txt2vid_current_num_frames, # State λ³€μˆ˜ μ°Έμ‘°
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], # seed, inference_steps, guidance_scale
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