Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,20 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from google import genai
|
| 3 |
-
import
|
| 4 |
-
import edge_tts
|
| 5 |
import os
|
| 6 |
import re
|
| 7 |
|
| 8 |
# =====================================================================
|
| 9 |
-
# 🎙️
|
| 10 |
# =====================================================================
|
| 11 |
-
|
| 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 = "
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
|
| 31 |
-
|
| 32 |
return filename
|
| 33 |
|
| 34 |
# =====================================================================
|
| 35 |
-
# 🚀 MAIN RECAP PROCESSOR
|
| 36 |
# =====================================================================
|
| 37 |
-
|
| 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="🎙️
|
| 81 |
|
| 82 |
-
#
|
| 83 |
-
voice_mp3 =
|
| 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("
|
| 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():
|