Download server.py from P2THE28/model: direct link, hf CLI and curl.
- Browser
- Download file 2.22 kB
-
https://huggingface.co/spaces/P2THE28/model/resolve/main/server.py
- Command line
-
hf download hf://spaces/P2THE28/model/server.py
-
curl -L -o server.py https://huggingface.co/spaces/P2THE28/model/resolve/main/server.py
2.22 kB
| import sys | |
| from pathlib import Path | |
| from fastapi import FastAPI, HTTPException | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from pydantic import BaseModel | |
| # ============================================================ | |
| # PROJECT PATH | |
| # ============================================================ | |
| PROJECT_ROOT = Path(__file__).resolve().parent.parent | |
| sys.path.append(str(PROJECT_ROOT)) | |
| # ============================================================ | |
| # RIGHTS NAVIGATOR | |
| # ============================================================ | |
| from rights_navigator.rights_navigator import get_rights_response | |
| # ============================================================ | |
| # FASTAPI | |
| # ============================================================ | |
| app = FastAPI( | |
| title="CaseLoop Rights Navigator API" | |
| ) | |
| # ============================================================ | |
| # CORS | |
| # ============================================================ | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # ============================================================ | |
| # REQUEST MODEL | |
| # ============================================================ | |
| class RightsRequest(BaseModel): | |
| grievance: str | |
| # ============================================================ | |
| # HEALTH CHECK | |
| # ============================================================ | |
| async def root(): | |
| return { | |
| "status": "online", | |
| "service": "CaseLoop Rights Navigator", | |
| "endpoint": "/rights" | |
| } | |
| # ============================================================ | |
| # RIGHTS NAVIGATOR | |
| # ============================================================ | |
| async def rights_endpoint(request: RightsRequest): | |
| if not request.grievance.strip(): | |
| raise HTTPException( | |
| status_code=400, | |
| detail="Grievance cannot be empty." | |
| ) | |
| try: | |
| result = get_rights_response( | |
| request.grievance | |
| ) | |
| return result | |
| except Exception as e: | |
| raise HTTPException( | |
| status_code=500, | |
| detail=str(e) | |
| ) |