Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -604,6 +604,51 @@ def generate_single_section_prompt(scenario, section_number):
|
|
| 604 |
return "Error occurred during prompt generation"
|
| 605 |
|
| 606 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 607 |
# Gradio Interface Definition
|
| 608 |
with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
| 609 |
with gr.Tabs():
|
|
@@ -735,19 +780,19 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
| 735 |
lines=4
|
| 736 |
)
|
| 737 |
with gr.Row():
|
| 738 |
-
section1_regenerate = gr.Button("π ν둬ννΈ
|
| 739 |
-
section1_generate = gr.Button("μμ±")
|
| 740 |
section1_video = gr.Video(label="μΉμ
1 μμ")
|
| 741 |
|
| 742 |
# μΉμ
2
|
| 743 |
with gr.Column():
|
| 744 |
section2_prompt = gr.Textbox(
|
| 745 |
-
label="2.
|
| 746 |
lines=4
|
| 747 |
)
|
| 748 |
with gr.Row():
|
| 749 |
-
section2_regenerate = gr.Button("π ν둬ννΈ
|
| 750 |
-
section2_generate = gr.Button("μμ±")
|
| 751 |
section2_video = gr.Video(label="μΉμ
2 μμ")
|
| 752 |
|
| 753 |
with gr.Row():
|
|
@@ -758,8 +803,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
| 758 |
lines=4
|
| 759 |
)
|
| 760 |
with gr.Row():
|
| 761 |
-
section3_regenerate = gr.Button("π ν둬ννΈ
|
| 762 |
-
section3_generate = gr.Button("μμ±")
|
| 763 |
section3_video = gr.Video(label="μΉμ
3 μμ")
|
| 764 |
|
| 765 |
# μΉμ
4
|
|
@@ -769,8 +814,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
| 769 |
lines=4
|
| 770 |
)
|
| 771 |
with gr.Row():
|
| 772 |
-
section4_regenerate = gr.Button("π ν둬ννΈ
|
| 773 |
-
section4_generate = gr.Button("μμ±")
|
| 774 |
section4_video = gr.Video(label="μΉμ
4 μμ")
|
| 775 |
|
| 776 |
with gr.Row():
|
|
@@ -781,10 +826,28 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
| 781 |
lines=4
|
| 782 |
)
|
| 783 |
with gr.Row():
|
| 784 |
-
section5_regenerate = gr.Button("π ν둬ννΈ
|
| 785 |
-
section5_generate = gr.Button("μμ±")
|
| 786 |
section5_video = gr.Video(label="μΉμ
5 μμ")
|
| 787 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 788 |
# Event handlers
|
| 789 |
txt2vid_preset.change(
|
| 790 |
fn=preset_changed,
|
|
@@ -929,6 +992,20 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
| 929 |
outputs=section5_video
|
| 930 |
)
|
| 931 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 932 |
|
| 933 |
if __name__ == "__main__":
|
| 934 |
iface.queue(max_size=64, default_concurrency_limit=1, api_open=False).launch(
|
|
|
|
| 604 |
return "Error occurred during prompt generation"
|
| 605 |
|
| 606 |
|
| 607 |
+
# λΉλμ€ κ²°ν© ν¨μ μΆκ°
|
| 608 |
+
def combine_videos(video_paths, output_path):
|
| 609 |
+
"""μ¬λ¬ λΉλμ€λ₯Ό νλλ‘ κ²°ν©"""
|
| 610 |
+
if not all(video_paths):
|
| 611 |
+
raise gr.Error("λͺ¨λ μΉμ
μ μμμ΄ μμ±λμ΄μΌ ν©λλ€.")
|
| 612 |
+
|
| 613 |
+
try:
|
| 614 |
+
# 첫 λ²μ§Έ λΉλμ€μ μμ± κ°μ Έμ€κΈ°
|
| 615 |
+
cap = cv2.VideoCapture(video_paths[0])
|
| 616 |
+
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
| 617 |
+
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
| 618 |
+
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 619 |
+
cap.release()
|
| 620 |
+
|
| 621 |
+
# μΆλ ₯ λΉλμ€ μ€μ
|
| 622 |
+
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 623 |
+
out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
|
| 624 |
+
|
| 625 |
+
# κ° λΉλμ€ μμ°¨μ μΌλ‘ κ²°ν©
|
| 626 |
+
for video_path in video_paths:
|
| 627 |
+
if video_path and os.path.exists(video_path):
|
| 628 |
+
cap = cv2.VideoCapture(video_path)
|
| 629 |
+
while True:
|
| 630 |
+
ret, frame = cap.read()
|
| 631 |
+
if not ret:
|
| 632 |
+
break
|
| 633 |
+
out.write(frame)
|
| 634 |
+
cap.release()
|
| 635 |
+
|
| 636 |
+
out.release()
|
| 637 |
+
return output_path
|
| 638 |
+
except Exception as e:
|
| 639 |
+
raise gr.Error(f"λΉλμ€ κ²°ν© μ€ μ€λ₯ λ°μ: {e}")
|
| 640 |
+
|
| 641 |
+
def merge_section_videos(section1, section2, section3, section4, section5):
|
| 642 |
+
"""μΉμ
λΉλμ€λ€μ νλλ‘ κ²°ν©"""
|
| 643 |
+
videos = [section1, section2, section3, section4, section5]
|
| 644 |
+
|
| 645 |
+
if not all(videos):
|
| 646 |
+
raise gr.Error("λͺ¨λ μΉμ
μ μμμ΄ λ¨Όμ μμ±λμ΄μΌ ν©λλ€.")
|
| 647 |
+
|
| 648 |
+
output_path = tempfile.mktemp(suffix=".mp4")
|
| 649 |
+
return combine_videos(videos, output_path)
|
| 650 |
+
|
| 651 |
+
|
| 652 |
# Gradio Interface Definition
|
| 653 |
with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
| 654 |
with gr.Tabs():
|
|
|
|
| 780 |
lines=4
|
| 781 |
)
|
| 782 |
with gr.Row():
|
| 783 |
+
section1_regenerate = gr.Button("π ν둬ννΈ μμ±")
|
| 784 |
+
section1_generate = gr.Button("π μμ μμ±")
|
| 785 |
section1_video = gr.Video(label="μΉμ
1 μμ")
|
| 786 |
|
| 787 |
# μΉμ
2
|
| 788 |
with gr.Column():
|
| 789 |
section2_prompt = gr.Textbox(
|
| 790 |
+
label="2. ν₯λ―Έ μ λ°",
|
| 791 |
lines=4
|
| 792 |
)
|
| 793 |
with gr.Row():
|
| 794 |
+
section2_regenerate = gr.Button("π ν둬ννΈ μμ±")
|
| 795 |
+
section2_generate = gr.Button("π μμ μμ±")
|
| 796 |
section2_video = gr.Video(label="μΉμ
2 μμ")
|
| 797 |
|
| 798 |
with gr.Row():
|
|
|
|
| 803 |
lines=4
|
| 804 |
)
|
| 805 |
with gr.Row():
|
| 806 |
+
section3_regenerate = gr.Button("π ν둬ννΈ μμ±")
|
| 807 |
+
section3_generate = gr.Button("π μμ μμ±")
|
| 808 |
section3_video = gr.Video(label="μΉμ
3 μμ")
|
| 809 |
|
| 810 |
# μΉμ
4
|
|
|
|
| 814 |
lines=4
|
| 815 |
)
|
| 816 |
with gr.Row():
|
| 817 |
+
section4_regenerate = gr.Button("π ν둬ννΈ μμ±")
|
| 818 |
+
section4_generate = gr.Button("π μμ μμ±")
|
| 819 |
section4_video = gr.Video(label="μΉμ
4 μμ")
|
| 820 |
|
| 821 |
with gr.Row():
|
|
|
|
| 826 |
lines=4
|
| 827 |
)
|
| 828 |
with gr.Row():
|
| 829 |
+
section5_regenerate = gr.Button("π ν둬ννΈ μμ±")
|
| 830 |
+
section5_generate = gr.Button("π μμ μμ±")
|
| 831 |
section5_video = gr.Video(label="μΉμ
5 μμ")
|
| 832 |
|
| 833 |
+
|
| 834 |
+
|
| 835 |
+
# ν΅ν© μμ μΉμ
μΆκ°
|
| 836 |
+
with gr.Row():
|
| 837 |
+
with gr.Column(scale=1):
|
| 838 |
+
# κΈ°μ‘΄μ scenario_inputκ³Ό analyze_btn μ μ§
|
| 839 |
+
merge_videos_btn = gr.Button("ν΅ν© μμ μμ±", variant="primary", size="lg")
|
| 840 |
+
|
| 841 |
+
with gr.Column(scale=2):
|
| 842 |
+
# κΈ°μ‘΄μ μΉμ
1-5 μ μ§
|
| 843 |
+
|
| 844 |
+
# ν΅ν© μμ μΆλ ₯ μΉμ
μΆκ°
|
| 845 |
+
with gr.Row():
|
| 846 |
+
merged_video_output = gr.Video(label="ν΅ν© μμ")
|
| 847 |
+
|
| 848 |
+
|
| 849 |
+
|
| 850 |
+
|
| 851 |
# Event handlers
|
| 852 |
txt2vid_preset.change(
|
| 853 |
fn=preset_changed,
|
|
|
|
| 992 |
outputs=section5_video
|
| 993 |
)
|
| 994 |
|
| 995 |
+
|
| 996 |
+
# μ΄λ²€νΈ νΈλ€λ¬ μΆκ°
|
| 997 |
+
merge_videos_btn.click(
|
| 998 |
+
fn=merge_section_videos,
|
| 999 |
+
inputs=[
|
| 1000 |
+
section1_video,
|
| 1001 |
+
section2_video,
|
| 1002 |
+
section3_video,
|
| 1003 |
+
section4_video,
|
| 1004 |
+
section5_video
|
| 1005 |
+
],
|
| 1006 |
+
outputs=merged_video_output
|
| 1007 |
+
)
|
| 1008 |
+
|
| 1009 |
|
| 1010 |
if __name__ == "__main__":
|
| 1011 |
iface.queue(max_size=64, default_concurrency_limit=1, api_open=False).launch(
|