HusseinBashir commited on
Commit
27bc436
·
verified ·
1 Parent(s): f664b44

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +26 -0
main.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Save this as main.py
2
+
3
+ from fastapi import FastAPI, Request
4
+ from fastapi.responses import JSONResponse
5
+ from gradio_client import Client
6
+ import uvicorn
7
+
8
+ app = FastAPI()
9
+ client = Client("HusseinBashir/Somali_tts") #
10
+
11
+ @app.post("/somali-tts/")
12
+ async def somali_tts(request: Request):
13
+ data = await request.json()
14
+ text = data.get("text")
15
+ if not text:
16
+ return JSONResponse(content={"error": "No text provided"}, status_code=400)
17
+ try:
18
+ # Call your Hugging Face Space via gradio_client
19
+ audio_url = client.predict(text, api_name="/predict")
20
+ return JSONResponse(content={"audio_url": audio_url})
21
+ except Exception as e:
22
+ return JSONResponse(content={"error": str(e)}, status_code=500)
23
+
24
+ # For local testing
25
+ if __name__ == "__main__":
26
+ uvicorn.run("main:app", host="0.0.0.0", port=7860, reload=True)