Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,44 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from google import genai
|
| 3 |
-
|
|
|
|
| 4 |
import os
|
| 5 |
import re
|
| 6 |
|
| 7 |
# =====================================================================
|
| 8 |
-
# 🎙️
|
| 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()
|
| 21 |
-
|
|
|
|
| 22 |
if line_clean:
|
| 23 |
if not line_clean.endswith('။') and not line_clean.endswith('၊'):
|
| 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 |
-
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 |
|
|
@@ -48,7 +52,7 @@ def process_movie_recap(movie_name, episode_part, movie_context, api_key, durati
|
|
| 48 |
word_count = "စာလုံးရေ ၁၁၀၀ ကျော် မှ ၁၅၀၀ အတွင်း"
|
| 49 |
length_desc = "၃ မိနစ်မှ ၅ မိနစ်စာ YouTube ဗီဒီယို"
|
| 50 |
else:
|
| 51 |
-
word_count = "စာလုံးရေ ၂၅
|
| 52 |
length_desc = "၁၀ မိနစ်စာ YouTube Long-form ဗီဒီယို"
|
| 53 |
|
| 54 |
additional_context = ""
|
|
@@ -77,10 +81,10 @@ def process_movie_recap(movie_name, episode_part, movie_context, api_key, durati
|
|
| 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 = generate_voice_audio(burmese_script)
|
| 84 |
|
| 85 |
return burmese_script, voice_mp3
|
| 86 |
|
|
@@ -88,11 +92,11 @@ def process_movie_recap(movie_name, episode_part, movie_context, api_key, durati
|
|
| 88 |
return f"❌ Error တက်သွားပါတယ်- {str(e)}", None
|
| 89 |
|
| 90 |
# =====================================================================
|
| 91 |
-
# 🎨 GRADIO UI DESIGN
|
| 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():
|
|
@@ -111,6 +115,16 @@ with gr.Blocks(title="Smart Movie Auto Recap") as demo:
|
|
| 111 |
value="Medium (YouTube - 3 to 5 Mins)",
|
| 112 |
label="⏱️ ဗီဒီယို အချိန်အရှည်"
|
| 113 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
submit_btn = gr.Button("🚀 Auto Process စတင်မည်", variant="primary")
|
| 115 |
|
| 116 |
with gr.Column():
|
|
@@ -119,7 +133,7 @@ with gr.Blocks(title="Smart Movie Auto Recap") as demo:
|
|
| 119 |
|
| 120 |
submit_btn.click(
|
| 121 |
fn=process_movie_recap,
|
| 122 |
-
inputs=[movie_name_input, episode_input, movie_context_input, api_key_input, duration_dropdown],
|
| 123 |
outputs=[output_script, output_audio]
|
| 124 |
)
|
| 125 |
|
|
|
|
| 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 WITH DYNAMIC SPEED SWITCH
|
| 10 |
# =====================================================================
|
| 11 |
+
async def generate_voice_audio(text, speed_percent, 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()
|
| 21 |
+
# အသံဖတ်ရတာ ပိုမိုချောမွေ့စေရန် သင်္ကေတများ ရှင်းထုတ်ခြင်း
|
| 22 |
+
line_clean = re.sub(r'[💡💥🎬🔥\d+\.\s\-–—*#_]', '', line_clean)
|
| 23 |
if line_clean:
|
| 24 |
if not line_clean.endswith('။') and not line_clean.endswith('၊'):
|
| 25 |
line_clean += '။'
|
| 26 |
clean_lines.append(line_clean)
|
| 27 |
|
| 28 |
+
final_text = " ".join(clean_lines)
|
| 29 |
|
| 30 |
+
# Slider ကနေရလာတဲ့ ကိန်းဂဏန်းကို edge-tts ရဲ့ Format ပုံစံ (+X% သို့မဟုတ် -X%) ပြောင်းလဲခြင်း
|
| 31 |
+
sign = "+" if speed_percent >= 0 else ""
|
| 32 |
+
rate_string = f"{sign}{speed_percent}%"
|
| 33 |
+
|
| 34 |
+
communicate = edge_tts.Communicate(text=final_text, voice="my-MM-NilarNeural", rate=rate_string)
|
| 35 |
+
await communicate.save(filename)
|
| 36 |
return filename
|
| 37 |
|
| 38 |
# =====================================================================
|
| 39 |
+
# 🚀 MAIN RECAP PROCESSOR (ASYNC COMPLIANT)
|
| 40 |
# =====================================================================
|
| 41 |
+
async def process_movie_recap(movie_name, episode_part, movie_context, api_key, duration_choice, voice_speed, progress=gr.Progress(track_tqdm=True)):
|
| 42 |
if not api_key or api_key.strip() == "":
|
| 43 |
return "⚠️ ကျေးဇူးပြု၍ သင်၏ Gemini API Key ကို အရင်ထည့်ပေးပါဗျာ။", None
|
| 44 |
|
|
|
|
| 52 |
word_count = "စာလုံးရေ ၁၁၀၀ ကျော် မှ ၁၅၀၀ အတွင်း"
|
| 53 |
length_desc = "၃ မိနစ်မှ ၅ မိနစ်စာ YouTube ဗီဒီယို"
|
| 54 |
else:
|
| 55 |
+
word_count = "စာလုံးရေ ၂၅謎ာ် မှ ၃၀၀0 အတွင်း"
|
| 56 |
length_desc = "၁၀ မိနစ်စာ YouTube Long-form ဗီဒီယို"
|
| 57 |
|
| 58 |
additional_context = ""
|
|
|
|
| 81 |
response = client.models.generate_content(model='gemini-2.5-flash', contents=script_prompt)
|
| 82 |
burmese_script = response.text
|
| 83 |
|
| 84 |
+
progress(0.80, desc="🎙️ Edge-TTS ဖြင့် သဘာဝကျလှပသော မြန်မာ AI Voiceover ဖန်တီးနေပါသည်...")
|
| 85 |
|
| 86 |
+
# Slider ကနေ ရလာတဲ့ voice_speed တန်ဖိုးကို ပါဝါ ပေးပို့ခြင်း
|
| 87 |
+
voice_mp3 = await generate_voice_audio(burmese_script, speed_percent=voice_speed)
|
| 88 |
|
| 89 |
return burmese_script, voice_mp3
|
| 90 |
|
|
|
|
| 92 |
return f"❌ Error တက်သွားပါတယ်- {str(e)}", None
|
| 93 |
|
| 94 |
# =====================================================================
|
| 95 |
+
# 🎨 GRADIO UI DESIGN WITH SPEED SLIDER
|
| 96 |
# =====================================================================
|
| 97 |
with gr.Blocks(title="Smart Movie Auto Recap") as demo:
|
| 98 |
gr.Markdown("# ✨ Smart Movie Auto Recap Pro ✨")
|
| 99 |
+
gr.Markdown("ဇာတ်လမ်းအစအဆုံးကို မြန်မာလို Script ထုတ်ပေးပြီး **စိတ်ကြိုက်အမြန်နှုန်း ချိန်ညှိနိုင်သော သဘာဝကျသည့် AI Voiceover** စနစ် ဖြစ်ပါသည်။")
|
| 100 |
|
| 101 |
with gr.Row():
|
| 102 |
with gr.Column():
|
|
|
|
| 115 |
value="Medium (YouTube - 3 to 5 Mins)",
|
| 116 |
label="⏱️ ဗီဒီယို အချိန်အရှည်"
|
| 117 |
)
|
| 118 |
+
|
| 119 |
+
# 🎚️ UI အတွက် အသံ အမြန်အနှေး Slider (Default: +15%)
|
| 120 |
+
voice_speed_slider = gr.Slider(
|
| 121 |
+
minimum=-50,
|
| 122 |
+
maximum=50,
|
| 123 |
+
value=15,
|
| 124 |
+
step=5,
|
| 125 |
+
label="🎚️ အသံ အမြန်အနှေး ချိန်ညှိရန် (Speed %)"
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
submit_btn = gr.Button("🚀 Auto Process စတင်မည်", variant="primary")
|
| 129 |
|
| 130 |
with gr.Column():
|
|
|
|
| 133 |
|
| 134 |
submit_btn.click(
|
| 135 |
fn=process_movie_recap,
|
| 136 |
+
inputs=[movie_name_input, episode_input, movie_context_input, api_key_input, duration_dropdown, voice_speed_slider],
|
| 137 |
outputs=[output_script, output_audio]
|
| 138 |
)
|
| 139 |
|