Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -69,16 +69,54 @@ def contains_korean(text):
|
|
| 69 |
korean_pattern = re.compile('[ใฑ-ใ
ใ
-ใ
ฃ๊ฐ-ํฃ]')
|
| 70 |
return bool(korean_pattern.search(text))
|
| 71 |
|
| 72 |
-
def translate_korean_prompt(prompt):
|
| 73 |
"""
|
| 74 |
Translate Korean prompt to English if Korean text is detected
|
|
|
|
| 75 |
"""
|
| 76 |
-
if contains_korean(prompt):
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
print(f"Original Korean prompt: {prompt}")
|
| 79 |
-
print(f"Translated English prompt: {
|
| 80 |
-
return
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
def enhance_prompt(prompt, type="t2v"):
|
| 84 |
system_prompt = system_prompt_t2v if type == "t2v" else system_prompt_i2v
|
|
@@ -554,20 +592,25 @@ def analyze_scenario(scenario):
|
|
| 554 |
return ["Error occurred during analysis"] * 5
|
| 555 |
|
| 556 |
def generate_section_video(prompt, preset, section_number=1, base_seed=171198, progress=gr.Progress()):
|
| 557 |
-
"""๊ฐ ์น์
์ ๋น๋์ค ์์ฑ -
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 571 |
|
| 572 |
|
| 573 |
# ๊ฐ๋ณ ์น์
ํ๋กฌํํธ ์์ฑ ํจ์ ์ถ๊ฐ
|
|
@@ -930,37 +973,44 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
| 930 |
]
|
| 931 |
)
|
| 932 |
|
| 933 |
-
|
| 934 |
-
|
| 935 |
-
fn=
|
| 936 |
-
inputs=[
|
| 937 |
-
outputs=
|
|
|
|
| 938 |
)
|
| 939 |
-
|
| 940 |
-
|
| 941 |
-
fn=lambda
|
| 942 |
-
inputs=[
|
| 943 |
-
outputs=
|
|
|
|
| 944 |
)
|
| 945 |
-
|
| 946 |
-
|
| 947 |
-
fn=lambda
|
| 948 |
-
inputs=[
|
| 949 |
-
outputs=
|
|
|
|
| 950 |
)
|
| 951 |
-
|
| 952 |
-
|
| 953 |
-
fn=lambda
|
| 954 |
-
inputs=[
|
| 955 |
-
outputs=
|
|
|
|
| 956 |
)
|
| 957 |
-
|
| 958 |
-
|
| 959 |
-
fn=lambda
|
| 960 |
-
inputs=[
|
| 961 |
-
outputs=
|
|
|
|
| 962 |
)
|
| 963 |
|
|
|
|
|
|
|
| 964 |
# ์น์
์์ฑ ์ด๋ฒคํธ ํธ๋ค๋ฌ
|
| 965 |
section1_generate.click(
|
| 966 |
fn=lambda p, pr: generate_section_video(p, pr, 1),
|
|
|
|
| 69 |
korean_pattern = re.compile('[ใฑ-ใ
ใ
-ใ
ฃ๊ฐ-ํฃ]')
|
| 70 |
return bool(korean_pattern.search(text))
|
| 71 |
|
| 72 |
+
def translate_korean_prompt(prompt, max_length=450):
|
| 73 |
"""
|
| 74 |
Translate Korean prompt to English if Korean text is detected
|
| 75 |
+
Split long text into chunks if necessary
|
| 76 |
"""
|
| 77 |
+
if not contains_korean(prompt):
|
| 78 |
+
return prompt
|
| 79 |
+
|
| 80 |
+
# Split long text into chunks
|
| 81 |
+
def split_text(text, max_length):
|
| 82 |
+
words = text.split()
|
| 83 |
+
chunks = []
|
| 84 |
+
current_chunk = []
|
| 85 |
+
current_length = 0
|
| 86 |
+
|
| 87 |
+
for word in words:
|
| 88 |
+
if current_length + len(word) + 1 > max_length:
|
| 89 |
+
chunks.append(' '.join(current_chunk))
|
| 90 |
+
current_chunk = [word]
|
| 91 |
+
current_length = len(word)
|
| 92 |
+
else:
|
| 93 |
+
current_chunk.append(word)
|
| 94 |
+
current_length += len(word) + 1
|
| 95 |
+
|
| 96 |
+
if current_chunk:
|
| 97 |
+
chunks.append(' '.join(current_chunk))
|
| 98 |
+
return chunks
|
| 99 |
+
|
| 100 |
+
try:
|
| 101 |
+
if len(prompt) > max_length:
|
| 102 |
+
chunks = split_text(prompt, max_length)
|
| 103 |
+
translated_chunks = []
|
| 104 |
+
|
| 105 |
+
for chunk in chunks:
|
| 106 |
+
translated = translator(chunk, max_length=512)[0]['translation_text']
|
| 107 |
+
translated_chunks.append(translated)
|
| 108 |
+
|
| 109 |
+
final_translation = ' '.join(translated_chunks)
|
| 110 |
+
else:
|
| 111 |
+
final_translation = translator(prompt, max_length=512)[0]['translation_text']
|
| 112 |
+
|
| 113 |
print(f"Original Korean prompt: {prompt}")
|
| 114 |
+
print(f"Translated English prompt: {final_translation}")
|
| 115 |
+
return final_translation
|
| 116 |
+
|
| 117 |
+
except Exception as e:
|
| 118 |
+
print(f"Translation error: {e}")
|
| 119 |
+
return prompt # Return original prompt if translation fails
|
| 120 |
|
| 121 |
def enhance_prompt(prompt, type="t2v"):
|
| 122 |
system_prompt = system_prompt_t2v if type == "t2v" else system_prompt_i2v
|
|
|
|
| 592 |
return ["Error occurred during analysis"] * 5
|
| 593 |
|
| 594 |
def generate_section_video(prompt, preset, section_number=1, base_seed=171198, progress=gr.Progress()):
|
| 595 |
+
"""๊ฐ ์น์
์ ๋น๋์ค ์์ฑ - ์๋ฌ ์ฒ๋ฆฌ ์ถ๊ฐ"""
|
| 596 |
+
try:
|
| 597 |
+
if not prompt or len(prompt.strip()) < 50:
|
| 598 |
+
raise gr.Error("ํ๋กฌํํธ๋ ์ต์ 50์ ์ด์์ด์ด์ผ ํฉ๋๋ค.")
|
| 599 |
+
|
| 600 |
+
selected = next(item for item in preset_options if item["label"] == preset)
|
| 601 |
+
section_seed = base_seed + section_number
|
| 602 |
+
|
| 603 |
+
return generate_video_from_text(
|
| 604 |
+
prompt=prompt,
|
| 605 |
+
height=selected["height"],
|
| 606 |
+
width=selected["width"],
|
| 607 |
+
num_frames=selected["num_frames"],
|
| 608 |
+
seed=section_seed,
|
| 609 |
+
progress=progress
|
| 610 |
+
)
|
| 611 |
+
except Exception as e:
|
| 612 |
+
print(f"Error in section {section_number}: {e}")
|
| 613 |
+
raise gr.Error(f"์น์
{section_number} ์์ฑ ์ค ์ค๋ฅ: {str(e)}")
|
| 614 |
|
| 615 |
|
| 616 |
# ๊ฐ๋ณ ์น์
ํ๋กฌํํธ ์์ฑ ํจ์ ์ถ๊ฐ
|
|
|
|
| 973 |
]
|
| 974 |
)
|
| 975 |
|
| 976 |
+
# ์น์
์์ฑ ์ด๋ฒคํธ ํธ๋ค๋ฌ
|
| 977 |
+
section1_generate.click(
|
| 978 |
+
fn=generate_section_video,
|
| 979 |
+
inputs=[section1_prompt, scenario_preset],
|
| 980 |
+
outputs=section1_video,
|
| 981 |
+
api_name=f"generate_section1"
|
| 982 |
)
|
| 983 |
+
|
| 984 |
+
section2_generate.click(
|
| 985 |
+
fn=lambda p, pr: generate_section_video(p, pr, 2),
|
| 986 |
+
inputs=[section2_prompt, scenario_preset],
|
| 987 |
+
outputs=section2_video,
|
| 988 |
+
api_name=f"generate_section2"
|
| 989 |
)
|
| 990 |
+
|
| 991 |
+
section3_generate.click(
|
| 992 |
+
fn=lambda p, pr: generate_section_video(p, pr, 3),
|
| 993 |
+
inputs=[section3_prompt, scenario_preset],
|
| 994 |
+
outputs=section3_video,
|
| 995 |
+
api_name=f"generate_section3"
|
| 996 |
)
|
| 997 |
+
|
| 998 |
+
section4_generate.click(
|
| 999 |
+
fn=lambda p, pr: generate_section_video(p, pr, 4),
|
| 1000 |
+
inputs=[section4_prompt, scenario_preset],
|
| 1001 |
+
outputs=section4_video,
|
| 1002 |
+
api_name=f"generate_section4"
|
| 1003 |
)
|
| 1004 |
+
|
| 1005 |
+
section5_generate.click(
|
| 1006 |
+
fn=lambda p, pr: generate_section_video(p, pr, 5),
|
| 1007 |
+
inputs=[section5_prompt, scenario_preset],
|
| 1008 |
+
outputs=section5_video,
|
| 1009 |
+
api_name=f"generate_section5"
|
| 1010 |
)
|
| 1011 |
|
| 1012 |
+
|
| 1013 |
+
|
| 1014 |
# ์น์
์์ฑ ์ด๋ฒคํธ ํธ๋ค๋ฌ
|
| 1015 |
section1_generate.click(
|
| 1016 |
fn=lambda p, pr: generate_section_video(p, pr, 1),
|