File size: 652 Bytes
c23265c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from gradio_client import Client

app = FastAPI()
client = Client("HusseinBashir/Somali_tts")

@app.post("/somali-tts/")
async def somali_tts(request: Request):
    data = await request.json()
    text = data.get("text")
    if not text:
        return JSONResponse(content={"error": "No text provided"}, status_code=400)
    try:
        audio_url = client.predict(text, api_name="/predict")
        return JSONResponse(content={"audio_url": audio_url})
    except Exception as e:
        return JSONResponse(content={"error": str(e)}, status_code=500)