Spaces:
Runtime error
Runtime error
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() | |
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} | |
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} | |
async def serve_audio(file_name: str): | |
file_path = f"audio/{file_name}" | |
return FileResponse(file_path) | |