File size: 876 Bytes
27bc436
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Save this as main.py

from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from gradio_client import Client
import uvicorn

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:
        # Call your Hugging Face Space via gradio_client
        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)

# For local testing
if __name__ == "__main__":
    uvicorn.run("main:app", host="0.0.0.0", port=7860, reload=True)