Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import AutoProcessor, AutoModelForTextToSpeech | |
| import torch | |
| import soundfile as sf | |
| import tempfile | |
| # ู ูุฏูู ุนููู ู ู ููุณุจูู (ุตูุช ุนุฑุจู ุฃูุซูู) | |
| MODEL_NAME = "facebook/mms-tts-ar" | |
| # ุชุญู ูู ุงูู ูุฏูู ูุงูู ุนุงูุฌ | |
| processor = AutoProcessor.from_pretrained(MODEL_NAME) | |
| model = AutoModelForTextToSpeech.from_pretrained(MODEL_NAME) | |
| def generate_audio(prompt: str): | |
| if not prompt.strip(): | |
| return None, "โ ุงููุต ูุงุฑุบ!" | |
| inputs = processor(text=prompt, return_tensors="pt") | |
| # ุชูููุฏ ุงูุตูุช | |
| with torch.no_grad(): | |
| output = model(**inputs).waveform | |
| # ุญูุธ ุงูุตูุช ูู ู ูู ู ุคูุช | |
| with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_audio_file: | |
| sf.write(temp_audio_file.name, output.squeeze().cpu().numpy(), samplerate=16000) | |
| audio_path = temp_audio_file.name | |
| return audio_path, "โ ุชู ุชูููุฏ ุงูุตูุช ุจูุฌุงุญ!" | |
| # ูุงุฌูุฉ Gradio | |
| with gr.Blocks() as app: | |
| gr.Markdown("# ๐๏ธ ุชุญููู ุงููุต ุงูุนุฑุจู ูุตูุช ุฃูุซูู") | |
| gr.Markdown("ุฃุฏุฎู ูุตูุง ุนุฑุจููุง ูุณูุชู ุชุญูููู ุฅูู ุตูุช ุฃูุซูู ุจุงุณุชุฎุฏุงู ู ูุฏูู TTS ู ู Facebook.") | |
| with gr.Row(): | |
| prompt_input = gr.Textbox(label="ุงููุต ุงูุนุฑุจู", placeholder="ุงูุชุจ ุงููุต ููุง...") | |
| submit_button = gr.Button("๐ ุชูููุฏ ุงูุตูุช") | |
| with gr.Row(): | |
| audio_output = gr.Audio(label="ุงูุตูุช ุงููุงุชุฌ", type="filepath") | |
| status_output = gr.Textbox(label="ุงูุญุงูุฉ") | |
| submit_button.click( | |
| fn=generate_audio, | |
| inputs=[prompt_input], | |
| outputs=[audio_output, status_output] | |
| ) | |
| if __name__ == "__main__": | |
| app.launch() | |