Update app.py
Browse files
app.py
CHANGED
|
@@ -2,9 +2,7 @@ import gradio as gr
|
|
| 2 |
import edge_tts
|
| 3 |
import asyncio
|
| 4 |
import tempfile
|
| 5 |
-
import os
|
| 6 |
|
| 7 |
-
# မြန်မာနဲ့ အင်္ဂလိပ် အသံတချို့ကို Default ထည့်ပေးထားပါတယ်
|
| 8 |
VOICES = [
|
| 9 |
"my-MM-NilarNeural",
|
| 10 |
"my-MM-ThihaNeural",
|
|
@@ -15,19 +13,14 @@ VOICES = [
|
|
| 15 |
async def generate_tts(text, voice, proxy):
|
| 16 |
if not text:
|
| 17 |
return None, "ကျေးဇူးပြု၍ စာသားထည့်ပါ။"
|
| 18 |
-
|
| 19 |
try:
|
| 20 |
-
# အသံဖိုင်သိမ်းရန် Temporary file ဖန်တီးခြင်း
|
| 21 |
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
|
| 22 |
temp_file.close()
|
| 23 |
|
| 24 |
-
|
| 25 |
-
proxy_url = proxy if proxy.strip() != "" else None
|
| 26 |
|
| 27 |
-
# edge_tts ကို proxy parameter ထည့်ပြီး ခေါ်ခြင်း
|
| 28 |
communicate = edge_tts.Communicate(text, voice, proxy=proxy_url)
|
| 29 |
await communicate.save(temp_file.name)
|
| 30 |
-
|
| 31 |
return temp_file.name, "အောင်မြင်ပါသည်။"
|
| 32 |
except Exception as e:
|
| 33 |
return None, f"Error: {str(e)}"
|
|
@@ -35,24 +28,17 @@ async def generate_tts(text, voice, proxy):
|
|
| 35 |
def tts_interface(text, voice, proxy):
|
| 36 |
return asyncio.run(generate_tts(text, voice, proxy))
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
gr.Markdown("## Hugging Face Space အတွက် Edge TTS (Proxy Support)")
|
| 41 |
-
gr.Markdown("Proxy ကို `http://ip:port` သို့မဟုတ် `http://user:pass@ip:port` ပုံစံဖြင့် ထည့်သွင်းအသုံးပြုနိုင်ပါသည်။")
|
| 42 |
-
|
| 43 |
with gr.Row():
|
| 44 |
with gr.Column():
|
| 45 |
-
text_input = gr.Textbox(label="စာသားထည့်ပါ
|
| 46 |
-
voice_dropdown = gr.Dropdown(choices=VOICES, value="my-MM-NilarNeural", label="အသံရွေးချယ်ပါ
|
| 47 |
-
proxy_input = gr.Textbox(
|
| 48 |
-
|
| 49 |
-
placeholder="http://123.45.67.89:8080 (RunPod သို့မဟုတ် အခြား Proxy ကို ထည့်ပါ)"
|
| 50 |
-
)
|
| 51 |
-
submit_btn = gr.Button("အသံဖန်တီးမည် (Generate TTS)", variant="primary")
|
| 52 |
-
|
| 53 |
with gr.Column():
|
| 54 |
-
audio_output = gr.Audio(label="ထွက်ပေါ်လာသောအသံ
|
| 55 |
-
status_output = gr.Textbox(label="အခြေအနေ
|
| 56 |
|
| 57 |
submit_btn.click(
|
| 58 |
fn=tts_interface,
|
|
@@ -61,5 +47,4 @@ with gr.Blocks(title="Edge TTS with Proxy") as app:
|
|
| 61 |
)
|
| 62 |
|
| 63 |
if __name__ == "__main__":
|
| 64 |
-
|
| 65 |
-
app.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 2 |
import edge_tts
|
| 3 |
import asyncio
|
| 4 |
import tempfile
|
|
|
|
| 5 |
|
|
|
|
| 6 |
VOICES = [
|
| 7 |
"my-MM-NilarNeural",
|
| 8 |
"my-MM-ThihaNeural",
|
|
|
|
| 13 |
async def generate_tts(text, voice, proxy):
|
| 14 |
if not text:
|
| 15 |
return None, "ကျေးဇူးပြု၍ စာသားထည့်ပါ။"
|
|
|
|
| 16 |
try:
|
|
|
|
| 17 |
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
|
| 18 |
temp_file.close()
|
| 19 |
|
| 20 |
+
proxy_url = proxy if proxy and proxy.strip() != "" else None
|
|
|
|
| 21 |
|
|
|
|
| 22 |
communicate = edge_tts.Communicate(text, voice, proxy=proxy_url)
|
| 23 |
await communicate.save(temp_file.name)
|
|
|
|
| 24 |
return temp_file.name, "အောင်မြင်ပါသည်။"
|
| 25 |
except Exception as e:
|
| 26 |
return None, f"Error: {str(e)}"
|
|
|
|
| 28 |
def tts_interface(text, voice, proxy):
|
| 29 |
return asyncio.run(generate_tts(text, voice, proxy))
|
| 30 |
|
| 31 |
+
with gr.Blocks() as app:
|
| 32 |
+
gr.Markdown("## Edge TTS with Proxy Support")
|
|
|
|
|
|
|
|
|
|
| 33 |
with gr.Row():
|
| 34 |
with gr.Column():
|
| 35 |
+
text_input = gr.Textbox(label="စာသားထည့်ပါ", lines=5)
|
| 36 |
+
voice_dropdown = gr.Dropdown(choices=VOICES, value="my-MM-NilarNeural", label="အသံရွေးချယ်ပါ")
|
| 37 |
+
proxy_input = gr.Textbox(label="Proxy URL (Optional)", placeholder="http://ip:port")
|
| 38 |
+
submit_btn = gr.Button("အသံဖန်တီးမည်", variant="primary")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
with gr.Column():
|
| 40 |
+
audio_output = gr.Audio(label="ထွက်ပေါ်လာသောအသံ", type="filepath")
|
| 41 |
+
status_output = gr.Textbox(label="အခြေအနေ")
|
| 42 |
|
| 43 |
submit_btn.click(
|
| 44 |
fn=tts_interface,
|
|
|
|
| 47 |
)
|
| 48 |
|
| 49 |
if __name__ == "__main__":
|
| 50 |
+
app.launch()
|
|
|