MusicalChatBott / app.py
kareem2222's picture
Update app.py
f94e225 verified
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 some file information for debugging
print(f"File name: {file.filename}")
print(f"File content type: {file.content_type}")
# Ensure the directory exists
os.makedirs("/tmp", exist_ok=True)
# Define the file location
file_location = f"/tmp/{file.filename}"
with open(file_location, "wb") as f:
f.write(await file.read())
# Process the question from the audio file
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__":
# Apply the patch
nest_asyncio.apply()
# Run the FastAPI app
uvicorn.run(app, host="0.0.0.0", port=8000)