Download app.py from kareem2222/MusicalChatBott: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/kareem2222/MusicalChatBott/resolve/main/app.py
- Command line
-
hf download hf://kareem2222/MusicalChatBott/app.py
-
curl -L -o app.py https://huggingface.co/kareem2222/MusicalChatBott/resolve/main/app.py
1.18 kB
| from fastapi import FastAPI, UploadFile, HTTPException | |
| import subprocess | |
| import os | |
| app = FastAPI() | |
| # تثبيت المكتبات عند بدء التشغيل | |
| subprocess.check_call(["pip", "install", "-r", "requirements.txt"]) | |
| 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) | |