Spaces:
Running on Zero
Running on Zero
Deploy MyanmarTTS ZeroGPU demo
Browse files- README.md +1 -3
- app.py +33 -79
- requirements.txt +1 -6
README.md
CHANGED
|
@@ -4,10 +4,8 @@ emoji: 🎙️
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 5.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: cc0-1.0
|
| 11 |
---
|
| 12 |
-
|
| 13 |
-
# MyanmarTTS ZeroGPU Demo
|
|
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.29.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: cc0-1.0
|
| 11 |
---
|
|
|
|
|
|
app.py
CHANGED
|
@@ -1,100 +1,54 @@
|
|
| 1 |
-
import spaces
|
| 2 |
-
import os
|
| 3 |
import tempfile
|
| 4 |
-
import torch
|
| 5 |
import soundfile as sf
|
| 6 |
import gradio as gr
|
| 7 |
-
from huggingface_hub import hf_hub_download
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
-
MODEL_REPO = "freococo/MyanmarTTS"
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
print("[Space Startup] Initializing StableTTSAPI...")
|
| 20 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 21 |
-
model = StableTTSAPI(model_path, vocos_path, "vocos").to(device)
|
| 22 |
-
model.g2p_mapping["burmese"] = burmese_to_ipa2
|
| 23 |
-
print("[Space Startup] Model ready!")
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
if not text or not text.strip():
|
| 29 |
-
raise gr.Error("
|
| 30 |
-
|
| 31 |
-
ref = ref_audio if ref_audio else default_ref
|
| 32 |
-
|
| 33 |
-
audio, _ = model.inference(
|
| 34 |
-
text=text.strip(),
|
| 35 |
-
ref_audio=ref,
|
| 36 |
-
language="burmese",
|
| 37 |
-
step=int(steps),
|
| 38 |
-
solver=solver,
|
| 39 |
-
cfg=float(cfg),
|
| 40 |
-
)
|
| 41 |
-
|
| 42 |
tmp = tempfile.NamedTemporaryFile(suffix=".wav", delete=False)
|
| 43 |
-
sf.write(tmp.name, audio
|
| 44 |
return tmp.name
|
| 45 |
|
| 46 |
|
| 47 |
EXAMPLES = [
|
| 48 |
-
["မ
|
| 49 |
-
["
|
| 50 |
-
["
|
| 51 |
-
["လ
|
| 52 |
-
["ဒီအသံထုတ်စနစ်လေးကို အသုံးပြုသူတိုင်း ကျန်းမာချမ်းသာပြီး လိုရာဆန္ဒတွေ တလုံးတဝတည်း ပြည့်စုံနိုင်ကြပါစေ", 12, "euler", 3.0],
|
| 53 |
-
["ဟယ်လို... ဒါလင်... မတွေ့ရတာ... ကြာပီနော်", 8, "euler", 3.0],
|
| 54 |
]
|
| 55 |
|
| 56 |
-
with gr.Blocks(title="MyanmarTTS
|
| 57 |
-
gr.Markdown(""
|
| 58 |
-
# 🎙️ MyanmarTTS (မြန်မာ အသံထွက်စနစ်)
|
| 59 |
-
A from-scratch **31M parameter Burmese Text-to-Speech model** trained with Flow Matching and DiT.
|
| 60 |
-
- **Model Repository:** [freococo/MyanmarTTS](https://huggingface.co/freococo/MyanmarTTS)
|
| 61 |
-
- **License:** CC0 1.0 (Public Domain)
|
| 62 |
-
""")
|
| 63 |
-
|
| 64 |
with gr.Row():
|
| 65 |
-
with gr.Column(
|
| 66 |
-
text_input = gr.Textbox(
|
| 67 |
-
label="Burmese Text (မြန်မာစာ ထည့်ပါ)",
|
| 68 |
-
lines=4,
|
| 69 |
-
placeholder="ဒီမှာ မြ���်မာစာသား ရိုက်ထည့်ပါ...",
|
| 70 |
-
)
|
| 71 |
-
ref_input = gr.Audio(
|
| 72 |
-
label="Reference Voice (Leave empty for default voice)",
|
| 73 |
-
type="filepath",
|
| 74 |
-
)
|
| 75 |
with gr.Row():
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
gr.Examples(
|
| 86 |
-
examples=EXAMPLES,
|
| 87 |
-
inputs=[text_input, steps_slider, solver_dropdown, cfg_slider],
|
| 88 |
-
outputs=audio_output,
|
| 89 |
-
fn=generate_speech,
|
| 90 |
-
cache_examples=False,
|
| 91 |
-
)
|
| 92 |
-
|
| 93 |
-
generate_btn.click(
|
| 94 |
-
fn=generate_speech,
|
| 95 |
-
inputs=[text_input, ref_input, steps_slider, solver_dropdown, cfg_slider],
|
| 96 |
-
outputs=audio_output,
|
| 97 |
-
)
|
| 98 |
|
| 99 |
if __name__ == "__main__":
|
| 100 |
demo.queue(max_size=20).launch()
|
|
|
|
| 1 |
+
import spaces
|
|
|
|
| 2 |
import tempfile
|
|
|
|
| 3 |
import soundfile as sf
|
| 4 |
import gradio as gr
|
|
|
|
| 5 |
|
| 6 |
+
_model = None
|
| 7 |
+
_ref = None
|
| 8 |
|
|
|
|
| 9 |
|
| 10 |
+
def _ensure_model():
|
| 11 |
+
global _model, _ref
|
| 12 |
+
if _model is None:
|
| 13 |
+
from myanmar_tts import MyanmarTTS
|
| 14 |
+
_model = MyanmarTTS(device="cuda")
|
| 15 |
+
_model._load()
|
| 16 |
+
_ref = _model._ref
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
@spaces.GPU(duration=60)
|
| 20 |
+
def generate_speech(text, step, cfg):
|
| 21 |
+
_ensure_model()
|
| 22 |
if not text or not text.strip():
|
| 23 |
+
raise gr.Error("Please enter Burmese text.")
|
| 24 |
+
audio = _model.tts(text.strip(), solver="euler", step=int(step), cfg=float(cfg))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
tmp = tempfile.NamedTemporaryFile(suffix=".wav", delete=False)
|
| 26 |
+
sf.write(tmp.name, audio, 44100)
|
| 27 |
return tmp.name
|
| 28 |
|
| 29 |
|
| 30 |
EXAMPLES = [
|
| 31 |
+
["မင်္ဂလာပါ ကျွန်တော် မြန်မာ ဖြစ်ပါတယ်", 12, 3.0],
|
| 32 |
+
["ဒီနေ့ ရာသီဥတု အလွန်ကောင်းမွန်ပါတယ်", 12, 3.0],
|
| 33 |
+
["လူသားတွေ အားလုံးကို အရမ်း ချစ်ပါတယ်ရှင့်", 12, 3.0],
|
| 34 |
+
["ဟယ်လို... ဒါလင်... မတွေ့ရတာ... ကြာပီနော်", 8, 3.0],
|
|
|
|
|
|
|
| 35 |
]
|
| 36 |
|
| 37 |
+
with gr.Blocks(title="MyanmarTTS") as demo:
|
| 38 |
+
gr.Markdown("# MyanmarTTS — Burmese TTS\n31M params, CC0 1.0")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
with gr.Row():
|
| 40 |
+
with gr.Column():
|
| 41 |
+
text_input = gr.Textbox(label="Burmese Text", lines=4)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
with gr.Row():
|
| 43 |
+
step_slider = gr.Slider(4, 32, value=12, step=4, label="Steps")
|
| 44 |
+
cfg_slider = gr.Slider(1.0, 5.0, value=3.0, step=0.5, label="CFG")
|
| 45 |
+
btn = gr.Button("Generate", variant="primary")
|
| 46 |
+
with gr.Column():
|
| 47 |
+
out = gr.Audio(label="Output", type="filepath")
|
| 48 |
+
gr.Examples(EXAMPLES, inputs=[text_input, step_slider, cfg_slider],
|
| 49 |
+
outputs=out, fn=generate_speech, cache_examples=False)
|
| 50 |
+
btn.click(fn=generate_speech,
|
| 51 |
+
inputs=[text_input, step_slider, cfg_slider], outputs=out)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
if __name__ == "__main__":
|
| 54 |
demo.queue(max_size=20).launch()
|
requirements.txt
CHANGED
|
@@ -1,6 +1 @@
|
|
| 1 |
-
|
| 2 |
-
soundfile
|
| 3 |
-
huggingface_hub
|
| 4 |
-
unidecode
|
| 5 |
-
pypinyin
|
| 6 |
-
eng_to_ipa
|
|
|
|
| 1 |
+
myanmartts>=1.0.3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|