s / backend /app.py
redfernstech's picture
Upload 5 files
6537124 verified
raw
history blame
961 Bytes
from fastapi import FastAPI, UploadFile
from fastapi.responses import FileResponse
from backend.whisper_utils import transcribe_audio
from backend.gtts_utils import generate_speech
from backend.llm_utils import get_llm_response
import os
app = FastAPI()
@app.post("/transcribe/")
async def transcribe(file: UploadFile):
file_path = f"audio/{file.filename}"
with open(file_path, "wb") as audio:
audio.write(await file.read())
text = transcribe_audio(file_path)
os.remove(file_path) # Cleanup audio file
return {"transcription": text}
@app.post("/response/")
async def get_response(input_text: str):
llm_response = get_llm_response(input_text)
audio_path = generate_speech(llm_response)
return {"response": llm_response, "audio_url": audio_path}
@app.get("/audio/{file_name}")
async def serve_audio(file_name: str):
file_path = f"audio/{file_name}"
return FileResponse(file_path)