Nabule1990 commited on
Commit
daef2da
·
verified ·
1 Parent(s): b92de4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -13
app.py CHANGED
@@ -749,7 +749,7 @@ def resolve_actor_voice(speaker_tag: str, main_voice: str, lang_key: str, task_m
749
 
750
 
751
  def build_pro_prompt(task_mode: str, genre_prompt: str, lang_key: str, current_is_first: bool, previous_chunk_memory: str, custom_prompt: str, video_duration_sec: float = 60.0, chunk_idx: int = 1, total_chunks: int = 1, narrator_gender: str = "male"):
752
- target_name = {"myanmar": "Burmese", "english": "English", "thai": "Thai", "chinese": "Simplified Chinese"}.get(lang_key, "Burmese")
753
 
754
  memory_injection = (
755
  f"🎬 [MASTER STORY MEMORY & CONTINUITY - PART {chunk_idx} OF {total_chunks}]:\n"
@@ -803,6 +803,15 @@ def build_pro_prompt(task_mode: str, genre_prompt: str, lang_key: str, current_i
803
  "2. 外国角色名全部音译为标准中文(例如:'约翰'、'亚历克斯'、'玛丽'),全剧严格保持统一中文译名。\n"
804
  "3. 年份、日期、金额与数量全部采用自然中文表述(例如:'1995年'、'500美元'、'3个人'),确保配音连贯。\n"
805
  )
 
 
 
 
 
 
 
 
 
806
  elif lang_key == "english":
807
  skip_title_rule = "🚫 [STRICT RULE]: Do NOT speak or read movie title cards or credits. Start narrating directly from the first character action.\n"
808
  first_person_word = "'I'"
@@ -1141,8 +1150,9 @@ async def process_video_task_pro(
1141
  lang_clean = to_str(lang, "myanmar").lower().strip()
1142
  is_thai_mode = ("thai" in lang_clean) or ("thai" in v_check) or ("th-" in v_check) or ("ထိုင်း" in v_check)
1143
  is_chinese_mode = ("chinese" in lang_clean) or ("chinese" in v_check) or ("zh-" in v_check) or ("တရုတ်" in v_check)
 
1144
  is_eng_mode = ("english" in lang_clean) or ("english" in v_check) or ("en-" in v_check) or ("အင်္ဂလိပ်" in v_check)
1145
- lang_key = "thai" if is_thai_mode else "chinese" if is_chinese_mode else "english" if is_eng_mode else "myanmar"
1146
 
1147
  task_mode = to_str(task_mode, "pro_recap").lower()
1148
  script_text = to_str(script_text)
@@ -1786,6 +1796,7 @@ async def process_video_task_pro(
1786
  font_name = "Zawgyi-One"
1787
  if is_thai_mode: font_name = "Kanit"
1788
  elif is_chinese_mode: font_name = "Noto Sans SC"
 
1789
  elif is_eng_mode: font_name = "Kanit"
1790
 
1791
  with open(sub_file, "w", encoding="utf-8") as f:
@@ -1810,18 +1821,20 @@ async def process_video_task_pro(
1810
 
1811
  is_thai_text = is_thai_mode or bool(re.search(r'[\u0E00-\u0E7F]', clean_text))
1812
  is_chinese_text = is_chinese_mode or bool(re.search(r'[\u4E00-\u9FFF]', clean_text))
 
1813
 
1814
  ratio_limits = {
1815
  "myanmar": {"9:16": 8, "4:5": 8, "1:1": 9, "4:3": 11, "16:9": 13},
1816
  "thai": {"9:16": 12, "4:5": 12, "1:1": 14, "4:3": 17, "16:9": 20},
1817
  "chinese": {"9:16": 8, "4:5": 8, "1:1": 10, "4:3": 12, "16:9": 15},
 
1818
  "english": {"9:16": 20, "4:5": 20, "1:1": 24, "4:3": 28, "16:9": 34}
1819
  }
1820
 
1821
  short_chunks = []
1822
 
1823
- if is_chinese_text:
1824
- limit_zh = ratio_limits["chinese"].get(ratio_str, 12)
1825
  zh_tokens = re.findall(r"[a-zA-Z0-9]+|[^\sa-zA-Z0-9]", clean_text)
1826
  temp_str = ""; count = 0
1827
  for tk in zh_tokens:
@@ -1924,7 +1937,7 @@ async def process_video_task_pro(
1924
  if marquee_toggle == "on" and marquee_text:
1925
  font_path = os.path.join(USER_FONT_DIR, "Zawgyi-One.ttf").replace('\\', '/')
1926
  safe_text = to_str(marquee_text).replace("'", "").replace(":", "\\:")
1927
- if not is_thai_mode and not is_chinese_mode and not is_eng_mode:
1928
  try: safe_text = rabbit.Rabbit.uni2zg(safe_text)
1929
  except: pass
1930
  mq_y = to_float(marquee_y, 90.0) / 100.0 * target_h
@@ -2394,8 +2407,9 @@ async def process_video_task(job_id: str, user_id: str, file_path: str, wm_path:
2394
  lang_clean = to_str(lang, "myanmar").lower().strip()
2395
  is_thai_mode = ("thai" in lang_clean) or ("thai" in v_check) or ("th-" in v_check) or ("ထိုင်း" in v_check)
2396
  is_chinese_mode = ("chinese" in lang_clean) or ("chinese" in v_check) or ("zh-" in v_check) or ("တရုတ်" in v_check)
 
2397
  is_eng_mode = ("english" in lang_clean) or ("english" in v_check) or ("en-" in v_check) or ("အင်္ဂလိပ်" in v_check)
2398
- lang_key = "thai" if is_thai_mode else "chinese" if is_chinese_mode else "english" if is_eng_mode else "myanmar"
2399
  task_mode = (task_mode or "single_voice").strip().lower()
2400
  voice2_name = (voice2_name or "").strip()
2401
  script_text = (script_text or "").strip()
@@ -2547,7 +2561,7 @@ async def process_video_task(job_id: str, user_id: str, file_path: str, wm_path:
2547
  video_file_ai = None
2548
 
2549
  if not is_direct_script_render:
2550
- target_name = {"myanmar": "Burmese", "english": "English", "thai": "Thai", "chinese": "Simplified Chinese"}.get(lang_key, lang_key)
2551
  style_header = (
2552
  f"🔥 [HIGHEST PRIORITY - MANDATORY SPEAKING & TRANSLATION STYLE ({str(genre or 'original').upper()})]:\n"
2553
  f"{genre_prompt}\n"
@@ -2736,7 +2750,7 @@ async def process_video_task(job_id: str, user_id: str, file_path: str, wm_path:
2736
  clean_txt = clean_txt.replace('*', '').strip()
2737
 
2738
  if is_eng_mode or is_thai_mode: clean_txt = re.sub(r'[\t\n\r]+', ' ', clean_txt)
2739
- elif is_chinese_mode: clean_txt = re.sub(r'\s+', '', clean_txt)
2740
  else:
2741
  clean_txt = re.sub(r'[\u0E00-\u0E7F]+', '', clean_txt)
2742
  clean_txt = re.sub(r'[\u4E00-\u9FFF]+', '', clean_txt)
@@ -3079,6 +3093,7 @@ async def process_video_task(job_id: str, user_id: str, file_path: str, wm_path:
3079
  font_name = "Zawgyi-One"
3080
  if is_thai_mode: font_name = "Kanit"
3081
  elif is_chinese_mode: font_name = "Noto Sans SC"
 
3082
  elif is_eng_mode: font_name = "Kanit"
3083
 
3084
  with open(sub_file, "w", encoding="utf-8") as f:
@@ -3100,11 +3115,11 @@ async def process_video_task(job_id: str, user_id: str, file_path: str, wm_path:
3100
  for res in chunk_results:
3101
  sync_start_ms = res.get("final_start_ms", 0); sync_dur_ms = res.get("actual_dur", 0); clean_text = res.get("clean_text", "")
3102
  if not clean_text: continue
3103
- if not is_thai_mode and not is_chinese_mode and not is_eng_mode:
3104
  try: clean_text = rabbit.Rabbit.uni2zg(clean_text)
3105
  except: pass
3106
 
3107
- if is_chinese_mode:
3108
  zh_tokens = re.findall(r"[a-zA-Z0-9]+|[^\sa-zA-Z0-9]", clean_text); short_chunks = []; temp_str = ""; count = 0
3109
  for tk in zh_tokens:
3110
  temp_str += tk; count += 1
@@ -3156,11 +3171,11 @@ async def process_video_task(job_id: str, user_id: str, file_path: str, wm_path:
3156
  current_start = line_data.get("time_ms", 0); current_end = line_data.get("orig_end_ms", current_start + 2000)
3157
  clean_text = re.sub(r'\[.*?\]', '', line_data.get("text", "")).strip()
3158
  if not clean_text: continue
3159
- if not is_thai_mode and not is_chinese_mode and not is_eng_mode:
3160
  try: clean_text = rabbit.Rabbit.uni2zg(clean_text)
3161
  except: pass
3162
 
3163
- if is_chinese_mode:
3164
  zh_tokens = re.findall(r"[a-zA-Z0-9]+|[^\sa-zA-Z0-9]", clean_text); short_chunks = []; temp_str = ""; count = 0
3165
  for tk in zh_tokens:
3166
  temp_str += tk; count += 1
@@ -3271,7 +3286,7 @@ async def process_video_task(job_id: str, user_id: str, file_path: str, wm_path:
3271
  if marquee_toggle == "on" and marquee_text:
3272
  font_path = os.path.join(USER_FONT_DIR, "Zawgyi-One.ttf").replace(chr(92), '/')
3273
  safe_text = to_str(marquee_text).replace("'", "").replace(":", f"\:")
3274
- if not is_thai_mode and not is_chinese_mode and not is_eng_mode:
3275
  try: safe_text = rabbit.Rabbit.uni2zg(safe_text)
3276
  except: pass
3277
  mq_y = to_float(marquee_y, 90.0) / 100.0 * target_h
 
749
 
750
 
751
  def build_pro_prompt(task_mode: str, genre_prompt: str, lang_key: str, current_is_first: bool, previous_chunk_memory: str, custom_prompt: str, video_duration_sec: float = 60.0, chunk_idx: int = 1, total_chunks: int = 1, narrator_gender: str = "male"):
752
+ target_name = {"myanmar": "Burmese", "english": "English", "thai": "Thai", "chinese": "Simplified Chinese", "japanese": "Japanese"}.get(lang_key, "Burmese")
753
 
754
  memory_injection = (
755
  f"🎬 [MASTER STORY MEMORY & CONTINUITY - PART {chunk_idx} OF {total_chunks}]:\n"
 
803
  "2. 外国角色名全部音译为标准中文(例如:'约翰'、'亚历克斯'、'玛丽'),全剧严格保持统一中文译名。\n"
804
  "3. 年份、日期、金额与数量全部采用自然中文表述(例如:'1995年'、'500美元'、'3个人'),确保配音连贯。\n"
805
  )
806
+ elif lang_key == "japanese":
807
+ skip_title_rule = "🚫 [重要ルール]: 映画のタイトル、クレジット、画面上の文字を読み上げたり言及したりせず、最初のキャラクターの行動から直接ナレーションを始めてください。\n"
808
+ first_person_word = "'私'"
809
+ localization_rules = (
810
+ "⚠️ [自然な日本語ナレーション - 登場人物名と数字の完全ローカライズ (CRITICAL FOR NATURAL TTS)]:\n"
811
+ "1. [MM:SS - MM:SS] 形式のタイムスタンプのみ英語のまま残し、ナレーション本文に英語の単語を混ぜないでください。\n"
812
+ "2. 外国の登場人物名はすべてカタカナに音訳し(例:'ジョン'、'アレックス'、'メアリー')、全編を通して同じ表記を維持してください。\n"
813
+ "3. 年、金額、数量は自然な日本語で表記してください(例:'1995年'、'500ドル'、'3人')。\n"
814
+ )
815
  elif lang_key == "english":
816
  skip_title_rule = "🚫 [STRICT RULE]: Do NOT speak or read movie title cards or credits. Start narrating directly from the first character action.\n"
817
  first_person_word = "'I'"
 
1150
  lang_clean = to_str(lang, "myanmar").lower().strip()
1151
  is_thai_mode = ("thai" in lang_clean) or ("thai" in v_check) or ("th-" in v_check) or ("ထိုင်း" in v_check)
1152
  is_chinese_mode = ("chinese" in lang_clean) or ("chinese" in v_check) or ("zh-" in v_check) or ("တရုတ်" in v_check)
1153
+ is_japanese_mode = ("japanese" in lang_clean) or ("japanese" in v_check) or ("ja-" in v_check) or ("ဂျပန်" in v_check)
1154
  is_eng_mode = ("english" in lang_clean) or ("english" in v_check) or ("en-" in v_check) or ("အင်္ဂလိပ်" in v_check)
1155
+ lang_key = "thai" if is_thai_mode else "chinese" if is_chinese_mode else "english" if is_eng_mode else "japanese" if is_japanese_mode else "myanmar"
1156
 
1157
  task_mode = to_str(task_mode, "pro_recap").lower()
1158
  script_text = to_str(script_text)
 
1796
  font_name = "Zawgyi-One"
1797
  if is_thai_mode: font_name = "Kanit"
1798
  elif is_chinese_mode: font_name = "Noto Sans SC"
1799
+ elif is_japanese_mode: font_name = "Noto Sans JP"
1800
  elif is_eng_mode: font_name = "Kanit"
1801
 
1802
  with open(sub_file, "w", encoding="utf-8") as f:
 
1821
 
1822
  is_thai_text = is_thai_mode or bool(re.search(r'[\u0E00-\u0E7F]', clean_text))
1823
  is_chinese_text = is_chinese_mode or bool(re.search(r'[\u4E00-\u9FFF]', clean_text))
1824
+ is_japanese_text = is_japanese_mode or bool(re.search(r'[\u3040-\u30FF]', clean_text))
1825
 
1826
  ratio_limits = {
1827
  "myanmar": {"9:16": 8, "4:5": 8, "1:1": 9, "4:3": 11, "16:9": 13},
1828
  "thai": {"9:16": 12, "4:5": 12, "1:1": 14, "4:3": 17, "16:9": 20},
1829
  "chinese": {"9:16": 8, "4:5": 8, "1:1": 10, "4:3": 12, "16:9": 15},
1830
+ "japanese": {"9:16": 8, "4:5": 8, "1:1": 10, "4:3": 12, "16:9": 15},
1831
  "english": {"9:16": 20, "4:5": 20, "1:1": 24, "4:3": 28, "16:9": 34}
1832
  }
1833
 
1834
  short_chunks = []
1835
 
1836
+ if is_chinese_text or is_japanese_text:
1837
+ limit_zh = ratio_limits["japanese" if is_japanese_text else "chinese"].get(ratio_str, 12)
1838
  zh_tokens = re.findall(r"[a-zA-Z0-9]+|[^\sa-zA-Z0-9]", clean_text)
1839
  temp_str = ""; count = 0
1840
  for tk in zh_tokens:
 
1937
  if marquee_toggle == "on" and marquee_text:
1938
  font_path = os.path.join(USER_FONT_DIR, "Zawgyi-One.ttf").replace('\\', '/')
1939
  safe_text = to_str(marquee_text).replace("'", "").replace(":", "\\:")
1940
+ if not is_thai_mode and not is_chinese_mode and not is_eng_mode and not is_japanese_mode:
1941
  try: safe_text = rabbit.Rabbit.uni2zg(safe_text)
1942
  except: pass
1943
  mq_y = to_float(marquee_y, 90.0) / 100.0 * target_h
 
2407
  lang_clean = to_str(lang, "myanmar").lower().strip()
2408
  is_thai_mode = ("thai" in lang_clean) or ("thai" in v_check) or ("th-" in v_check) or ("ထိုင်း" in v_check)
2409
  is_chinese_mode = ("chinese" in lang_clean) or ("chinese" in v_check) or ("zh-" in v_check) or ("တရုတ်" in v_check)
2410
+ is_japanese_mode = ("japanese" in lang_clean) or ("japanese" in v_check) or ("ja-" in v_check) or ("ဂျပန်" in v_check)
2411
  is_eng_mode = ("english" in lang_clean) or ("english" in v_check) or ("en-" in v_check) or ("အင်္ဂလိပ်" in v_check)
2412
+ lang_key = "thai" if is_thai_mode else "chinese" if is_chinese_mode else "english" if is_eng_mode else "japanese" if is_japanese_mode else "myanmar"
2413
  task_mode = (task_mode or "single_voice").strip().lower()
2414
  voice2_name = (voice2_name or "").strip()
2415
  script_text = (script_text or "").strip()
 
2561
  video_file_ai = None
2562
 
2563
  if not is_direct_script_render:
2564
+ target_name = {"myanmar": "Burmese", "english": "English", "thai": "Thai", "chinese": "Simplified Chinese", "japanese": "Japanese"}.get(lang_key, lang_key)
2565
  style_header = (
2566
  f"🔥 [HIGHEST PRIORITY - MANDATORY SPEAKING & TRANSLATION STYLE ({str(genre or 'original').upper()})]:\n"
2567
  f"{genre_prompt}\n"
 
2750
  clean_txt = clean_txt.replace('*', '').strip()
2751
 
2752
  if is_eng_mode or is_thai_mode: clean_txt = re.sub(r'[\t\n\r]+', ' ', clean_txt)
2753
+ elif is_chinese_mode or is_japanese_mode: clean_txt = re.sub(r'\s+', '', clean_txt)
2754
  else:
2755
  clean_txt = re.sub(r'[\u0E00-\u0E7F]+', '', clean_txt)
2756
  clean_txt = re.sub(r'[\u4E00-\u9FFF]+', '', clean_txt)
 
3093
  font_name = "Zawgyi-One"
3094
  if is_thai_mode: font_name = "Kanit"
3095
  elif is_chinese_mode: font_name = "Noto Sans SC"
3096
+ elif is_japanese_mode: font_name = "Noto Sans JP"
3097
  elif is_eng_mode: font_name = "Kanit"
3098
 
3099
  with open(sub_file, "w", encoding="utf-8") as f:
 
3115
  for res in chunk_results:
3116
  sync_start_ms = res.get("final_start_ms", 0); sync_dur_ms = res.get("actual_dur", 0); clean_text = res.get("clean_text", "")
3117
  if not clean_text: continue
3118
+ if not is_thai_mode and not is_chinese_mode and not is_eng_mode and not is_japanese_mode:
3119
  try: clean_text = rabbit.Rabbit.uni2zg(clean_text)
3120
  except: pass
3121
 
3122
+ if is_chinese_mode or is_japanese_mode:
3123
  zh_tokens = re.findall(r"[a-zA-Z0-9]+|[^\sa-zA-Z0-9]", clean_text); short_chunks = []; temp_str = ""; count = 0
3124
  for tk in zh_tokens:
3125
  temp_str += tk; count += 1
 
3171
  current_start = line_data.get("time_ms", 0); current_end = line_data.get("orig_end_ms", current_start + 2000)
3172
  clean_text = re.sub(r'\[.*?\]', '', line_data.get("text", "")).strip()
3173
  if not clean_text: continue
3174
+ if not is_thai_mode and not is_chinese_mode and not is_eng_mode and not is_japanese_mode:
3175
  try: clean_text = rabbit.Rabbit.uni2zg(clean_text)
3176
  except: pass
3177
 
3178
+ if is_chinese_mode or is_japanese_mode:
3179
  zh_tokens = re.findall(r"[a-zA-Z0-9]+|[^\sa-zA-Z0-9]", clean_text); short_chunks = []; temp_str = ""; count = 0
3180
  for tk in zh_tokens:
3181
  temp_str += tk; count += 1
 
3286
  if marquee_toggle == "on" and marquee_text:
3287
  font_path = os.path.join(USER_FONT_DIR, "Zawgyi-One.ttf").replace(chr(92), '/')
3288
  safe_text = to_str(marquee_text).replace("'", "").replace(":", f"\:")
3289
+ if not is_thai_mode and not is_chinese_mode and not is_eng_mode and not is_japanese_mode:
3290
  try: safe_text = rabbit.Rabbit.uni2zg(safe_text)
3291
  except: pass
3292
  mq_y = to_float(marquee_y, 90.0) / 100.0 * target_h