Spaces:
Running
Running
Upload app.py
Browse files
app.py
CHANGED
|
@@ -865,7 +865,7 @@ def get_sys_prompt(ct, vo_lang='my'):
|
|
| 865 |
"စည်းကမ်း သုံးချက်။ မူရင်း အကြောင်းအရာပါတဲ့ အချက်တွေကိုပဲ ပြန်ဆိုရမယ်။ မူရင်းမပါတဲ့ ဇာတ်ကွက်၊ အချက်အလက် ဘာမှ ထပ်မထည့်ရ။\n"
|
| 866 |
"စည်းကမ်း လေးချက်။ မြန်မာစာသားပဲ သုံးရမယ်။ အင်္ဂလိပ် စကားလုံးနဲ့ အာရဗီ ဂဏန်းတွေ လုံးဝ မသုံးရ။ ဂဏန်းတွေ့ရင် မြန်မာ အသံထွက်နဲ့ ရေးပါ — တစ်၊ နှစ်၊ သုံး၊ တစ်ဆယ်၊ နှစ်ဆယ်၊ တစ်ရာ၊ တစ်ထောင် စသဖြင့်။\n"
|
| 867 |
"စည်းကမ်း ငါးချက်။ အဖြေပေးတဲ့အခါ မြန်မာဘာသာနဲ့ပဲ ဖြေပါ။ အင်္ဂလိပ်ဘာသာနဲ့ ရှင်းလင်းချက် ဒါမှမဟုတ် မူရင်း အင်္ဂလိပ် စာသားတွေ ပြန်ထည့်ခြင်း လုံးဝ မလုပ်ရ။\n"
|
| 868 |
-
"စည်းကမ်း ခြောက်ချက်။ -တယ်
|
| 869 |
"Format: [SCRIPT](script)[TITLE](title ≤10 words)[HASHTAGS]#"
|
| 870 |
)
|
| 871 |
|
|
@@ -938,6 +938,30 @@ def call_api(msgs, api='Gemini', purpose='transcript'):
|
|
| 938 |
continue
|
| 939 |
raise Exception(f'❌ All keys/models failed ({purpose}): {last_err}')
|
| 940 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 941 |
def parse_out(text):
|
| 942 |
sc, ti, ht = '', '', ''
|
| 943 |
m = re.search(r'\[SCRIPT\](.*?)\[TITLE\]', text, re.DOTALL)
|
|
@@ -947,6 +971,8 @@ def parse_out(text):
|
|
| 947 |
if m2: ti = m2.group(1).strip()
|
| 948 |
if m3: ht = m3.group(1).strip()
|
| 949 |
if not sc: sc = re.sub(r'\[SCRIPT\]|\[TITLE\]|\[HASHTAGS\]', '', text.split('[TITLE]')[0]).strip()
|
|
|
|
|
|
|
| 950 |
tags = re.findall(r'#\S+', ht)
|
| 951 |
if len(tags) < 5:
|
| 952 |
defaults = ['#myanmar','#viral','#trending','#foryou','#entertainment']
|
|
|
|
| 865 |
"စည်းကမ်း သုံးချက်။ မူရင်း အကြောင်းအရာပါတဲ့ အချက်တွေကိုပဲ ပြန်ဆိုရမယ်။ မူရင်းမပါတဲ့ ဇာတ်ကွက်၊ အချက်အလက် ဘာမှ ထပ်မထည့်ရ။\n"
|
| 866 |
"စည်းကမ်း လေးချက်။ မြန်မာစာသားပဲ သုံးရမယ်။ အင်္ဂလိပ် စကားလုံးနဲ့ အာရဗီ ဂဏန်းတွေ လုံးဝ မသုံးရ။ ဂဏန်းတွေ့ရင် မြန်မာ အသံထွက်နဲ့ ရေးပါ — တစ်၊ နှစ်၊ သုံး၊ တစ်ဆယ်၊ နှစ်ဆယ်၊ တစ်ရာ၊ တစ်ထောင် စသဖြင့်။\n"
|
| 867 |
"စည်းကမ်း ငါးချက်။ အဖြေပေးတဲ့အခါ မြန်မာဘာသာနဲ့ပဲ ဖြေပါ။ အင်္ဂလိပ်ဘာသာနဲ့ ရှင်းလင်းချက် ဒါမှမဟုတ် မူရင်း အင်္ဂလိပ် စာသားတွေ ပြန်ထည့်ခြင်း လုံးဝ မလုပ်ရ။\n"
|
| 868 |
+
"စည်းကမ်း ခြောက်ချက်။ ဝါကျတိုင်း -တယ် နဲ့သာ ပြီးဆုံးရမယ်။ နော်၊ တာပဲ၊ တာပေါ့၊ ပေါ့၊ ဟင်၊ ဟာ၊ ကွာ၊ ရှင် ဆိုတဲ့ particle တွေကို ဝါကျအဆုံးမှာ လုံးဝ မတပ်ရ။ ဥပမာ မှားတာ: သွားလိုက်တယ် နော် / ပြောလိုက်တယ် ဟင် / ဖြစ်သွားတယ် တာပဲ — ဒီပုံစံတွေ လုံးဝ မရေးရ။ မှန်တာ: သွားလိုက်တယ် / ပြောလိုက်တယ် / ဖြစ်သွားတယ် — -တယ် ဖြင့်သာ ဝါကျချက်ချင်း ပိတ်ပါ။\n"
|
| 869 |
"Format: [SCRIPT](script)[TITLE](title ≤10 words)[HASHTAGS]#"
|
| 870 |
)
|
| 871 |
|
|
|
|
| 938 |
continue
|
| 939 |
raise Exception(f'❌ All keys/models failed ({purpose}): {last_err}')
|
| 940 |
|
| 941 |
+
def _strip_my_fillers(script_text):
|
| 942 |
+
"""Myanmar movie recap script မှ ဝါကျအဆုံးရှိ filler particles တွေ ဖယ်ရှားသည်။"""
|
| 943 |
+
# Particles to strip from end of each sentence (after -တယ် or before ။)
|
| 944 |
+
fillers = ['နော်', 'တာပဲ', 'တာပေါ့', 'ပေါ့', 'ဟင်', 'ဟာ', 'ကွာ', 'ရှင်', 'ပါ့', 'ပေါ့လေ', 'ဆိုတော့', 'လေ']
|
| 945 |
+
# Build regex: -(တယ်) then optional space then filler then optional ။
|
| 946 |
+
# Matches patterns like: တယ် နော်၊ တယ် ဟင်။ etc.
|
| 947 |
+
filler_pattern = '|'.join(re.escape(f) for f in fillers)
|
| 948 |
+
# Strip fillers after -တယ် (with optional space/punct between)
|
| 949 |
+
script_text = re.sub(
|
| 950 |
+
r'(တယ်)\s*(?:' + filler_pattern + r')\s*([၊။]?)',
|
| 951 |
+
r'',
|
| 952 |
+
script_text
|
| 953 |
+
)
|
| 954 |
+
# Also strip fillers at very end of a line (sentence-final position)
|
| 955 |
+
lines = script_text.split('\n')
|
| 956 |
+
cleaned = []
|
| 957 |
+
for line in lines:
|
| 958 |
+
stripped = line.rstrip()
|
| 959 |
+
for f in fillers:
|
| 960 |
+
# Remove trailing filler before ။ or at end
|
| 961 |
+
stripped = re.sub(r'\s*' + re.escape(f) + r'\s*([၊။]?)\s*$', r'\1', stripped)
|
| 962 |
+
cleaned.append(stripped)
|
| 963 |
+
return '\n'.join(cleaned)
|
| 964 |
+
|
| 965 |
def parse_out(text):
|
| 966 |
sc, ti, ht = '', '', ''
|
| 967 |
m = re.search(r'\[SCRIPT\](.*?)\[TITLE\]', text, re.DOTALL)
|
|
|
|
| 971 |
if m2: ti = m2.group(1).strip()
|
| 972 |
if m3: ht = m3.group(1).strip()
|
| 973 |
if not sc: sc = re.sub(r'\[SCRIPT\]|\[TITLE\]|\[HASHTAGS\]', '', text.split('[TITLE]')[0]).strip()
|
| 974 |
+
# ── Postprocess: strip trailing filler particles from Myanmar scripts ──
|
| 975 |
+
sc = _strip_my_fillers(sc)
|
| 976 |
tags = re.findall(r'#\S+', ht)
|
| 977 |
if len(tags) < 5:
|
| 978 |
defaults = ['#myanmar','#viral','#trending','#foryou','#entertainment']
|