Spaces:
Sleeping
Sleeping
Add sample test cases knowledge base for demo validation
Browse files- app.py +108 -1
- papers/The Atomic VSA.tex +0 -0
app.py
CHANGED
|
@@ -80,6 +80,91 @@ SYMPTOM_LABELS = {
|
|
| 80 |
"chills": "Chills"
|
| 81 |
}
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
# ============================================================================
|
| 84 |
# UI Functions
|
| 85 |
# ============================================================================
|
|
@@ -229,7 +314,29 @@ with gr.Blocks(title="Atomic VSA", theme=gr.themes.Soft()) as demo:
|
|
| 229 |
outputs=[result_output, scores_output, tech_output]
|
| 230 |
)
|
| 231 |
|
| 232 |
-
# Tab 2:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
with gr.TabItem("📄 About"):
|
| 234 |
gr.Markdown("""
|
| 235 |
## Atomic Vector Symbolic Architecture
|
|
|
|
| 80 |
"chills": "Chills"
|
| 81 |
}
|
| 82 |
|
| 83 |
+
# ============================================================================
|
| 84 |
+
# Sample Test Cases for Knowledge Base
|
| 85 |
+
# ============================================================================
|
| 86 |
+
|
| 87 |
+
SAMPLE_CASES = [
|
| 88 |
+
{
|
| 89 |
+
"name": "🚨 Case 1: Cardiac Emergency",
|
| 90 |
+
"symptoms": ["chest_pain", "shortness_of_breath", "dizziness"],
|
| 91 |
+
"expected": "Emergency - Cardiac",
|
| 92 |
+
"rationale": "Classic cardiac triad: chest pain + breathlessness + dizziness indicates possible MI/ACS",
|
| 93 |
+
"confidence": "~85-95%"
|
| 94 |
+
},
|
| 95 |
+
{
|
| 96 |
+
"name": "⚠️ Case 2: Respiratory Distress",
|
| 97 |
+
"symptoms": ["shortness_of_breath", "cough", "fever", "chills"],
|
| 98 |
+
"expected": "Urgent - Respiratory",
|
| 99 |
+
"rationale": "Fever + chills with respiratory symptoms suggests pneumonia or severe bronchitis",
|
| 100 |
+
"confidence": "~75-85%"
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
"name": "⚠️ Case 3: Systemic Infection",
|
| 104 |
+
"symptoms": ["fever", "chills", "fatigue", "muscle_ache"],
|
| 105 |
+
"expected": "Urgent - Infection",
|
| 106 |
+
"rationale": "High fever with systemic symptoms (chills, myalgia) indicates significant infection",
|
| 107 |
+
"confidence": "~80-90%"
|
| 108 |
+
},
|
| 109 |
+
{
|
| 110 |
+
"name": "📋 Case 4: Common Flu",
|
| 111 |
+
"symptoms": ["fever", "cough", "sore_throat", "runny_nose", "muscle_ache"],
|
| 112 |
+
"expected": "Standard - Flu-like",
|
| 113 |
+
"rationale": "Classic influenza presentation: upper respiratory + systemic symptoms",
|
| 114 |
+
"confidence": "~85-95%"
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
"name": "📋 Case 5: GI Complaint",
|
| 118 |
+
"symptoms": ["nausea", "abdominal_pain", "fever"],
|
| 119 |
+
"expected": "Standard - GI",
|
| 120 |
+
"rationale": "GI symptoms with low-grade fever suggests gastroenteritis or food poisoning",
|
| 121 |
+
"confidence": "~70-80%"
|
| 122 |
+
},
|
| 123 |
+
{
|
| 124 |
+
"name": "📋 Case 6: Musculoskeletal",
|
| 125 |
+
"symptoms": ["back_pain", "joint_pain", "muscle_ache"],
|
| 126 |
+
"expected": "Standard - Musculoskeletal",
|
| 127 |
+
"rationale": "Localized pain without systemic symptoms - routine orthopedic/rheumatologic eval",
|
| 128 |
+
"confidence": "~75-85%"
|
| 129 |
+
},
|
| 130 |
+
{
|
| 131 |
+
"name": "✅ Case 7: Minor Illness",
|
| 132 |
+
"symptoms": ["headache", "fatigue", "runny_nose"],
|
| 133 |
+
"expected": "Low Priority - Minor",
|
| 134 |
+
"rationale": "Mild symptoms without fever or respiratory distress - likely common cold",
|
| 135 |
+
"confidence": "~70-80%"
|
| 136 |
+
},
|
| 137 |
+
]
|
| 138 |
+
|
| 139 |
+
def get_sample_cases_markdown():
|
| 140 |
+
"""Generate markdown table of sample cases."""
|
| 141 |
+
md = """
|
| 142 |
+
## 📚 Sample Test Cases
|
| 143 |
+
|
| 144 |
+
Use these cases to validate the system is working correctly. Click "Try This Case" to auto-fill symptoms.
|
| 145 |
+
|
| 146 |
+
| Case | Symptoms | Expected Result | Confidence |
|
| 147 |
+
|------|----------|-----------------|------------|
|
| 148 |
+
"""
|
| 149 |
+
for case in SAMPLE_CASES:
|
| 150 |
+
symptoms_str = ", ".join([SYMPTOM_LABELS[s] for s in case["symptoms"]])
|
| 151 |
+
md += f"| {case['name']} | {symptoms_str} | **{case['expected']}** | {case['confidence']} |\n"
|
| 152 |
+
|
| 153 |
+
md += """
|
| 154 |
+
|
| 155 |
+
### How to Use
|
| 156 |
+
1. Go to the **Clinical Triage** tab
|
| 157 |
+
2. Select the symptoms listed for a case
|
| 158 |
+
3. Click **Classify Patient**
|
| 159 |
+
4. Verify the result matches the expected classification
|
| 160 |
+
|
| 161 |
+
### Understanding Results
|
| 162 |
+
- **Confidence** is the cosine similarity between patient vector and category prototype
|
| 163 |
+
- Higher values (>80%) indicate strong match
|
| 164 |
+
- Multiple categories may have similar scores for overlapping symptoms
|
| 165 |
+
"""
|
| 166 |
+
return md
|
| 167 |
+
|
| 168 |
# ============================================================================
|
| 169 |
# UI Functions
|
| 170 |
# ============================================================================
|
|
|
|
| 314 |
outputs=[result_output, scores_output, tech_output]
|
| 315 |
)
|
| 316 |
|
| 317 |
+
# Tab 2: Sample Cases (Knowledge Base)
|
| 318 |
+
with gr.TabItem("📚 Sample Cases"):
|
| 319 |
+
gr.Markdown(get_sample_cases_markdown())
|
| 320 |
+
|
| 321 |
+
gr.Markdown("---\n### 🧪 Detailed Case Explanations")
|
| 322 |
+
|
| 323 |
+
for case in SAMPLE_CASES:
|
| 324 |
+
with gr.Accordion(case["name"], open=False):
|
| 325 |
+
gr.Markdown(f"""
|
| 326 |
+
**Symptoms to Select:**
|
| 327 |
+
{chr(10).join(['- ' + SYMPTOM_LABELS[s] for s in case['symptoms']])}
|
| 328 |
+
|
| 329 |
+
**Expected Classification:** `{case['expected']}`
|
| 330 |
+
|
| 331 |
+
**Clinical Rationale:** {case['rationale']}
|
| 332 |
+
|
| 333 |
+
**Expected Confidence Range:** {case['confidence']}
|
| 334 |
+
|
| 335 |
+
---
|
| 336 |
+
*This pattern is encoded in the VSA prototype vectors built from clinical knowledge.*
|
| 337 |
+
""")
|
| 338 |
+
|
| 339 |
+
# Tab 3: About
|
| 340 |
with gr.TabItem("📄 About"):
|
| 341 |
gr.Markdown("""
|
| 342 |
## Atomic Vector Symbolic Architecture
|
papers/The Atomic VSA.tex
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|