s / app.py
redfernstech's picture
Update app.py
3076331 verified
raw
history blame contribute delete
908 Bytes
from fastapi import FastAPI, UploadFile
from fastapi.responses import FileResponse
from whisper_utils import transcribe_audio
from gtts_utils import generate_speech
from 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)