Spaces:
Sleeping
Sleeping
Commit ·
2aaf0f3
1
Parent(s): 15bc933
Initialization
Browse files- .env.example +1 -0
- .gitignore +1 -0
- app.py +61 -0
- dockerfile +24 -0
- requirements.txt +3 -0
.env.example
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
API_KEY=
|
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.env
|
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import uuid
|
| 4 |
+
import os
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
|
| 7 |
+
# Load environment variables from .env
|
| 8 |
+
load_dotenv()
|
| 9 |
+
API_KEY = os.getenv("API_KEY")
|
| 10 |
+
API_URL = 'https://api.aiforthai.in.th/vaja9/synth_audiovisual'
|
| 11 |
+
|
| 12 |
+
def synthesize(text, speaker):
|
| 13 |
+
headers = {'Apikey': API_KEY, 'Content-Type': 'application/json'}
|
| 14 |
+
payload = {
|
| 15 |
+
'input_text': text,
|
| 16 |
+
'speaker': speaker,
|
| 17 |
+
'phrase_break': 0,
|
| 18 |
+
'audiovisual': 0
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
response = requests.post(API_URL, json=payload, headers=headers)
|
| 22 |
+
if response.status_code != 200:
|
| 23 |
+
return None, "Error in synthesis."
|
| 24 |
+
|
| 25 |
+
audio_url = response.json().get('wav_url')
|
| 26 |
+
if not audio_url:
|
| 27 |
+
return None, "No audio URL returned."
|
| 28 |
+
|
| 29 |
+
audio_data = requests.get(audio_url, headers={'Apikey': API_KEY})
|
| 30 |
+
if audio_data.status_code != 200:
|
| 31 |
+
return None, "Failed to download audio."
|
| 32 |
+
|
| 33 |
+
file_path = f"output_{uuid.uuid4().hex[:8]}.wav"
|
| 34 |
+
with open(file_path, 'wb') as f:
|
| 35 |
+
f.write(audio_data.content)
|
| 36 |
+
|
| 37 |
+
return file_path, file_path
|
| 38 |
+
|
| 39 |
+
with gr.Blocks() as demo:
|
| 40 |
+
gr.Markdown("## 🇹🇭 Thai Text-to-Speech with VAJA9")
|
| 41 |
+
|
| 42 |
+
with gr.Row():
|
| 43 |
+
text_input = gr.Textbox(label="ใส่ข้อความที่ต้องการสังเคราะห์เสียง (Thai text)", lines=3)
|
| 44 |
+
speaker_selector = gr.Dropdown(
|
| 45 |
+
choices=[
|
| 46 |
+
("เสียงผู้ชาย", 0),
|
| 47 |
+
("เสียงผู้หญิง", 1),
|
| 48 |
+
("เสียงเด็กผู้ชาย", 2),
|
| 49 |
+
("เสียงเด็กผู้หญิง", 3)
|
| 50 |
+
],
|
| 51 |
+
value=1,
|
| 52 |
+
label="เลือกเสียงพูด"
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
convert_button = gr.Button("🎤 สังเคราะห์เสียง")
|
| 56 |
+
audio_output = gr.Audio(label="🔊 เสียงที่สังเคราะห์", type="filepath")
|
| 57 |
+
download_output = gr.File(label="📥 ดาวน์โหลดไฟล์เสียง")
|
| 58 |
+
|
| 59 |
+
convert_button.click(fn=synthesize, inputs=[text_input, speaker_selector], outputs=[audio_output, download_output])
|
| 60 |
+
|
| 61 |
+
demo.launch()
|
dockerfile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use an official Python runtime as a parent image
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Set environment variables
|
| 5 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 6 |
+
ENV PYTHONUNBUFFERED=1
|
| 7 |
+
|
| 8 |
+
# Set work directory
|
| 9 |
+
WORKDIR /app
|
| 10 |
+
|
| 11 |
+
# Install dependencies
|
| 12 |
+
COPY requirements.txt /app/
|
| 13 |
+
RUN pip install --upgrade pip && pip install -r requirements.txt
|
| 14 |
+
|
| 15 |
+
# Copy the rest of the application
|
| 16 |
+
COPY . /app/
|
| 17 |
+
# Copy .env file
|
| 18 |
+
# COPY .env /app/.env
|
| 19 |
+
|
| 20 |
+
# Expose port for Gradio
|
| 21 |
+
EXPOSE 7860
|
| 22 |
+
|
| 23 |
+
# Run the application
|
| 24 |
+
CMD ["python", "app.py"]
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.33.2
|
| 2 |
+
requests
|
| 3 |
+
python-dotenv
|