Spaces:
Sleeping
Sleeping
Download app.py from abdulhamed/AgriBot: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/spaces/abdulhamed/AgriBot/resolve/main/app.py
- Command line
-
hf download hf://spaces/abdulhamed/AgriBot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/abdulhamed/AgriBot/resolve/main/app.py
1.21 kB
| from fastapi import FastAPI | |
| from fastapi.responses import HTMLResponse | |
| from fastapi.staticfiles import StaticFiles | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from pydantic import BaseModel | |
| from pathlib import Path | |
| app = FastAPI() | |
| # CORS – allow embedding and external calls if needed | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # FIX: Use absolute path for Hugging Face Spaces | |
| STATIC_DIR = Path(__file__).parent / "static" | |
| app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static") | |
| class ChatRequest(BaseModel): | |
| message: str | |
| def serve_html(): | |
| index_path = STATIC_DIR / "index.html" | |
| return index_path.read_text(encoding="utf-8") | |
| def chat_endpoint(req: ChatRequest): | |
| user_message = req.message.strip() | |
| if not user_message: | |
| reply = "من فضلك اكتب رسالة للبدء." | |
| else: | |
| reply = ( | |
| "هذا رد مؤقت — سيتم دمج نموذج الذكاء الاصطناعي لاحقًا.\n\n" | |
| f"لقد كتبت: \"{user_message}\"" | |
| ) | |
| return {"response": reply} | |