Spaces:
Paused
Paused
File size: 1,212 Bytes
6a500ca |
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
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")
@app.post("/transcribe")
async def transcribe(file: UploadFile = File(...)):
audio_bytes = await file.read()
text = transcribe_audio(audio_bytes)
return {"transcription": text}
@app.post("/query")
async def query_agent(request: Request):
data = await request.json()
input_text = data.get("input_text", "")
response = process_text(input_text)
return {"response": response}
@app.get("/speak")
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)
|