Autorecap commited on
Commit
dbc6477
·
verified ·
1 Parent(s): 356cba3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -1,20 +1,20 @@
1
  import gradio as gr
2
  from google import genai
3
- import asyncio
4
- import edge_tts
5
  import os
6
  import re
7
 
8
  # =====================================================================
9
- # 🎙️ EDGE-TTS AUDIO GENERATOR (FIXED FOR HUGGINGFACE)
10
  # =====================================================================
11
- async def generate_voice_audio(text, filename="recap_voiceover.mp3"):
12
  if os.path.exists(filename):
13
  try:
14
  os.remove(filename)
15
  except Exception:
16
  pass
17
 
 
18
  clean_lines = []
19
  for line in text.split('\n'):
20
  line_clean = line.strip()
@@ -24,17 +24,17 @@ async def generate_voice_audio(text, filename="recap_voiceover.mp3"):
24
  line_clean += '။'
25
  clean_lines.append(line_clean)
26
 
27
- final_text = " ".join(clean_lines)
28
 
29
- # Hugging Face ပေါ်မှာ တိုက်ရိုက် အလုပ်လုပ်မယ့် အသံထုတ်လုပ်ခြင်း Logic
30
- communicate = edge_tts.Communicate(text=final_text, voice="my-MM-NilarNeural", rate="+16%")
31
- await communicate.save(filename)
32
  return filename
33
 
34
  # =====================================================================
35
- # 🚀 MAIN RECAP PROCESSOR (ASYNC COMPLIANT)
36
  # =====================================================================
37
- async def process_movie_recap(movie_name, episode_part, movie_context, api_key, duration_choice, progress=gr.Progress(track_tqdm=True)):
38
  if not api_key or api_key.strip() == "":
39
  return "⚠️ ကျေးဇူးပြု၍ သင်၏ Gemini API Key ကို အရင်ထည့်ပေးပါဗျာ။", None
40
 
@@ -45,10 +45,10 @@ async def process_movie_recap(movie_name, episode_part, movie_context, api_key,
45
  word_count = "စာလုံးရေ ၃၀၀ ကျော် မှ ၄၀၀ အတွင်း"
46
  length_desc = "၁ မိနစ်စာ Short ဗီဒီယို"
47
  elif duration_choice == "Medium (YouTube - 3 to 5 Mins)":
48
- word_count = "စာလုံးရေ ၁၁၀၀ ကျော် မှ ၁၁၅၀၀ အတွင်း"
49
  length_desc = "၃ မိနစ်မှ ၅ မိနစ်စာ YouTube ဗီဒီယို"
50
  else:
51
- word_count = "စာလုံးရေ ၂၅၀၀ ကျော် မှ ၃၀၀၀ အတွင်း"
52
  length_desc = "၁၀ မိနစ်စာ YouTube Long-form ဗီဒီယို"
53
 
54
  additional_context = ""
@@ -77,10 +77,10 @@ async def process_movie_recap(movie_name, episode_part, movie_context, api_key,
77
  response = client.models.generate_content(model='gemini-2.5-flash', contents=script_prompt)
78
  burmese_script = response.text
79
 
80
- progress(0.80, desc="🎙️ Edge-TTS ဖြင့် သဘာဝကျလှပသော မြန်မာ AI Voiceover ဖန်တီးနေပါသည်...")
81
 
82
- # Audio Generator ကို Async အတိုင်း သေသေချာချာ စောင့်ပြီး ခေါ်ယူခြင်း
83
- voice_mp3 = await generate_voice_audio(burmese_script)
84
 
85
  return burmese_script, voice_mp3
86
 
@@ -92,7 +92,7 @@ async def process_movie_recap(movie_name, episode_part, movie_context, api_key,
92
  # =====================================================================
93
  with gr.Blocks(title="Smart Movie Auto Recap") as demo:
94
  gr.Markdown("# ✨ Smart Movie Auto Recap Pro ✨")
95
- gr.Markdown("ရုပ်ရှင် သို့မဟုတ် စီးရီးနာမည်ကို တိကျစွာ ထည့်သွင်းပါ။ ဇာတ်လမ်းကို **ဇ��တ်သိမ်းပိုင်းအထိ ပြီးပြည့်စုံအောင်** ရေးပေးပြီး **မြန်မာ AI Voiceover** ထွက်လာမည့် စနစ် ဖြစ်ပါသည်။")
96
 
97
  with gr.Row():
98
  with gr.Column():
 
1
  import gradio as gr
2
  from google import genai
3
+ from gtts import gTTS
 
4
  import os
5
  import re
6
 
7
  # =====================================================================
8
+ # 🎙️ GTTS AUDIO GENERATOR (PYTHON 3.13 STABLE FOR HUGGINGFACE)
9
  # =====================================================================
10
+ def generate_voice_audio(text, filename="recap_voiceover.mp3"):
11
  if os.path.exists(filename):
12
  try:
13
  os.remove(filename)
14
  except Exception:
15
  pass
16
 
17
+ # စာသားထဲက သင်္ကေတနဲ့ အီမိုဂျီတွေကို ရှင်းထုတ်ခြင်း
18
  clean_lines = []
19
  for line in text.split('\n'):
20
  line_clean = line.strip()
 
24
  line_clean += '။'
25
  clean_lines.append(line_clean)
26
 
27
+ final_text = " ".join(clean_lines)
28
 
29
+ # Python 3.13 မှာ တည်ငြိမ်မှုအရှိဆုံး Google TTS ဖြင့် အသံပြောင်းလဲခြင်း (မြန်မာဘာသာ 'my')
30
+ tts = gTTS(text=final_text, lang='my')
31
+ tts.save(filename)
32
  return filename
33
 
34
  # =====================================================================
35
+ # 🚀 MAIN RECAP PROCESSOR
36
  # =====================================================================
37
+ def process_movie_recap(movie_name, episode_part, movie_context, api_key, duration_choice, progress=gr.Progress(track_tqdm=True)):
38
  if not api_key or api_key.strip() == "":
39
  return "⚠️ ကျေးဇူးပြု၍ သင်၏ Gemini API Key ကို အရင်ထည့်ပေးပါဗျာ။", None
40
 
 
45
  word_count = "စာလုံးရေ ၃၀၀ ကျော် မှ ၄၀၀ အတွင်း"
46
  length_desc = "၁ မိနစ်စာ Short ဗီဒီယို"
47
  elif duration_choice == "Medium (YouTube - 3 to 5 Mins)":
48
+ word_count = "စာလုံးရေ ၁၁၀၀ ကျော် မှ ၁၅၀၀ အတွင်း"
49
  length_desc = "၃ မိနစ်မှ ၅ မိနစ်စာ YouTube ဗီဒီယို"
50
  else:
51
+ word_count = "စာလုံးရေ ၂၅၀၀ ကျော် မှ ၃၀၀0 အတွင်း"
52
  length_desc = "၁၀ မိနစ်စာ YouTube Long-form ဗီဒီယို"
53
 
54
  additional_context = ""
 
77
  response = client.models.generate_content(model='gemini-2.5-flash', contents=script_prompt)
78
  burmese_script = response.text
79
 
80
+ progress(0.80, desc="🎙️ Google-TTS ဖြင့် တည်ငြိမ်သော မြန်မာ AI Voiceover ဖန်တီးနေပါသည်...")
81
 
82
+ # gTTS သို့ ပြောင်းလဲခေါ်ယူခြင်း
83
+ voice_mp3 = generate_voice_audio(burmese_script)
84
 
85
  return burmese_script, voice_mp3
86
 
 
92
  # =====================================================================
93
  with gr.Blocks(title="Smart Movie Auto Recap") as demo:
94
  gr.Markdown("# ✨ Smart Movie Auto Recap Pro ✨")
95
+ gr.Markdown("Python 3.13 အတွက် သေချာပေါက် အသံထွက်လာမည့် တည်ငြိမ်သော **Google-TTS စနစ်သစ်** ဖြစ်ပါသည်။")
96
 
97
  with gr.Row():
98
  with gr.Column():