Spaces:
Sleeping
Sleeping
| # 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") # | |
| 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) | |