Spaces:
Runtime error
Runtime error
| import os | |
| import gradio as gr | |
| import requests | |
| API_URL = "https://api-inference.huggingface.co/models/facebook/mms-tts-eng" | |
| HF_TOKEN = os.getenv("HF_TOKEN", "") | |
| headers = {"Authorization": f"Bearer {HF_TOKEN}"} if HF_TOKEN else {} | |
| def text_to_speech(text): | |
| if not text.strip(): | |
| return None, "অনুগ্রহ করে কিছু টেক্সট লিখুন।" | |
| try: | |
| response = requests.post(API_URL, headers=headers, json={"inputs": text}, timeout=60) | |
| if response.status_code == 200: | |
| output_path = "voice.wav" | |
| with open(output_path, "wb") as f: | |
| f.write(response.content) | |
| return output_path, "ভয়েস সফলভাবে তৈরি হয়েছে!" | |
| else: | |
| return None, f"সার্ভার এরর কোড: {response.status_code}" | |
| except Exception as e: | |
| return None, f"নেটওয়ার্ক সমস্যা: {str(e)}" | |
| # Gradio 6.0+ এর নিয়ম অনুযায়ী theme এখন launch() এ দিতে হয় | |
| demo = gr.Blocks() | |
| with demo: | |
| gr.Markdown("# 🎙️ Raybil Voice AI Engine") | |
| with gr.Row(): | |
| with gr.Column(): | |
| input_text = gr.Textbox(label="আপনার টেক্সট লিখুন", placeholder="এখানে ইংরেজি টেক্সট লিখুন...", lines=4) | |
| submit_btn = gr.Button("ভয়েস জেনারেট করুন", variant="primary") | |
| with gr.Column(): | |
| output_audio = gr.Audio(label="জেনারেটেড ভয়েস", type="filepath") | |
| status_text = gr.Markdown() | |
| submit_btn.click(fn=text_to_speech, inputs=input_text, outputs=[output_audio, status_text]) | |
| if __name__ == "__main__": | |
| demo.launch(server_name="0.0.0.0", server_port=7860) | |