Raybilhelp commited on
Commit
f517129
·
verified ·
1 Parent(s): b5a9702

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import requests
4
+
5
+ # গ্রাডিওর জন্য ইন্টারনাল রাউটিং কাজ করে
6
+ API_URL = "https://api-inference.huggingface.co/models/facebook/mms-tts-eng"
7
+ HF_TOKEN = os.getenv("HF_TOKEN", "")
8
+ headers = {"Authorization": f"Bearer {HF_TOKEN}"} if HF_TOKEN else {}
9
+
10
+ def text_to_speech(text):
11
+ if not text.strip():
12
+ return None, "অনুগ্রহ করে কিছু টেক্সট লিখুন।"
13
+ try:
14
+ response = requests.post(API_URL, headers=headers, json={"inputs": text}, timeout=30)
15
+ if response.status_code == 200:
16
+ output_path = "voice.wav"
17
+ with open(output_path, "wb") as f:
18
+ f.write(response.content)
19
+ return output_path, "ভয়েস সফলভাবে তৈরি হয়েছে!"
20
+ else:
21
+ return None, f"সার্ভার এরর কোড: {response.status_code}"
22
+ except Exception as e:
23
+ return None, f"নেটওয়ার্ক সমস্যা: {str(e)}"
24
+
25
+ # সুন্দর ডার্ক থিম ওয়েব UI
26
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
27
+ gr.Markdown("# 🎙️ Raybil Voice AI Engine (Gradio Embedded)")
28
+ with gr.Row():
29
+ with gr.Column():
30
+ input_text = gr.Textbox(label="আপনার টেক্সট লিখুন", placeholder="এখানে ইংরেজি টেক্সট লিখুন...", lines=4)
31
+ submit_btn = gr.Button("ভয়েস জেনারেট করুন", variant="primary")
32
+ with gr.Column():
33
+ output_audio = gr.Audio(label="জেনারেটেড ভয়েস", type="filepath")
34
+ status_text = gr.Markdown()
35
+
36
+ submit_btn.click(fn=text_to_speech, inputs=input_text, outputs=[output_audio, status_text])
37
+
38
+ demo.launch()