Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import os
|
|
| 5 |
import re
|
| 6 |
|
| 7 |
# =====================================================================
|
| 8 |
-
# 🎙️ GTTS AUDIO GENERATOR (
|
| 9 |
# =====================================================================
|
| 10 |
def generate_voice_audio(text, filename="recap_voiceover.mp3"):
|
| 11 |
if os.path.exists(filename):
|
|
@@ -14,21 +14,19 @@ def generate_voice_audio(text, filename="recap_voiceover.mp3"):
|
|
| 14 |
except Exception:
|
| 15 |
pass
|
| 16 |
|
| 17 |
-
# စာသားထဲက သင်္ကေတနဲ့ အီမိုဂျီ
|
| 18 |
clean_lines = []
|
| 19 |
for line in text.split('\n'):
|
| 20 |
line_clean = line.strip()
|
| 21 |
-
line_clean = re.sub(r'[💡💥🎬🔥\d+\.\s\-–—
|
| 22 |
if line_clean:
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
if not line_clean.endswith('၊') and not line_clean.endswith('။'):
|
| 26 |
-
line_clean += '၊'
|
| 27 |
clean_lines.append(line_clean)
|
| 28 |
|
| 29 |
-
final_text = "
|
| 30 |
|
| 31 |
-
# မ
|
| 32 |
tts = gTTS(text=final_text, lang='my')
|
| 33 |
tts.save(filename)
|
| 34 |
return filename
|
|
@@ -50,8 +48,8 @@ def process_movie_recap(movie_name, episode_part, movie_context, api_key, durati
|
|
| 50 |
word_count = "စာလုံးရေ ၁၁၀၀ ကျော် မှ ၁၅၀၀ အတွင်း"
|
| 51 |
length_desc = "၃ မိနစ်မှ ၅ မိနစ်စာ YouTube ဗီဒီယို"
|
| 52 |
else:
|
| 53 |
-
word_count = "စာလုံးရေ ၂၅၀၀ ကျော် မှ ၃၀၀
|
| 54 |
-
length_desc = "၁
|
| 55 |
|
| 56 |
additional_context = ""
|
| 57 |
if movie_context and movie_context.strip() != "":
|
|
@@ -81,7 +79,7 @@ def process_movie_recap(movie_name, episode_part, movie_context, api_key, durati
|
|
| 81 |
|
| 82 |
progress(0.80, desc="🎙️ Google-TTS ဖြင့် တည်ငြိမ်သော မြန်မာ AI Voiceover ဖန်တီးနေပါသည်...")
|
| 83 |
|
| 84 |
-
#
|
| 85 |
voice_mp3 = generate_voice_audio(burmese_script)
|
| 86 |
|
| 87 |
return burmese_script, voice_mp3
|
|
@@ -90,11 +88,11 @@ def process_movie_recap(movie_name, episode_part, movie_context, api_key, durati
|
|
| 90 |
return f"❌ Error တက်သွားပါတယ်- {str(e)}", None
|
| 91 |
|
| 92 |
# =====================================================================
|
| 93 |
-
# 🎨 GRADIO UI DESIGN
|
| 94 |
# =====================================================================
|
| 95 |
with gr.Blocks(title="Smart Movie Auto Recap") as demo:
|
| 96 |
gr.Markdown("# ✨ Smart Movie Auto Recap Pro ✨")
|
| 97 |
-
gr.Markdown("သေ
|
| 98 |
|
| 99 |
with gr.Row():
|
| 100 |
with gr.Column():
|
|
@@ -113,49 +111,17 @@ with gr.Blocks(title="Smart Movie Auto Recap") as demo:
|
|
| 113 |
value="Medium (YouTube - 3 to 5 Mins)",
|
| 114 |
label="⏱️ ဗီဒီယို အချိန်အ���ှည်"
|
| 115 |
)
|
| 116 |
-
|
| 117 |
-
# 🎚️ Gradio ရဲ့ built-in JavaScript Speed Controller ကို အသုံးပြုရန် Slider ထည့်သွင်းခြင်း
|
| 118 |
-
# ဒါက Server ထဲမှာ Audio ကို ချိုးဖဲ့စရာမလိုဘဲ UI ကစားရုံနဲ့ အသံကို မြန်စေ/နှေးစေမှာဖြစ်ပါတယ်
|
| 119 |
-
voice_speed_slider = gr.Slider(
|
| 120 |
-
minimum=0.5,
|
| 121 |
-
maximum=2.0,
|
| 122 |
-
value=1.3, # Recap ဗီဒီယိုတွေအတွက် အကောင်းဆုံးနှုန်း 1.3 ဆကို ပုံမှန်ထားပေးထားပါတယ်
|
| 123 |
-
step=0.1,
|
| 124 |
-
label="🎚️ အသံ ဖွင့်မည့် အမြန်နှုန်း (Playback Speed)"
|
| 125 |
-
)
|
| 126 |
-
|
| 127 |
submit_btn = gr.Button("🚀 Auto Process စတင်မည်", variant="primary")
|
| 128 |
|
| 129 |
with gr.Column():
|
| 130 |
output_script = gr.Textbox(label="📝 ထွက်လာသည့် မြန်မာလို Script", interactive=False, lines=12)
|
|
|
|
| 131 |
|
| 132 |
-
# 🔊 output_audio UI ထဲမှာ အသံအမြန်အနှေး ကစားလို့ရအောင် Custom Javascript ဖြင့် တွဲဆက်ပေးထားပါသည်
|
| 133 |
-
output_audio = gr.Audio(
|
| 134 |
-
label="🔊 ထွက်လာသည့် 🎙️ မြန်မာ AI Voiceover",
|
| 135 |
-
type="filepath",
|
| 136 |
-
interactive=False
|
| 137 |
-
)
|
| 138 |
-
|
| 139 |
-
# Slider တန်ဖို ပြောင်းလဲလိုက်တာနဲ့ အသံဖွင့်တဲ့ အမြန်နှုန်းပါ လိုက်ပြောင်းမည့် Logic
|
| 140 |
-
def change_speed(audio_path, speed):
|
| 141 |
-
return audio_path
|
| 142 |
-
|
| 143 |
submit_btn.click(
|
| 144 |
fn=process_movie_recap,
|
| 145 |
inputs=[movie_name_input, episode_input, movie_context_input, api_key_input, duration_dropdown],
|
| 146 |
outputs=[output_script, output_audio]
|
| 147 |
)
|
| 148 |
-
|
| 149 |
-
# HTML/JS စနစ်သုံးပြီး Gradio Audio Player ၏ အမြန်နှုန်းကို တိုက်ရိုက်ထိန်းချုပ်ခြင်း
|
| 150 |
-
voice_speed_slider.change(
|
| 151 |
-
fn=None,
|
| 152 |
-
inputs=[voice_speed_slider],
|
| 153 |
-
js="""(speed) => {
|
| 154 |
-
const audios = document.querySelectorAll('audio');
|
| 155 |
-
audios.forEach(audio => { if(audio) audio.playbackRate = speed; });
|
| 156 |
-
return [];
|
| 157 |
-
}"""
|
| 158 |
-
)
|
| 159 |
|
| 160 |
if __name__ == "__main__":
|
| 161 |
demo.launch()
|
|
|
|
| 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):
|
|
|
|
| 14 |
except Exception:
|
| 15 |
pass
|
| 16 |
|
| 17 |
+
# စာသားထဲက သင်္ကေတနဲ့ အီမိုဂျီတွေကို ရှင်းထုတ်ခြင်း
|
| 18 |
clean_lines = []
|
| 19 |
for line in text.split('\n'):
|
| 20 |
line_clean = line.strip()
|
| 21 |
+
line_clean = re.sub(r'[💡💥🎬🔥\d+\.\s\-–—]', '', line_clean)
|
| 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 = " ".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
|
|
|
|
| 48 |
word_count = "စာလုံးရေ ၁၁၀၀ ကျော် မှ ၁၅၀၀ အတွင်း"
|
| 49 |
length_desc = "၃ မိနစ်မှ ၅ မိနစ်စာ YouTube ဗီဒီယို"
|
| 50 |
else:
|
| 51 |
+
word_count = "စာလုံးရေ ၂၅၀၀ ကျော် မှ ၃၀၀0 အတွင်း"
|
| 52 |
+
length_desc = "၁၅ မိနစ်စာ YouTube Long-form ဗီဒီယို"
|
| 53 |
|
| 54 |
additional_context = ""
|
| 55 |
if movie_context and movie_context.strip() != "":
|
|
|
|
| 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
|
|
|
|
| 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 |
value="Medium (YouTube - 3 to 5 Mins)",
|
| 112 |
label="⏱️ ဗီဒီယို အချိန်အ���ှည်"
|
| 113 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
submit_btn = gr.Button("🚀 Auto Process စတင်မည်", variant="primary")
|
| 115 |
|
| 116 |
with gr.Column():
|
| 117 |
output_script = gr.Textbox(label="📝 ထွက်လာသည့် မြန်မာလို Script", interactive=False, lines=12)
|
| 118 |
+
output_audio = gr.Audio(label="🔊 ထွက်လာသည့် 🎙️ မြန်မာ AI Voiceover", type="filepath")
|
| 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 |
|
| 126 |
if __name__ == "__main__":
|
| 127 |
demo.launch()
|