Spaces:
Build error
Build error
Download app/main.py from SherinMohamed/Egyptian_Chatbot: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/spaces/SherinMohamed/Egyptian_Chatbot/resolve/main/app/main.py
- Command line
-
hf download hf://spaces/SherinMohamed/Egyptian_Chatbot/app/main.py
-
curl -L -o main.py https://huggingface.co/spaces/SherinMohamed/Egyptian_Chatbot/resolve/main/app/main.py
1.49 kB
| import os | |
| import shutil | |
| from fastapi import FastAPI, UploadFile, File | |
| from fastapi.responses import FileResponse, JSONResponse | |
| from app.pipeline import FullEgyptianVoiceChatbot | |
| app = FastAPI(title="Egyptian Arabic Voice Chatbot (JAIS + EGTTS)") | |
| bot = FullEgyptianVoiceChatbot() | |
| from fastapi.middleware.cors import CORSMiddleware | |
| app = FastAPI(title="Egyptian Arabic Voice Chatbot (JAIS + EGTTS)") | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["http://localhost:3000", "http://127.0.0.1:3000"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| def health(): | |
| return {"status": "ok"} | |
| async def chat_text(payload: dict): | |
| text = (payload.get("text") or "").strip() | |
| if not text: | |
| return JSONResponse({"error": "Missing text"}, status_code=400) | |
| result = bot.chat_text(text) | |
| return result | |
| async def chat_voice(file: UploadFile = File(...)): | |
| os.makedirs("uploads", exist_ok=True) | |
| tmp_path = f"uploads/{file.filename}" | |
| with open(tmp_path, "wb") as f: | |
| shutil.copyfileobj(file.file, f) | |
| result = bot.chat_voice(tmp_path) | |
| return result | |
| def get_audio(audio_id: str): | |
| path = f"outputs/{audio_id}.wav" | |
| if not os.path.exists(path): | |
| return JSONResponse({"error": "Audio not found"}, status_code=404) | |
| return FileResponse(path, media_type="audio/wav", filename=f"{audio_id}.wav") | |