Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- api/agent.py +6 -6
- api/main.py +9 -9
api/agent.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
"""
|
| 2 |
-
|
| 3 |
=============================================================
|
| 4 |
Architecture:
|
| 5 |
Every user message with symptom content is ALWAYS classified by Python directly.
|
|
@@ -30,7 +30,7 @@ _USE_HF = bool(_HF_TOKEN) and _HF_TOKEN not in ("", "none", "local")
|
|
| 30 |
LLM_MODEL = os.environ.get("HF_MODEL", "mistralai/Mistral-7B-Instruct-v0.3")
|
| 31 |
|
| 32 |
if _USE_HF:
|
| 33 |
-
logger.info("[
|
| 34 |
_hf_endpoint = HuggingFaceEndpoint(
|
| 35 |
repo_id=LLM_MODEL,
|
| 36 |
huggingfacehub_api_token=_HF_TOKEN,
|
|
@@ -39,11 +39,11 @@ if _USE_HF:
|
|
| 39 |
)
|
| 40 |
llm = ChatHuggingFace(llm=_hf_endpoint)
|
| 41 |
else:
|
| 42 |
-
logger.info("[
|
| 43 |
llm = ChatOllama(model="llama3.1:8b", temperature=0.1, num_predict=1024)
|
| 44 |
|
| 45 |
# ββ System Prompt βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 46 |
-
SYSTEM_PROMPT = """You are
|
| 47 |
|
| 48 |
YOUR ROLE:
|
| 49 |
- Conduct a structured clinical interview to gather neurological symptoms
|
|
@@ -157,7 +157,7 @@ def _greeting_response(msg: str, is_first_turn: bool) -> str | None:
|
|
| 157 |
"whats neurocheck","what can you do","tell me about",
|
| 158 |
"how does this work","how do you work","what do you do"]):
|
| 159 |
return (
|
| 160 |
-
"I'm
|
| 161 |
"specialising in Multiple Sclerosis (MS) and related neurological conditions.\n\n"
|
| 162 |
"I was designed by Dr. Avasarala (MD PhD, University of Kentucky) and "
|
| 163 |
"Dr. Kadambari (PhD, NIT Warangal).\n\n"
|
|
@@ -191,7 +191,7 @@ def _greeting_response(msg: str, is_first_turn: bool) -> str | None:
|
|
| 191 |
return "You're welcome! Is there anything else you'd like me to assess?"
|
| 192 |
if is_first_turn:
|
| 193 |
return (
|
| 194 |
-
"Hello! I'm
|
| 195 |
"I'm here to help evaluate neurological symptoms that may be related to "
|
| 196 |
"Multiple Sclerosis. Could you describe what you've been experiencing? "
|
| 197 |
"Please include when it started, which part of the body is affected, "
|
|
|
|
| 1 |
"""
|
| 2 |
+
AxonIQ Agentic AI β Direct Architecture (no tool-calling)
|
| 3 |
=============================================================
|
| 4 |
Architecture:
|
| 5 |
Every user message with symptom content is ALWAYS classified by Python directly.
|
|
|
|
| 30 |
LLM_MODEL = os.environ.get("HF_MODEL", "mistralai/Mistral-7B-Instruct-v0.3")
|
| 31 |
|
| 32 |
if _USE_HF:
|
| 33 |
+
logger.info("[AxonIQ] Using HuggingFace Inference API ({})", LLM_MODEL)
|
| 34 |
_hf_endpoint = HuggingFaceEndpoint(
|
| 35 |
repo_id=LLM_MODEL,
|
| 36 |
huggingfacehub_api_token=_HF_TOKEN,
|
|
|
|
| 39 |
)
|
| 40 |
llm = ChatHuggingFace(llm=_hf_endpoint)
|
| 41 |
else:
|
| 42 |
+
logger.info("[AxonIQ] Using local Ollama (llama3.1:8b)")
|
| 43 |
llm = ChatOllama(model="llama3.1:8b", temperature=0.1, num_predict=1024)
|
| 44 |
|
| 45 |
# ββ System Prompt βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 46 |
+
SYSTEM_PROMPT = """You are AxonIQ, a clinical decision support AI specialising in Multiple Sclerosis (MS). Designed by Dr. Avasarala (MD PhD, University of Kentucky) and Dr. Kadambari (PhD, NIT Warangal).
|
| 47 |
|
| 48 |
YOUR ROLE:
|
| 49 |
- Conduct a structured clinical interview to gather neurological symptoms
|
|
|
|
| 157 |
"whats neurocheck","what can you do","tell me about",
|
| 158 |
"how does this work","how do you work","what do you do"]):
|
| 159 |
return (
|
| 160 |
+
"I'm AxonIQ, an AI-powered clinical decision support assistant "
|
| 161 |
"specialising in Multiple Sclerosis (MS) and related neurological conditions.\n\n"
|
| 162 |
"I was designed by Dr. Avasarala (MD PhD, University of Kentucky) and "
|
| 163 |
"Dr. Kadambari (PhD, NIT Warangal).\n\n"
|
|
|
|
| 191 |
return "You're welcome! Is there anything else you'd like me to assess?"
|
| 192 |
if is_first_turn:
|
| 193 |
return (
|
| 194 |
+
"Hello! I'm AxonIQ, your MS clinical decision support assistant.\n\n"
|
| 195 |
"I'm here to help evaluate neurological symptoms that may be related to "
|
| 196 |
"Multiple Sclerosis. Could you describe what you've been experiencing? "
|
| 197 |
"Please include when it started, which part of the body is affected, "
|
api/main.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
"""
|
| 2 |
-
|
| 3 |
MS Symptom Classifier Β· spaCy NegEx Β· LangGraph Agent Β· RAG Knowledge Base
|
| 4 |
|
| 5 |
Tier 1/2 (SYMPTOM_PATTERNS) β 3.0 pts Γ severity multiplier
|
|
@@ -62,7 +62,7 @@ async def lifespan(app: FastAPI):
|
|
| 62 |
})
|
| 63 |
nlp.add_pipe("negex", config={"ent_types": ["SYMPTOM"], "neg_termset": ts.get_patterns()})
|
| 64 |
app.state.nlp = nlp
|
| 65 |
-
logger.info("[
|
| 66 |
|
| 67 |
# Init persistent database
|
| 68 |
from api.database import init_db, migrate_add_admin_column, set_admin, get_user_by_username, DB_PATH
|
|
@@ -72,16 +72,16 @@ async def lifespan(app: FastAPI):
|
|
| 72 |
migrate_add_logs_table()
|
| 73 |
migrate_add_otp_table()
|
| 74 |
# Log exact DB path so we can verify persistent storage is mounted
|
| 75 |
-
logger.info("[
|
| 76 |
-
logger.info("[
|
| 77 |
-
logger.info("[
|
| 78 |
# Auto-grant admin to ADMIN_USERNAME env var if set
|
| 79 |
admin_user = os.environ.get("ADMIN_USERNAME", "")
|
| 80 |
if admin_user:
|
| 81 |
u = get_user_by_username(admin_user)
|
| 82 |
if u and not u.get("is_admin"):
|
| 83 |
set_admin(admin_user, True)
|
| 84 |
-
logger.info("[
|
| 85 |
|
| 86 |
# Build RAG knowledge base (runs once, persists to disk)
|
| 87 |
try:
|
|
@@ -91,11 +91,11 @@ async def lifespan(app: FastAPI):
|
|
| 91 |
logger.warning("[RAG] Could not build knowledge base: {}", e)
|
| 92 |
|
| 93 |
yield
|
| 94 |
-
logger.info("[
|
| 95 |
|
| 96 |
|
| 97 |
app = FastAPI(
|
| 98 |
-
title="
|
| 99 |
version="9.0.0",
|
| 100 |
description=(
|
| 101 |
"MS Symptom Classifier + Agentic AI β 150-case validated. "
|
|
@@ -1122,7 +1122,7 @@ async def analyze_endpoint(req: SymptomRequest):
|
|
| 1122 |
async def health():
|
| 1123 |
return {
|
| 1124 |
"status": "ok",
|
| 1125 |
-
"model": "
|
| 1126 |
"negex": "active",
|
| 1127 |
"llm": "llama3.1:8b via Ollama",
|
| 1128 |
"rag": "ChromaDB (150 cases + MS guidelines)",
|
|
|
|
| 1 |
"""
|
| 2 |
+
AxonIQ β FastAPI Backend + Agentic AI
|
| 3 |
MS Symptom Classifier Β· spaCy NegEx Β· LangGraph Agent Β· RAG Knowledge Base
|
| 4 |
|
| 5 |
Tier 1/2 (SYMPTOM_PATTERNS) β 3.0 pts Γ severity multiplier
|
|
|
|
| 62 |
})
|
| 63 |
nlp.add_pipe("negex", config={"ent_types": ["SYMPTOM"], "neg_termset": ts.get_patterns()})
|
| 64 |
app.state.nlp = nlp
|
| 65 |
+
logger.info("[AxonIQ] spaCy model loaded: {}", model_path)
|
| 66 |
|
| 67 |
# Init persistent database
|
| 68 |
from api.database import init_db, migrate_add_admin_column, set_admin, get_user_by_username, DB_PATH
|
|
|
|
| 72 |
migrate_add_logs_table()
|
| 73 |
migrate_add_otp_table()
|
| 74 |
# Log exact DB path so we can verify persistent storage is mounted
|
| 75 |
+
logger.info("[AxonIQ] SQLite database initialized at: {}", str(DB_PATH))
|
| 76 |
+
logger.info("[AxonIQ] DB exists on disk: {}", DB_PATH.exists())
|
| 77 |
+
logger.info("[AxonIQ] /data mounted: {}", __import__("pathlib").Path("/data").exists())
|
| 78 |
# Auto-grant admin to ADMIN_USERNAME env var if set
|
| 79 |
admin_user = os.environ.get("ADMIN_USERNAME", "")
|
| 80 |
if admin_user:
|
| 81 |
u = get_user_by_username(admin_user)
|
| 82 |
if u and not u.get("is_admin"):
|
| 83 |
set_admin(admin_user, True)
|
| 84 |
+
logger.info("[AxonIQ] Admin access granted to '{}'", admin_user)
|
| 85 |
|
| 86 |
# Build RAG knowledge base (runs once, persists to disk)
|
| 87 |
try:
|
|
|
|
| 91 |
logger.warning("[RAG] Could not build knowledge base: {}", e)
|
| 92 |
|
| 93 |
yield
|
| 94 |
+
logger.info("[AxonIQ] Shutting down.")
|
| 95 |
|
| 96 |
|
| 97 |
app = FastAPI(
|
| 98 |
+
title="AxonIQ MS Classifier + Agentic AI",
|
| 99 |
version="9.0.0",
|
| 100 |
description=(
|
| 101 |
"MS Symptom Classifier + Agentic AI β 150-case validated. "
|
|
|
|
| 1122 |
async def health():
|
| 1123 |
return {
|
| 1124 |
"status": "ok",
|
| 1125 |
+
"model": "AxonIQ + Agentic AI",
|
| 1126 |
"negex": "active",
|
| 1127 |
"llm": "llama3.1:8b via Ollama",
|
| 1128 |
"rag": "ChromaDB (150 cases + MS guidelines)",
|