Download run_adherence.py from MoBkr/dosemate: direct link, hf CLI and curl.
- Browser
- Download file 2.86 kB
-
https://huggingface.co/spaces/MoBkr/dosemate/resolve/main/run_adherence.py
- Command line
-
hf download hf://spaces/MoBkr/dosemate/run_adherence.py
-
curl -L -o run_adherence.py https://huggingface.co/spaces/MoBkr/dosemate/resolve/main/run_adherence.py
2.86 kB
| """Lightweight dev harness for the medication-adherence layer. | |
| Runs ONLY the new feature routers (accounts, schedule, doses, gamification, | |
| caregiver) on SQLite — without loading the heavy AI chat pipeline. Use this to | |
| demo/test the new features when langchain/chromadb/Postgres/API keys aren't set | |
| up. The real production entry point remains `main.py` (uvicorn main:app). | |
| uvicorn run_adherence:app --reload | |
| """ | |
| import os | |
| import sys | |
| # Make console output UTF-8 safe on Windows (avoids emoji print crashes). | |
| try: | |
| sys.stdout.reconfigure(encoding="utf-8") | |
| sys.stderr.reconfigure(encoding="utf-8") | |
| except Exception: | |
| pass | |
| # Must be set BEFORE importing database/routers so the engine picks it up. | |
| os.environ.setdefault("DATABASE_URL", "sqlite:///./adherence_dev.db") | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from database import Base, engine | |
| from routers import ( | |
| auth_router, medications_router, schedule_router, notifications_router, | |
| gamification_router, settings_router, conversations_router, | |
| ) | |
| Base.metadata.create_all(bind=engine) | |
| app = FastAPI(title="PharmaChat — Adherence (dev harness)") | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["http://localhost:5173"], | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| app.include_router(auth_router.router) | |
| app.include_router(medications_router.router) | |
| app.include_router(schedule_router.router) | |
| app.include_router(notifications_router.router) | |
| app.include_router(gamification_router.router) | |
| app.include_router(settings_router.router) | |
| app.include_router(conversations_router.router) | |
| def health(): | |
| return {"status": "ok", "mode": "adherence-dev-harness", "db": os.environ["DATABASE_URL"]} | |
| # In this lightweight harness the AI chat pipeline isn't loaded. Return a clear | |
| # explanation instead of a connection error so the chat page stays friendly. | |
| from pydantic import BaseModel | |
| from typing import Optional | |
| class _ChatStub(BaseModel): | |
| query: Optional[str] = None | |
| image_base64: Optional[str] = None | |
| conversation_id: Optional[int] = None | |
| def chat_stub(_req: _ChatStub): | |
| return { | |
| "response": ( | |
| "ℹ️ Chat is disabled in this demo mode. The medication-assistant chat " | |
| "needs the full AI stack (Groq/Gemini + ChromaDB), which isn't installed " | |
| "here. All the new features work though — try Schedule, Today's Doses, " | |
| "Leaderboard, and Profile from the sidebar!" | |
| ) | |
| } | |
| def messages_stub(conversation_id: int): | |
| return {"messages": []} | |
| def _startup(): | |
| try: | |
| from scheduler import start_scheduler | |
| start_scheduler() | |
| except Exception as e: | |
| print(f"[harness] scheduler not started: {e}") | |