|
from fastapi import FastAPI, UploadFile, HTTPException |
|
import subprocess |
|
import os |
|
|
|
app = FastAPI() |
|
|
|
|
|
subprocess.check_call(["pip", "install", "-r", "requirements.txt"]) |
|
|
|
@app.post("/ask-question/") |
|
async def ask_question(file: UploadFile): |
|
try: |
|
|
|
print(f"File name: {file.filename}") |
|
print(f"File content type: {file.content_type}") |
|
|
|
|
|
os.makedirs("/tmp", exist_ok=True) |
|
|
|
|
|
file_location = f"/tmp/{file.filename}" |
|
with open(file_location, "wb") as f: |
|
f.write(await file.read()) |
|
|
|
|
|
answer, audio_response = process_audio_question(file_location) |
|
|
|
return {"text_answer": answer, "audio_response": audio_response} |
|
except Exception as e: |
|
raise HTTPException(status_code=500, detail=str(e)) |
|
|
|
import nest_asyncio |
|
import uvicorn |
|
|
|
if __name__ == "__main__": |
|
|
|
nest_asyncio.apply() |
|
|
|
|
|
uvicorn.run(app, host="0.0.0.0", port=8000) |
|
|