Spaces:
Paused
Paused
| import gradio as gr | |
| from fastapi import FastAPI, UploadFile, File, Request | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi.responses import StreamingResponse | |
| from fastapi.staticfiles import StaticFiles | |
| from app.agent import process_text | |
| from app.speech_to_text import transcribe_audio | |
| from app.text_to_speech import synthesize_speech | |
| import io | |
| app = FastAPI() | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| app.mount("/", StaticFiles(directory="frontend", html=True), name="frontend") | |
| async def transcribe(file: UploadFile = File(...)): | |
| audio_bytes = await file.read() | |
| text = transcribe_audio(audio_bytes) | |
| return {"transcription": text} | |
| async def query_agent(request: Request): | |
| data = await request.json() | |
| input_text = data.get("input_text", "") | |
| response = process_text(input_text) | |
| return {"response": response} | |
| async def speak(text: str): | |
| audio = synthesize_speech(text) | |
| return StreamingResponse(io.BytesIO(audio), media_type="audio/wav") | |
| # Required for Hugging Face Spaces | |
| gradio_app = gr.mount_gradio_app(app, None) | |