File size: 1,182 Bytes
3942755 f94e225 3942755 f94e225 3942755 f94e225 3942755 f94e225 3942755 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
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)
|