grasant commited on
Commit
c6204f8
Β·
verified Β·
1 Parent(s): 5968f6b

Rename Space card to HelloFibro

Browse files
Files changed (1) hide show
  1. README.md +1055 -0
README.md ADDED
@@ -0,0 +1,1055 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: HelloFibro
3
+ emoji: πŸ’œ
4
+ colorFrom: red
5
+ colorTo: yellow
6
+ sdk: gradio
7
+ sdk_version: 6.15.1
8
+ app_file: app.py
9
+ python_version: "3.12"
10
+ startup_duration_timeout: 1h
11
+ suggested_hardware: zero-a10g
12
+ short_description: Multimodal fibromyalgia support with MedGemma
13
+ models:
14
+ - google/medgemma-27b-it
15
+ ---
16
+
17
+ <p align="center">
18
+ <img width="250" height="250" alt="logo" src="https://github.com/user-attachments/assets/c2ad2088-729e-4257-9793-2f96f49053b0" />
19
+ </p>
20
+
21
+ <p align="center">
22
+ <strong>AI-powered support companion for people living with fibromyalgia</strong>
23
+ </p>
24
+
25
+ <p align="center">
26
+ <a href="#-features">Features</a> β€’
27
+ <a href="#-demo">Demo</a> β€’
28
+ <a href="#-quick-start">Quick Start</a> β€’
29
+ <a href="#-tech-stack">Tech Stack</a> β€’
30
+ <a href="#-architecture">Architecture</a> β€’
31
+ <a href="#-workflows">Workflows</a>
32
+ </p>
33
+
34
+ <p align="center">
35
+ <img src="https://img.shields.io/badge/Python-3.10+-3776AB?style=for-the-badge&logo=python&logoColor=white" alt="Python">
36
+ <img src="https://img.shields.io/badge/Gradio-6.0-FF7C00?style=for-the-badge&logo=gradio&logoColor=white" alt="Gradio">
37
+ <img src="https://img.shields.io/badge/Claude-Sonnet_4-191919?style=for-the-badge&logo=anthropic&logoColor=white" alt="Claude">
38
+
39
+ </p>
40
+
41
+ <p align="center">
42
+ <img src="https://img.shields.io/badge/UI-Art_Deco_Inspired-8B0000?style=flat-square" alt="Art Deco">
43
+ <img src="https://img.shields.io/badge/Accessibility-WCAG_AA-D4AF37?style=flat-square" alt="WCAG AA">
44
+ <img src="https://img.shields.io/badge/Languages-21_Supported-white?style=flat-square" alt="21 Languages">
45
+ </p>
46
+
47
+ ---
48
+
49
+ ## πŸ“– About
50
+
51
+ **HelloFibro** is an AI assistant designed specifically for people living with fibromyalgia. It provides emotional support, evidence-based information, practical coping strategies, and medication managementβ€”all through a beautiful, accessible interface optimized for those experiencing chronic pain and fatigue.
52
+
53
+ ### Why HelloFibro?
54
+
55
+ Living with fibromyalgia means dealing with invisible symptoms that others often don't understand. HelloFibro was built with deep empathy and understanding:
56
+
57
+ - πŸ’™ **Validation First** β€” Your pain is real. Your experiences matter.
58
+ - 🧠 **Brain Fog Friendly** β€” Clear, simple interface designed for cognitive challenges
59
+ - πŸŒ™ **Gentle Design** β€” Art Deco-inspired aesthetics that are calming, not overwhelming
60
+ - 🌍 **21 Languages** β€” Full internationalization with native language support
61
+ - πŸ”’ **Privacy Focused** β€” No data persistence, session-only storage
62
+
63
+ ---
64
+
65
+ ## 🎬 Demo
66
+
67
+ https://github.com/user-attachments/assets/4f57d250-8355-4167-927e-f14fa78e8a6e
68
+
69
+ The hosted MedGemma version is a research/portfolio demonstration, not a
70
+ medical device or healthcare service. Chat access is gated by acceptance of the
71
+ [HelloFibro HAI-DEF Demo Use Terms](docs/HAI_DEF_DEMO_TERMS.md), which
72
+ incorporate Google's
73
+ [HAI-DEF Terms of Use](https://developers.google.com/health-ai-developer-foundations/terms)
74
+ and
75
+ [Prohibited Use Policy](https://developers.google.com/health-ai-developer-foundations/prohibited-use-policy).
76
+
77
+ ---
78
+
79
+ ## ✨ Features
80
+
81
+ ### πŸ’¬ Empathetic AI Chat
82
+
83
+ The heart of HelloFibroβ€”intelligent, understanding conversations powered by Claude Sonnet 4.
84
+
85
+ | Feature | Description |
86
+ |---------|-------------|
87
+ | **Streaming Responses** | Real-time typing effect for natural conversation flow |
88
+ | **Fibromyalgia Expertise** | Specialized knowledge about symptoms, triggers, and management |
89
+ | **Session Memory** | Remembers context within your conversation |
90
+ | **Markdown Support** | Rich formatting for clear, readable responses |
91
+ | **Brain Fog Consideration** | Short paragraphs, clear language, patient pacing |
92
+ | **Medical Context Awareness** | Automatically detects worsening factors in your messages |
93
+ | **EULAR 2016 Compliance** | Recommendations align with EU clinical guidelines |
94
+
95
+ ```
96
+ User: Mam dziś bardzo silny ból i nie wiem co robić
97
+
98
+ HelloFibro: πŸ’™ Bardzo mi przykro, ΕΌe mierzysz siΔ™ dziΕ› z takim silnym bΓ³lem.
99
+ To musi być naprawdę trudne.
100
+
101
+ Kilka rzeczy, ktΓ³re mogΔ… pomΓ³c w tej chwili:
102
+ β€’ ZnajdΕΊ wygodnΔ… pozycjΔ™ i pozwΓ³l sobie odpoczΔ…Δ‡
103
+ β€’ CiepΕ‚y okΕ‚ad moΕΌe przynieΕ›Δ‡ ulgΔ™
104
+ β€’ Spokojne, gΕ‚Δ™bokie oddychanie...
105
+ ```
106
+
107
+ ### πŸ’Š Medication Management
108
+
109
+ Comprehensive medication tracking designed for chronic illness management.
110
+
111
+ | Feature | Description |
112
+ |---------|-------------|
113
+ | **Quick Add** | Add medications via chat or form interface |
114
+ | **Visual Tracking** | See all medications with taken/pending status |
115
+ | **One-Tap Logging** | Mark medications as taken with a single click |
116
+ | **Missed Dose Alerts** | Smart notifications for missed doses after 4 AM |
117
+ | **Reminder Toggle** | Enable/disable reminders per medication |
118
+ | **Adherence Stats** | Track your medication compliance |
119
+
120
+ #### ⚠️ Missed Dose Notification
121
+
122
+ When you miss a medication dose, HelloFibro will remind you the next morning (after 4:00 AM) with a gentle notification:
123
+
124
+ | Action | Description |
125
+ |--------|-------------|
126
+ | **βœ“ WziΔ™ty** | Mark as taken late (still counts for adherence) |
127
+ | **βœ— PominiΔ™ty** | Register as missed dose |
128
+ | **Odrzuć** | Dismiss notification without logging |
129
+
130
+ The notification uses calming amber colors (not aggressive red) following healthcare UX best practices for reduced alert fatigue.
131
+
132
+ **Supported medication categories:**
133
+ - Fibromyalgia/Neuropathic (Pregabalin, Duloxetine, Gabapentin...)
134
+ - NSAIDs (Ibuprofen, Ketoprofen, Naproxen...)
135
+ - Stronger painkillers (Tramadol, Tapentadol...)
136
+ - Muscle relaxants (Tizanidine, Baclofen...)
137
+ - Sleep aids (Melatonin, Trazodone...)
138
+ - Supplements (Magnesium, Vitamin D3, CBD oil...)
139
+
140
+ ### πŸ“… Appointment Management
141
+
142
+ Track and manage your doctor appointments with smart reminders.
143
+
144
+ | Feature | Description |
145
+ |---------|-------------|
146
+ | **Add Appointments** | Schedule visits with doctor name, specialty, date/time, location |
147
+ | **Specialty Types** | Pre-defined medical specialties (Rheumatologist, Neurologist, etc.) |
148
+ | **Visual Tracking** | See upcoming appointments with status indicators |
149
+ | **Smart Reminders** | Optional day-before reminder notifications |
150
+ | **Notes** | Add questions and notes for each appointment |
151
+ | **Status Indicators** | Today, Soon, Upcoming, Past appointment badges |
152
+
153
+ **Medical use cases:**
154
+ - Schedule rheumatologist follow-ups
155
+ - Track physiotherapy sessions
156
+ - Prepare questions for specialist visits
157
+ - Never miss important appointments
158
+
159
+ ### πŸ“Ž File Analysis
160
+
161
+ Upload and discuss medical documents with AI assistance.
162
+
163
+ | File Type | Supported Formats | Capabilities |
164
+ |-----------|-------------------|--------------|
165
+ | **Documents** | PDF, DOCX, DOC | Extract text, find key health info |
166
+ | **Spreadsheets** | XLSX, XLS, CSV | Analyze symptoms, patterns, statistics |
167
+ | **Text Files** | TXT, MD, JSON, XML, LOG | Parse and explain content |
168
+ | **Images** | PNG, JPG, GIF, WEBP | Describe and discuss |
169
+ | **Code** | PY, JS, HTML, CSS | Explain and analyze |
170
+
171
+ **Medical use cases:**
172
+ - πŸ“‹ Prescription analysis
173
+ - πŸ“Š Symptom diary review
174
+ - 🩺 Lab results discussion
175
+ - πŸ“ Doctor visit preparation
176
+
177
+ ### 🧠 Medical Intelligence Layer
178
+
179
+ Advanced AI-powered medical reasoning system for evidence-based fibromyalgia support.
180
+
181
+ | Component | Description |
182
+ |-----------|-------------|
183
+ | **Adaptive Reasoning Router** | Routes queries to appropriate reasoning depth based on complexity |
184
+ | **Medical Knowledge Service** | Queries 15+ worsening factors, EULAR guidelines, differential diagnosis |
185
+ | **EU Guidelines Validator** | Validates recommendations against EULAR 2016, German S3, UK NICE |
186
+ | **FHIR Patient Profile** | HL7 FHIR R4-compliant patient model with ACR 2016 criteria |
187
+ | **Agent Council** | Multi-agent system with backtracking exploration for complex cases |
188
+
189
+ #### Reasoning Modes
190
+
191
+ | Mode | Complexity | Use Case |
192
+ |------|------------|----------|
193
+ | **Parallel Short** | < 0.3 | Simple symptom questions, medication lookup |
194
+ | **Sequential Medium** | 0.3-0.7 | Symptom pattern analysis, treatment comparison |
195
+ | **Deep Sequential** | > 0.7 | Differential diagnosis, treatment-resistant cases |
196
+
197
+ #### Medical Knowledge Base
198
+
199
+ - **15 Worsening Factors** with severity scores, mechanisms, and neurotransmitter impacts
200
+ - **EULAR 2016 Recommendations** β€” Strong FOR, Weak FOR, Strong AGAINST
201
+ - **German S3 & UK NICE Guidelines** β€” First-line treatments, contraindications
202
+ - **Differential Diagnosis** β€” Lyme, hypothyroidism, vitamin D deficiency, ACR 2016 criteria
203
+ - **Medication Database** β€” EU/FDA approval status, response rates, contraindications
204
+
205
+ #### Automatic Factor Detection
206
+
207
+ The system detects worsening factors mentioned in your messages:
208
+
209
+ ```
210
+ User: "I can't sleep and I'm very stressed lately"
211
+
212
+ Detected Factors:
213
+ - sleep_deprivation (sleep, insomnia keywords)
214
+ - hpa_axis_dysregulation (stress, anxiety keywords)
215
+
216
+ β†’ Enhanced response with relevant coping strategies
217
+ ```
218
+
219
+ ### 🌍 Multi-Language Support
220
+
221
+ Full internationalization with 21 supported languages.
222
+
223
+ | Region | Languages |
224
+ |--------|-----------|
225
+ | **Europe** | English (US/UK), Polish, German, Spanish, French, Italian, Dutch, Portuguese, Swedish, Norwegian, Danish |
226
+ | **Asia** | Japanese, Korean, Chinese, Thai, Indonesian, Hindi |
227
+ | **Middle East** | Arabic, Hebrew, Turkish |
228
+
229
+ **Features:**
230
+ - Language selector in the UI sidebar
231
+ - All UI elements fully translated
232
+ - Automatic fallback to English for missing translations
233
+ - Easy to add new languages via JSON translation files
234
+
235
+ ### 🎨 Premium Design
236
+
237
+ Art Deco-inspired healthcare aesthetic that's both beautiful and functional.
238
+
239
+ | Design Element | Details |
240
+ |----------------|---------|
241
+ | **Primary Color** | Deep Crimson `#8B0000` β€” trust, medical seriousness |
242
+ | **Accent Color** | Warm Gold `#D4AF37` β€” premium, hopeful |
243
+ | **Background** | Ivory/Pearl `#FEFEFE` β€” clean, calming |
244
+ | **Typography** | Playfair Display (headings) + DM Sans (body) |
245
+ | **Accessibility** | WCAG AA compliant, high contrast for tired eyes |
246
+
247
+ ---
248
+
249
+ ## πŸ› οΈ Tech Stack
250
+
251
+ ### Core Technologies
252
+
253
+ | Component | Technology | Version | Purpose |
254
+ |-----------|------------|---------|---------|
255
+ | **Runtime** | Python | 3.10+ | Core programming language |
256
+ | **Web Framework** | Gradio | 6.0+ | Modern UI with messages format |
257
+ | **AI Provider** | OpenRouter | - | LLM API gateway |
258
+ | **AI Model** | Claude Sonnet 4 | Latest | Empathetic, intelligent responses |
259
+ | **Validation** | Pydantic | 2.11+ | Type-safe data models |
260
+ | **Configuration** | pydantic-settings | 2.7+ | Environment management |
261
+ | **Medical Standards** | HL7 FHIR R4 | - | Interoperable patient data |
262
+
263
+ ### Document Processing
264
+
265
+ | Library | Purpose |
266
+ |---------|---------|
267
+ | **PyMuPDF (fitz)** | PDF text extraction |
268
+ | **python-docx** | Word document parsing |
269
+ | **pandas** | CSV/Excel data analysis |
270
+ | **openpyxl** | Excel XLSX support |
271
+ | **xlrd** | Legacy XLS support |
272
+
273
+ ### Development Tools
274
+
275
+ | Tool | Purpose |
276
+ |------|---------|
277
+ | **pytest** | Testing framework |
278
+ | **pytest-asyncio** | Async test support |
279
+ | **black** | Code formatting |
280
+ | **ruff** | Fast Python linter |
281
+ | **mypy** | Static type checking |
282
+ | **loguru** | Beautiful logging |
283
+
284
+ ### Dependencies Overview
285
+
286
+ ```txt
287
+ # Core Framework
288
+ gradio>=6.0.0
289
+ openai>=1.54.0
290
+ pydantic>=2.11.0
291
+ pydantic-settings>=2.7.0
292
+
293
+ # Document Processing
294
+ PyMuPDF>=1.24.0
295
+ python-docx>=1.1.0
296
+ pandas>=2.2.0
297
+
298
+ # Development
299
+ pytest>=8.3.0
300
+ black>=24.10.0
301
+ ruff>=0.8.0
302
+ ```
303
+
304
+ ---
305
+
306
+ ## πŸ—οΈ Architecture
307
+
308
+ ### System Overview
309
+
310
+ ```
311
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
312
+ β”‚ USER INTERFACE β”‚
313
+ β”‚ (Gradio 6.0 Web App) β”‚
314
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
315
+ β”‚ Chat UI β”‚ Medication UI β”‚ File Upload β”‚ Quick Actionsβ”‚
316
+ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
317
+ β”‚ β”‚ β”‚ β”‚
318
+ β–Ό β–Ό β–Ό β–Ό
319
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
320
+ β”‚ APPLICATION LAYER β”‚
321
+ β”‚ (app/main.py) β”‚
322
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
323
+ β”‚ ChatHandler β”‚ MedicationReminderβ”‚ FileProcessor β”‚
324
+ β”‚ (chat.py) β”‚ (reminders.py) β”‚ (main.py) β”‚
325
+ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
326
+ β”‚ β”‚
327
+ β–Ό β–Ό
328
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
329
+ β”‚ CORE SERVICES β”‚
330
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
331
+ β”‚ LLMAgent β”‚ Data Models β”‚
332
+ β”‚ (agents.py) β”‚ (schemas.py) β”‚
333
+ β”‚ β”‚ β”‚
334
+ β”‚ β€’ Async OpenAI SDK β”‚ β€’ Medication / MedicationLog β”‚
335
+ β”‚ β€’ Streaming support β”‚ β€’ ConversationSession β”‚
336
+ β”‚ β€’ Error handling β”‚ β€’ MedicationState β”‚
337
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
338
+ β”‚
339
+ β–Ό
340
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
341
+ β”‚ EXTERNAL SERVICES β”‚
342
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
343
+ β”‚ OpenRouter API β”‚
344
+ β”‚ (anthropic/claude-sonnet-4) β”‚
345
+ β”‚ β”‚
346
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
347
+ β”‚ β”‚ HTTP/HTTPS + Streaming SSE β”‚ β”‚
348
+ β”‚ β”‚ β€’ Max 4096 tokens β”‚ β”‚
349
+ β”‚ β”‚ β€’ Temperature 0.7 β”‚ β”‚
350
+ β”‚ β”‚ β€’ Async with httpx β”‚ β”‚
351
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
352
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
353
+ ```
354
+
355
+ ### Component Details
356
+
357
+ #### 1. Main Interface (`app/main.py`)
358
+ - Creates Gradio 6 Blocks interface
359
+ - Handles file upload and processing
360
+ - Coordinates chat and medication features
361
+ - Injects custom CSS styling
362
+
363
+ #### 2. Chat Handler (`app/chat.py`)
364
+ - Manages conversation sessions
365
+ - Converts between Gradio 6 messages format and OpenAI API
366
+ - Handles streaming and non-streaming responses
367
+ - **Detects worsening factors** in user messages
368
+ - **Enhances system prompts** with medical context
369
+ - **Caches medical context** for performance (60s TTL)
370
+
371
+ #### 3. LLM Agent (`app/llm_agent.py`)
372
+ - Async OpenAI SDK client for OpenRouter
373
+ - Loads system prompt from file
374
+ - Implements retry logic and error handling
375
+ - Supports both streaming and batch responses
376
+
377
+ #### 4. Medical Intelligence Services (`app/services/`)
378
+
379
+ | Service | Purpose |
380
+ |---------|---------|
381
+ | **AdaptiveReasoningRouter** | Routes queries to parallel/sequential/deep modes based on complexity |
382
+ | **MedicalKnowledgeService** | 8 query methods for features, guidelines, differential diagnosis |
383
+ | **EUGuidelinesValidator** | Validates against EULAR 2016, German S3, UK NICE guidelines |
384
+
385
+ #### 5. Multi-Agent System (`app/agents/`)
386
+
387
+ | Agent | Role |
388
+ |-------|------|
389
+ | **FibroAgentCouncil** | Orchestrates specialized agents with consensus synthesis |
390
+ | **SymptomAnalyzer** | Analyzes symptom patterns and severity |
391
+ | **TherapyExpert** | Recommends evidence-based treatments |
392
+ | **LifestyleCoach** | Provides pacing and lifestyle strategies |
393
+ | **RiskAssessor** | Evaluates safety and recommends escalation |
394
+
395
+ **Exploration Strategies:**
396
+ - **Parallel Consensus** β€” All agents run simultaneously for routine queries
397
+ - **Deep Sequential with Backtracking** β€” DFS-style hypothesis exploration for complex cases
398
+
399
+ #### 6. FHIR Patient Profile (`app/schemas/patient.py`)
400
+ - HL7 FHIR R4 compliant patient resource
401
+ - **WPI** (Widespread Pain Index) 0-19
402
+ - **SSS** (Symptom Severity Score) 0-12
403
+ - **ACR 2016 criteria** automatic calculation
404
+ - **PHI masking** for privacy protection
405
+
406
+ #### 7. Medication Reminder (`app/reminders.py`)
407
+ - In-memory medication state management
408
+ - LLM command parsing (`[MEDICATION_CMD: ...]`)
409
+ - Adherence tracking and statistics
410
+ - Pending reminder detection
411
+ - **Missed dose detection** (after 4 AM daily check)
412
+ - Actions: mark taken late, register missed, dismiss
413
+
414
+ #### 8. Appointment Reminder (`app/appointments.py`)
415
+ - Doctor appointment scheduling and tracking
416
+ - Specialty-based categorization
417
+ - Day-before reminder system
418
+ - Status indicators (Today, Soon, Upcoming, Past)
419
+ - LLM command parsing (`[APPOINTMENT_CMD: ...]`)
420
+
421
+ #### 9. Internationalization (`app/i18n.py`)
422
+ - 21 supported languages with JSON translation files
423
+ - Dynamic language switching at runtime
424
+ - Nested key access with dot notation
425
+ - Automatic fallback to English
426
+ - `UIStrings` class for type-safe UI text access
427
+
428
+ #### 10. Configuration (`app/config.py`)
429
+ - Pydantic Settings with validation
430
+ - Environment variable loading
431
+ - Type-safe configuration access
432
+ - Default language setting
433
+
434
+ #### 11. Data Models (`models/schemas.py`)
435
+ - Pydantic 2.11 models
436
+ - Gradio 6 messages format support
437
+ - Medication and logging schemas
438
+
439
+ ### Directory Structure
440
+
441
+ ```
442
+ hellofibro/
443
+ β”œβ”€β”€ app/ # Application code
444
+ β”‚ β”œβ”€β”€ __init__.py
445
+ β”‚ β”œβ”€β”€ main.py # Gradio interface + file processing
446
+ β”‚ β”œβ”€β”€ config.py # Pydantic settings
447
+ β”‚ β”œβ”€β”€ llm_agent.py # LLM agent (OpenRouter)
448
+ β”‚ β”œβ”€β”€ chat.py # Chat session management + medical context
449
+ β”‚ β”œβ”€β”€ prompts.py # LLM prompts and file hints
450
+ β”‚ β”œβ”€β”€ i18n.py # Internationalization service (21 languages)
451
+ β”‚ β”œβ”€β”€ security.py # Input sanitization + HIPAA audit
452
+ β”‚ β”œβ”€β”€ reminders.py # Medication system
453
+ β”‚ β”œβ”€β”€ appointments.py # Appointment management
454
+ β”‚ β”‚
455
+ β”‚ β”œβ”€β”€ agents/ # πŸ†• Multi-agent system
456
+ β”‚ β”‚ β”œβ”€β”€ __init__.py
457
+ β”‚ β”‚ └── council.py # FibroAgentCouncil with backtracking
458
+ β”‚ β”‚
459
+ β”‚ β”œβ”€β”€ schemas/ # πŸ†• Medical data schemas
460
+ β”‚ β”‚ β”œβ”€β”€ __init__.py
461
+ β”‚ β”‚ └── patient.py # FHIR R4 patient profile + ACR 2016
462
+ β”‚ β”‚
463
+ β”‚ └── services/ # πŸ†• Medical intelligence services
464
+ β”‚ β”œβ”€β”€ __init__.py
465
+ β”‚ β”œβ”€β”€ reasoning_router.py # Adaptive chain-of-thought scaling
466
+ β”‚ β”œβ”€β”€ medical_knowledge.py # Knowledge base queries
467
+ β”‚ └── eu_guidelines_validator.py # EULAR/S3/NICE compliance
468
+ β”‚
469
+ β”œβ”€β”€ models/ # Data models
470
+ β”‚ β”œβ”€β”€ __init__.py
471
+ β”‚ └── schemas.py # Pydantic schemas
472
+ β”‚
473
+ β”œβ”€β”€ data/ # Static data
474
+ β”‚ β”œβ”€β”€ prompts/
475
+ β”‚ β”‚ └── system_prompt.txt # AI personality definition
476
+ β”‚ β”œβ”€β”€ translations/ # UI translations (21 languages)
477
+ β”‚ β”‚ β”œβ”€β”€ en-US.json # English (US)
478
+ β”‚ β”‚ β”œβ”€β”€ pl.json # Polish
479
+ β”‚ β”‚ β”œβ”€β”€ de.json # German
480
+ β”‚ β”‚ └── ... # 18 more languages
481
+ β”‚ β”œβ”€β”€ features.json # 15 worsening factors
482
+ β”‚ β”œβ”€β”€ metrics.json # 8 evaluation metrics
483
+ β”‚ β”œβ”€β”€ guidelines.json # EU clinical guidelines
484
+ β”‚ └── reasoning_config.json # Reasoning mode configuration
485
+ β”‚
486
+ β”œβ”€β”€ static/ # Web assets
487
+ β”‚ β”œβ”€β”€ logo.png # App logo
488
+ β”‚ └── custom.css # Premium styling (1100+ lines)
489
+ β”‚
490
+ β”œβ”€β”€ resources/ # Design resources
491
+ β”‚ β”œβ”€β”€ hellofibro_logo.png # Original logo
492
+ β”‚ β”œβ”€β”€ style.css # Reference styles
493
+ β”‚ └── hellofibro-gradio6-modern.md
494
+ β”‚
495
+ β”œβ”€β”€ tests/ # Test suite
496
+ β”‚ β”œβ”€β”€ __init__.py
497
+ β”‚ β”œβ”€β”€ conftest.py # Pytest fixtures (incl. medical)
498
+ β”‚ β”œβ”€β”€ test_chat.py # Chat tests
499
+ β”‚ β”œβ”€β”€ test_agents.py # Agent tests
500
+ β”‚ β”œβ”€β”€ test_reminders.py # Medication tests
501
+ β”‚ β”œβ”€β”€ test_missed_doses.py # Missed dose notification tests
502
+ β”‚ β”œβ”€β”€ test_config.py # Config tests
503
+ β”‚ β”œβ”€β”€ test_e2e.py # End-to-end tests
504
+ β”‚ β”œβ”€β”€ test_medical_layer.py # πŸ†• Medical services unit tests
505
+ β”‚ └── test_medical_integration.py # πŸ†• Medical integration tests
506
+ β”‚
507
+ β”œβ”€β”€ .env # Environment config (create this)
508
+ β”œβ”€β”€ .env.example # Example environment file
509
+ β”œβ”€β”€ requirements.txt # Python dependencies
510
+ β”œβ”€β”€ Makefile # Development commands
511
+ β”œβ”€β”€ Dockerfile # Container definition
512
+ β”œβ”€β”€ docker-compose.yml # Container orchestration
513
+ β”œβ”€β”€ pyproject.toml # Project metadata
514
+ β”œβ”€β”€ BRANDING_GUIDE.md # Design system documentation
515
+ β”œβ”€β”€ IMPLEMENTATION_PLAN.md # Development roadmap
516
+ └── README.md # This file
517
+ ```
518
+
519
+ ---
520
+
521
+ ## πŸ”„ Workflows
522
+
523
+ ### Chat Conversation Flow
524
+
525
+ ```
526
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
527
+ β”‚ User β”‚ β”‚ Gradio UI β”‚ β”‚ ChatHandler β”‚
528
+ β”‚ Input │─────▢│ (main.py) │─────▢│ (chat.py) β”‚
529
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
530
+ β”‚
531
+ β–Ό
532
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
533
+ β”‚ Streaming │◀─────│ LLMAgent │◀─────│ Session β”‚
534
+ β”‚ Response β”‚ β”‚ (agents.py) β”‚ β”‚ History β”‚
535
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
536
+ β”‚
537
+ β–Ό
538
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
539
+ β”‚ OpenRouter β”‚
540
+ β”‚ Claude API β”‚
541
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
542
+ ```
543
+
544
+ **Step-by-step:**
545
+
546
+ 1. **User Input** β†’ User types message + optional file upload
547
+ 2. **File Processing** β†’ Extract text from PDF/DOCX/CSV/images
548
+ 3. **Context Building** β†’ Add medication/appointment context + file hints
549
+ 4. **Session Management** β†’ Retrieve/create conversation session
550
+ 5. **LLM Request** β†’ Send to Claude via OpenRouter with streaming
551
+ 6. **Response Processing** β†’ Extract medication commands, clean response
552
+ 7. **UI Update** β†’ Stream response to chat interface
553
+
554
+ ### Medication Management Flow
555
+
556
+ ```
557
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
558
+ β”‚ USER ACTIONS β”‚
559
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
560
+ β”‚ "Dodaj lek β”‚ Click "Add β”‚ Click "Take" β”‚ "WziΔ…Ε‚em β”‚
561
+ β”‚ X 100mg" β”‚ Medication" β”‚ Button β”‚ pregabalinΔ™" β”‚
562
+ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
563
+ β”‚ β”‚ β”‚ β”‚
564
+ β–Ό β–Ό β–Ό β–Ό
565
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
566
+ β”‚ PROCESSING LAYER β”‚
567
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
568
+ β”‚ LLM generates: β”‚ Direct UI Handler: β”‚
569
+ β”‚ [MEDICATION_CMD: β”‚ add_medication_ui() β”‚
570
+ β”‚ ADD: X|100mg|...] β”‚ mark_taken_ui() β”‚
571
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
572
+ β”‚ β”‚
573
+ β–Ό β–Ό
574
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
575
+ β”‚ MedicationReminder (reminders.py) β”‚
576
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
577
+ β”‚ β€’ add_medication() β€’ mark_taken() β”‚
578
+ β”‚ β€’ remove_medication() β€’ get_medications_for_display() β”‚
579
+ β”‚ β€’ get_today_status() β€’ process_llm_medication_command() β”‚
580
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
581
+ β”‚
582
+ β–Ό
583
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
584
+ β”‚ MedicationState β”‚
585
+ β”‚ (In-memory storage with Pydantic models) β”‚
586
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
587
+ ```
588
+
589
+ **LLM Command Format:**
590
+
591
+ ```python
592
+ # Adding medication via chat
593
+ [MEDICATION_CMD: ADD: Pregabalina|150mg|21:00|wieczorem|na bΓ³l neuropatyczny]
594
+
595
+ # Removing medication
596
+ [MEDICATION_CMD: REMOVE: Pregabalina]
597
+
598
+ # Marking as taken
599
+ [MEDICATION_CMD: TAKEN: Pregabalina]
600
+
601
+ # Listing all medications
602
+ [MEDICATION_CMD: LIST:]
603
+ ```
604
+
605
+ ### Appointment Management Flow
606
+
607
+ ```
608
+ +---------------+ +------------------+ +-------------------+
609
+ | USER ACTIONS | | PROCESSING LAYER | | AppointmentReminder|
610
+ +---------------+ +------------------+ +-------------------+
611
+ | | |
612
+ v v v
613
+ "Add visit" LLM generates: add_appointment()
614
+ Click Form [APPOINTMENT_CMD: ADD: ...] get_appointments()
615
+ Click Card OR remove_appointment()
616
+ | Direct UI Handler |
617
+ +--------->----------------------->---------------+
618
+ |
619
+ v
620
+ +-------------------+
621
+ | AppointmentState |
622
+ | (In-memory) |
623
+ +-------------------+
624
+ ```
625
+
626
+ **LLM Command Format:**
627
+
628
+ ```python
629
+ # Adding appointment via chat
630
+ [APPOINTMENT_CMD: ADD: Dr. Smith|Rheumatologist|2025-01-15|10:00|ABC Clinic|bring test results]
631
+
632
+ # Removing appointment
633
+ [APPOINTMENT_CMD: REMOVE: Dr. Smith]
634
+
635
+ # Listing all appointments
636
+ [APPOINTMENT_CMD: LIST:]
637
+ ```
638
+
639
+ ### File Processing Flow
640
+
641
+ ```
642
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
643
+ β”‚ File Upload │─────▢│ process_uploaded │─────▢│ Type Check β”‚
644
+ β”‚ (User) β”‚ β”‚ _file() β”‚ β”‚ & Validate β”‚
645
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
646
+ β”‚
647
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
648
+ β”‚ β”‚ β”‚
649
+ β–Ό β–Ό β–Ό
650
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
651
+ β”‚ PDF (fitz) β”‚ β”‚ DOCX/DOC β”‚ β”‚ CSV/XLSX β”‚
652
+ β”‚ extract_pdf β”‚ β”‚ extract_docxβ”‚ β”‚ pandas read β”‚
653
+ β”‚ _text() β”‚ β”‚ _text() β”‚ β”‚ β”‚
654
+ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
655
+ β”‚ β”‚ β”‚
656
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
657
+ β”‚
658
+ β–Ό
659
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
660
+ β”‚ Content + Hint β”‚
661
+ β”‚ for LLM Context β”‚
662
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
663
+ β”‚
664
+ β–Ό
665
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
666
+ β”‚ Enhanced Chat β”‚
667
+ β”‚ Message β”‚
668
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
669
+ ```
670
+
671
+ **Supported File Processing:**
672
+
673
+ | Type | Library | Max Size | Features |
674
+ |------|---------|----------|----------|
675
+ | PDF | PyMuPDF | 15MB | Multi-page, page markers |
676
+ | DOCX | python-docx | 15MB | Paragraphs + tables |
677
+ | XLSX/XLS | pandas + openpyxl | 15MB | Multi-sheet, statistics |
678
+ | CSV | pandas | 15MB | Headers, stats preview |
679
+ | TXT/MD/JSON | Built-in | 50KB | UTF-8 with fallback |
680
+ | Images | Base64 | 15MB | Vision model support |
681
+
682
+ ---
683
+
684
+ ## πŸš€ Quick Start
685
+
686
+ ### Prerequisites
687
+
688
+ - **Python 3.10+** installed
689
+ - **OpenRouter API key** ([Get one here](https://openrouter.ai))
690
+
691
+ ### Installation
692
+
693
+ ```bash
694
+ # 1. Clone the repository
695
+ git clone https://github.com/hellofibro/hellofibro.git
696
+ cd hellofibro
697
+
698
+ # 2. Create virtual environment
699
+ python -m venv venv
700
+
701
+ # Windows
702
+ .\venv\Scripts\activate
703
+
704
+ # macOS/Linux
705
+ source venv/bin/activate
706
+
707
+ # 3. Install dependencies
708
+ pip install -r requirements.txt
709
+
710
+ # 4. Create environment file
711
+ cp .env.example .env
712
+ # Edit .env and add your OPENROUTER_API_KEY
713
+
714
+ # 5. Run the application
715
+ python -m app.main
716
+ ```
717
+
718
+ ### Using Docker
719
+
720
+ ```bash
721
+ # Build and run with Docker Compose
722
+ docker-compose up --build -d
723
+
724
+ # View logs
725
+ docker-compose logs -f
726
+
727
+ # Stop the container
728
+ docker-compose down
729
+ ```
730
+
731
+ **Container Status:**
732
+ ```
733
+ NAME IMAGE STATUS PORTS
734
+ hellofibro hellofibro-hellofibro Up (running) 0.0.0.0:7860->7860/tcp
735
+ ```
736
+
737
+ **With API Key (Production):**
738
+
739
+ ```bash
740
+ # Windows PowerShell
741
+ $env:OPENROUTER_API_KEY="sk-or-v1-your-key-here"
742
+ docker-compose up -d
743
+
744
+ # Linux/macOS
745
+ export OPENROUTER_API_KEY="sk-or-v1-your-key-here"
746
+ docker-compose up -d
747
+
748
+ # Or create .env file first
749
+ echo "OPENROUTER_API_KEY=sk-or-v1-your-key-here" > .env
750
+ docker-compose up -d
751
+ ```
752
+
753
+ **Demo Mode (No API Key):**
754
+
755
+ Without an API key, the app runs in demo mode with pre-defined responses:
756
+
757
+ ```bash
758
+ docker-compose up -d
759
+ # Logs will show: "Running in DEMO MODE - API calls disabled"
760
+ ```
761
+
762
+ **Manual Docker Build:**
763
+
764
+ ```bash
765
+ # Build image
766
+ docker build -t hellofibro .
767
+
768
+ # Run with environment variable
769
+ docker run -p 7860:7860 -e OPENROUTER_API_KEY=sk-or-v1-xxx hellofibro
770
+
771
+ # Or with .env file
772
+ docker run -p 7860:7860 --env-file .env hellofibro
773
+ ```
774
+
775
+ **Docker Compose Configuration:**
776
+
777
+ The `docker-compose.yml` includes:
778
+ - Health checks (every 30s)
779
+ - Resource limits (2 CPU, 2GB RAM)
780
+ - Automatic restart policy
781
+ - Environment variable passthrough
782
+
783
+ ### Using Make (Recommended)
784
+
785
+ ```bash
786
+ make setup # Create venv + install dependencies
787
+ make run # Start the application
788
+ make test # Run all tests
789
+ make lint # Check code quality
790
+ make format # Format code with black
791
+ make clean # Remove cache files
792
+ ```
793
+
794
+ ### Access the App
795
+
796
+ ```
797
+ 🌐 Open http://localhost:7860 in your browser
798
+ ```
799
+
800
+ ---
801
+
802
+ ## βš™οΈ Configuration
803
+
804
+ Create a `.env` file in the project root:
805
+
806
+ ```env
807
+ # Required - Your OpenRouter API key
808
+ OPENROUTER_API_KEY=sk-or-v1-your-api-key-here
809
+
810
+ # Optional - Model selection (defaults shown)
811
+ OPENROUTER_MODEL=anthropic/claude-sonnet-4
812
+ OPENROUTER_BASE_URL=https://openrouter.ai/api/v1
813
+
814
+ # Optional - Model parameters
815
+ MODEL_MAX_TOKENS=4096
816
+ MODEL_TEMPERATURE=0.7
817
+
818
+ # Optional - Application settings
819
+ APP_TITLE=HelloFibro
820
+ APP_HOST=0.0.0.0
821
+ APP_PORT=7860
822
+
823
+ # Optional - Feature flags
824
+ DEBUG_MODE=false # Set to true to test missed dose notifications anytime
825
+ STREAM_RESPONSES=true
826
+ LOG_LEVEL=INFO
827
+
828
+ # Optional - Internationalization
829
+ DEFAULT_LANGUAGE=pl # Default UI language (pl, en-US, de, es, fr, etc.)
830
+ ```
831
+
832
+ ### Supported Languages
833
+
834
+ | Code | Language | Native Name |
835
+ |------|----------|-------------|
836
+ | `en-US` | English (US) | English (US) |
837
+ | `en-GB` | English (UK) | English (UK) |
838
+ | `pl` | Polish | Polski |
839
+ | `de` | German | Deutsch |
840
+ | `es` | Spanish | Espanol |
841
+ | `fr` | French | Francais |
842
+ | `it` | Italian | Italiano |
843
+ | `nl` | Dutch | Nederlands |
844
+ | `pt` | Portuguese | Portugues |
845
+ | `sv` | Swedish | Svenska |
846
+ | `no` | Norwegian | Norsk |
847
+ | `da` | Danish | Dansk |
848
+ | `ja` | Japanese | Nihongo |
849
+ | `ko` | Korean | Hangugeo |
850
+ | `zh` | Chinese | Zhongwen |
851
+ | `ar` | Arabic | Al-Arabiyyah |
852
+ | `he` | Hebrew | Ivrit |
853
+ | `hi` | Hindi | Hindi |
854
+ | `th` | Thai | Phasa Thai |
855
+ | `tr` | Turkish | Turkce |
856
+ | `id` | Indonesian | Bahasa Indonesia |
857
+
858
+ ### Supported Models
859
+
860
+ Any OpenRouter-compatible model works. Recommended options:
861
+
862
+ | Model | ID | Best For |
863
+ |-------|-----|----------|
864
+ | **Claude Sonnet 4** | `anthropic/claude-sonnet-4` | Best quality (default) |
865
+ | **Claude 3.5 Sonnet** | `anthropic/claude-3.5-sonnet` | Fast, excellent |
866
+ | **GPT-4o** | `openai/gpt-4o` | Alternative |
867
+ | **Claude 3 Haiku** | `anthropic/claude-3-haiku` | Budget-friendly |
868
+
869
+ ---
870
+
871
+ ## πŸ§ͺ Testing
872
+
873
+ ```bash
874
+ # Run all tests
875
+ pytest tests/ -v
876
+
877
+ # Run with coverage
878
+ pytest tests/ --cov=app --cov=models
879
+
880
+ # Run specific test file
881
+ pytest tests/test_chat.py -v
882
+
883
+ # Run async tests only
884
+ pytest tests/ -v -k "async"
885
+ ```
886
+
887
+ ### Test Categories
888
+
889
+ | File | Tests |
890
+ |------|-------|
891
+ | `test_config.py` | Settings validation, API key format |
892
+ | `test_agents.py` | LLM agent, streaming, error handling |
893
+ | `test_chat.py` | Session management, message processing |
894
+ | `test_reminders.py` | Medication CRUD, logging, commands |
895
+ | `test_missed_doses.py` | Missed dose detection, actions |
896
+ | `test_language_selection.py` | i18n service, language switching |
897
+ | `test_e2e.py` | End-to-end integration tests |
898
+ | `test_medical_layer.py` | Medical services unit tests |
899
+ | `test_medical_integration.py` | End-to-end medical integration |
900
+
901
+ ### Medical Intelligence Tests
902
+
903
+ ```bash
904
+ # Run medical layer tests specifically
905
+ pytest tests/test_medical_layer.py -v
906
+ pytest tests/test_medical_integration.py -v
907
+
908
+ # Run all tests including medical
909
+ pytest tests/ -v --tb=short
910
+ ```
911
+
912
+ **Tested Components:**
913
+ - MedicalKnowledgeService queries (features, guidelines, differential)
914
+ - EUGuidelinesValidator (therapy validation, contraindications)
915
+ - AdaptiveReasoningRouter (complexity assessment, mode routing)
916
+ - FibroPatientProfile (ACR 2016, PHI masking, FHIR export)
917
+ - ChatHandler medical context integration
918
+ - FibroAgentCouncil parallel/deep modes
919
+
920
+ ---
921
+
922
+ ## πŸ”’ Security & Privacy
923
+
924
+ HelloFibro is designed with privacy as a core principle:
925
+
926
+ | Aspect | Implementation |
927
+ |--------|----------------|
928
+ | **Data Storage** | Session-only, in-memory (no persistence) |
929
+ | **API Keys** | Stored in `.env`, never logged or transmitted |
930
+ | **User Data** | Not stored, not tracked, not shared |
931
+ | **Conversations** | Cleared on session end |
932
+ | **Medications** | In-memory only (MVP) |
933
+ | **File Uploads** | Processed in memory, not stored |
934
+ | **PHI Protection** | πŸ†• FHIR patient profiles support PHI masking |
935
+ | **Medical Data** | πŸ†• No patient data persisted, session-only |
936
+
937
+ ### Important Notes
938
+
939
+ - βœ… HTTPS recommended for production
940
+ - βœ… API key validation at startup
941
+ - βœ… No PII collection or storage
942
+ - ⚠️ Future versions may add optional persistence with encryption
943
+
944
+ ---
945
+
946
+ ## ⚠️ Medical Disclaimer
947
+
948
+ > **HelloFibro is NOT a substitute for professional medical advice.**
949
+
950
+ This AI assistant provides general support and information only:
951
+
952
+ | ❌ HelloFibro Does NOT | βœ… HelloFibro Does |
953
+ |------------------------|-------------------|
954
+ | Diagnose conditions | Provide emotional support |
955
+ | Prescribe medications | Track prescribed medications |
956
+ | Replace healthcare providers | Help prepare for doctor visits |
957
+ | Provide emergency advice | Offer coping strategies |
958
+ | Make treatment decisions | Share general fibromyalgia info |
959
+ | Provide dosage advice | Reference EULAR/S3/NICE guidelines |
960
+
961
+ ### Clinical Guidelines Compliance
962
+
963
+ HelloFibro references established clinical guidelines for informational purposes:
964
+
965
+ | Guideline | Year | Scope |
966
+ |-----------|------|-------|
967
+ | **EULAR 2016** | 2016 | European League Against Rheumatism |
968
+ | **German S3** | 2017 | German Association of Scientific Medical Societies |
969
+ | **UK NICE** | 2021 | UK National Institute for Health and Care Excellence |
970
+ | **ACR 2016** | 2016 | American College of Rheumatology diagnostic criteria |
971
+
972
+ **Always consult qualified healthcare professionals for medical decisions.**
973
+
974
+ ---
975
+
976
+ ## 🀝 Contributing
977
+
978
+ Contributions are welcome! Please follow these guidelines:
979
+
980
+ ### Development Setup
981
+
982
+ ```bash
983
+ # 1. Fork and clone
984
+ git clone https://github.com/YOUR_USERNAME/hellofibro.git
985
+ cd hellofibro
986
+
987
+ # 2. Create branch
988
+ git checkout -b feature/your-feature
989
+
990
+ # 3. Install dev dependencies
991
+ pip install -r requirements.txt
992
+
993
+ # 4. Make changes and test
994
+ make test
995
+ make lint
996
+
997
+ # 5. Format code
998
+ make format
999
+
1000
+ # 6. Commit and push
1001
+ git commit -m "feat: add amazing feature"
1002
+ git push origin feature/your-feature
1003
+
1004
+ # 7. Open Pull Request
1005
+ ```
1006
+
1007
+ ### Code Style
1008
+
1009
+ - **Formatting**: Black (line length 88)
1010
+ - **Linting**: Ruff
1011
+ - **Type Hints**: Required for all functions
1012
+ - **Docstrings**: Required for public APIs
1013
+
1014
+ ### Commit Messages
1015
+
1016
+ Follow [Conventional Commits](https://www.conventionalcommits.org/):
1017
+
1018
+ ```
1019
+ feat: add new medication reminder feature
1020
+ fix: resolve chat history persistence issue
1021
+ docs: update README with architecture diagram
1022
+ style: format code with black
1023
+ refactor: extract file processing to separate module
1024
+ test: add tests for medication commands
1025
+ ```
1026
+
1027
+ ---
1028
+
1029
+ ## πŸ“œ License
1030
+
1031
+ This project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.
1032
+
1033
+ ---
1034
+
1035
+ ## πŸ’œ Acknowledgments
1036
+
1037
+ - Built with love for the fibromyalgia community πŸ’œ
1038
+ - AI powered by [Anthropic Claude](https://anthropic.com) via [OpenRouter](https://openrouter.ai)
1039
+ - UI framework by [Gradio](https://gradio.app)
1040
+ - Inspired by the strength and resilience of fibromyalgia warriors
1041
+
1042
+ ---
1043
+
1044
+
1045
+ <div align="center">
1046
+
1047
+ ### πŸ’œ Made with empathy for warriors living with fibromyalgia
1048
+
1049
+ *Your experience is valid. You are not alone. Your strength inspires us.*
1050
+
1051
+ ---
1052
+
1053
+ **[⬆ Back to Top](#-hellofibro)**
1054
+
1055
+ </div>