Download anam/main.py from SUPER321/anam_code: direct link, hf CLI and curl.
- Browser
- Download file 1.5 kB
-
https://huggingface.co/spaces/SUPER321/anam_code/resolve/main/anam/main.py
- Command line
-
hf download hf://spaces/SUPER321/anam_code/anam/main.py
-
curl -L -o main.py https://huggingface.co/spaces/SUPER321/anam_code/resolve/main/anam/main.py
1.5 kB
| from pathlib import Path | |
| import httpx | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi.staticfiles import StaticFiles | |
| from config import BASE, RAG_SYSTEM_PROMPT | |
| from helpers import auth_headers | |
| from rag import rag_state, router as rag_router | |
| from routers import clinical, frontend, llm, local_rag as local_rag_router, personas, sessions, telemetry as telemetry_router | |
| app = FastAPI(title="Anam AI Demo with RAG") | |
| app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"]) | |
| app.mount("/static", StaticFiles(directory=Path(__file__).parent / "static"), name="static") | |
| for router in (frontend.router, personas.router, sessions.router, llm.router, clinical.router, telemetry_router.router): | |
| app.include_router(router) | |
| app.include_router(rag_router) | |
| app.include_router(local_rag_router.router) | |
| async def sync_persona_prompt(): | |
| """Push the current RAG_SYSTEM_PROMPT to the existing persona on every server start.""" | |
| if not rag_state.get("persona_id"): | |
| return | |
| try: | |
| async with httpx.AsyncClient(timeout=15) as c: | |
| await c.put( | |
| f"{BASE}/personas/{rag_state['persona_id']}", | |
| headers=auth_headers(), | |
| json={"systemPrompt": RAG_SYSTEM_PROMPT}, | |
| ) | |
| print("RAG persona system prompt synced on startup.") | |
| except Exception as e: | |
| print(f"Could not sync persona prompt on startup: {e}") | |