Benedette commited on
Commit
058e623
·
1 Parent(s): 20219ae

initial commit

Browse files
Files changed (1) hide show
  1. README.md +4 -251
README.md CHANGED
@@ -1,259 +1,12 @@
1
  ---
2
  title: Ebola Case Detection
3
- colorFrom: red
4
- colorTo: yellow
 
5
  sdk: gradio
6
  sdk_version: 6.16.0
7
  app_file: app.py
8
  pinned: false
9
- python_version: "3.11"
10
  ---
11
 
12
- # Ebola Virus Disease Clinical Screening AI Agent
13
-
14
- Production-ready adaptive EVD screening agent for healthcare workers, built with Python, Pydantic, an LLM-driven reasoning layer, LangGraph, and Gradio.
15
-
16
- This agent performs dynamic clinical interviewing and classifies:
17
-
18
- - No Case
19
- - Suspected Case
20
- - Probable Case
21
-
22
- It does not classify Confirmed Case (laboratory confirmation is intentionally out of scope).
23
-
24
- ## 1) Solution Architecture
25
-
26
- ### Layer 1: Conversation Manager
27
- - Maintains session memory and full conversation history.
28
- - Tracks already asked questions and pending question.
29
- - Applies one-turn clinician input and returns one-turn agent output.
30
-
31
- ### Layer 2: LLM Clinical Reasoning Agent
32
- - Uses an LLM to summarize known evidence, identify missing evidence, extract structured facts, and choose the next best single question.
33
- - Adapts questioning dynamically to symptoms, travel, exposure, and epidemiological context.
34
- - Stops questioning when the model determines sufficient evidence has been gathered.
35
-
36
- ### Layer 3: Epidemiological Context Engine
37
- - Loads configurable outbreak context from JSON.
38
- - Computes proximity/context risk modifier from district, neighboring outbreaks, and alerts.
39
- - Prioritizes exposure questions earlier in high-risk context.
40
-
41
- ### Layer 4: Explainability Module
42
- - Generates structured, auditable rationale:
43
- - Classification
44
- - Evidence collected
45
- - Criteria/definition match explanation
46
- - Recommended action
47
-
48
- ## 2) Folder Structure
49
-
50
- ```text
51
- .
52
- ├── app.py
53
- ├── requirements.txt
54
- ├── data/
55
- │ └── epi_context.sample.json
56
- ├── evd_agent/
57
- │ ├── __init__.py
58
- │ ├── config.py
59
- │ ├── context_engine.py
60
- │ ├── conversation.py
61
- │ ├── explainability.py
62
- │ ├── graph.py
63
- │ ├── llm_client.py
64
- │ ├── models.py
65
- │ └── reasoning.py
66
- └── tests/
67
- └──
68
- ```
69
-
70
- ## 3) Data Models
71
-
72
- Implemented with Pydantic in `evd_agent/models.py`:
73
-
74
- - `PatientFacts`: structured interview variables (symptoms, exposure, death, lab availability, location).
75
- - `EpidemiologicalContext`: outbreak metadata and alerts.
76
- - `DecisionOutput`: classification, rule, evidence, action, confidence, stop flag.
77
- - `LLMInterviewPlan`: structured LLM output for evidence summary, fact updates, and next question.
78
- - `InterviewState`: full session state, asked questions, pending question, history.
79
- - `TurnResult`: structured output for each turn.
80
-
81
- ## 4) State Schema
82
-
83
- `InterviewState` fields:
84
-
85
- - `session_id`: unique UUID per session
86
- - `status`: in_progress | complete
87
- - `facts`: patient feature store
88
- - `context`: loaded epidemiological context
89
- - `history`: full clinician/assistant turns
90
- - `asked_questions`: dedup set
91
- - `followup_question_count`: tracks the max 3 follow-up questions rule
92
- - `pending_question_text`: next LLM-generated question
93
- - `decision`: current decision snapshot
94
- - `llm_summary`: latest reasoning summary from the model
95
- - `rationale_log`: extensible audit trail
96
-
97
- ## 5) Agent Workflow Diagram
98
-
99
- ```mermaid
100
- flowchart TD
101
- A[Clinician Input] --> B[Conversation Manager]
102
- B --> D[LLM Reasoning Agent]
103
- D --> E[Structured Fact Updates]
104
- E --> H{Case Definition Met? by LLM + MOH guidance}
105
- H -- Yes --> I[Suspected or Probable]
106
- H -- No --> J[LLM-Generated Next Question]
107
- I --> K[Explainability Module]
108
- J --> K
109
- K --> L[Gradio UI Panels + Chat]
110
- ```
111
-
112
- LangGraph orchestration is implemented in `evd_agent/graph.py` with nodes:
113
- - `ingest_input`
114
- - `llm_reason`
115
- - `compose_response`
116
-
117
- ## 6) Clinical Reasoning Logic
118
-
119
- Clinical decisions are made directly by the LLM using Kenya MOH case definitions plus county context as supplemental situational awareness.
120
- County context influences question priority and concern level but does not independently classify a case.
121
-
122
- ## 7) Clinical Reasoning Workflow
123
-
124
- Suspected case triggers if any:
125
- - Unexplained bleeding.
126
- - Sudden unexplained death.
127
- - Fever >= 38C with at least 3 compatible symptoms.
128
- - Fever >= 38C with qualifying exposure in previous 21 days.
129
-
130
- Probable case triggers when all:
131
- - Deceased,
132
- - Meets suspected criteria,
133
- - Epidemiological linkage to known case,
134
- - Laboratory confirmation unavailable.
135
-
136
- Adaptive questioning behavior:
137
- - One question at a time.
138
- - Stops immediately once suspect/probable criteria are met.
139
- - Uses LLM reasoning to prioritize highest-value unresolved evidence.
140
- - Asks a maximum of 3 follow-up questions when no case definition is met.
141
- - Avoids duplicate questions through state tracking.
142
-
143
- ## 8) Gradio Implementation
144
-
145
- Gradio app in `app.py` includes:
146
- - Chat interface
147
- - Conversation history
148
- - Session memory (`gr.State` with `InterviewState`)
149
- - Classification panel
150
- - Epidemiological context panel
151
- - Alert banner
152
- - Reset button
153
-
154
- ## 9) Deployment Instructions
155
-
156
- ### Deploy to Hugging Face Spaces (Gradio)
157
-
158
- This repository is now Space-ready.
159
-
160
- 1. Create a new Space on Hugging Face:
161
- - Owner: your account or org
162
- - Space SDK: Gradio
163
- - Visibility: public or private
164
- 2. Push this repository to the Space remote:
165
-
166
- ```bash
167
- # Replace with your values
168
- git remote add hf https://huggingface.co/spaces/<username-or-org>/<space-name>
169
- git push hf main
170
- ```
171
-
172
- 3. In the Space settings, add required Secrets:
173
- - `EVD_LLM_API_KEY` (or `OPENAI_API_KEY`)
174
- 4. Optional Space variables/secrets:
175
- - `EVD_LLM_MODEL` (example: `gpt-4.1-mini`)
176
- - `EVD_LLM_BASE_URL` (if using a compatible non-default endpoint)
177
- - `EVD_CONTEXT_PATH` (custom context path in the Space filesystem)
178
-
179
- When the build completes, the app launches automatically on the Space URL.
180
-
181
- ### Local run
182
-
183
- ```bash
184
- python -m venv .venv
185
- source .venv/bin/activate
186
- pip install -r requirements.txt
187
- python app.py
188
- ```
189
-
190
- Open `http://localhost:7860`.
191
-
192
- ### Configurable context
193
-
194
- Set custom context file:
195
-
196
- ```bash
197
- export EVD_CONTEXT_PATH=/absolute/path/to/epi_context.json
198
- python app.py
199
- ```
200
-
201
- ### LLM configuration
202
-
203
- Set an OpenAI-compatible model before starting the app. The UI will not launch without credentials, and the initial interview turn is generated by the LLM:
204
-
205
- ```bash
206
- export EVD_LLM_API_KEY=your_key_here
207
- export EVD_LLM_MODEL=gpt-4.1-mini
208
- python app.py
209
- ```
210
-
211
- You can also use a local `.env` file (auto-loaded by the app):
212
-
213
- ```bash
214
- cp .env.example .env
215
- # edit .env with your real key
216
- python app.py
217
- ```
218
-
219
- Optional custom endpoint:
220
-
221
- ```bash
222
- export EVD_LLM_BASE_URL=https://your-openai-compatible-endpoint
223
- python app.py
224
- ```
225
-
226
- ### Container (example)
227
-
228
- ```dockerfile
229
- FROM python:3.12-slim
230
- WORKDIR /app
231
- COPY . .
232
- RUN pip install --no-cache-dir -r requirements.txt
233
- EXPOSE 7860
234
- CMD ["python", "app.py"]
235
- ```
236
-
237
- ## 10) Production Hardening Recommendations
238
-
239
- 1. Add authentication and role-based access control for surveillance users.
240
- 2. Encrypt data in transit and at rest (TLS + disk/database encryption).
241
- 3. Replace in-memory session state with durable backend store (PostgreSQL/Redis).
242
- 4. Add structured audit logging (classification path, timestamp, user identity, facility).
243
- 5. Add observability (metrics, traces, interview completion rates, escalation latency).
244
- 6. Add input validation guardrails and red-team testing for ambiguous narratives.
245
- 7. Add clinical governance versioning for case definitions by country/date.
246
- 8. Integrate notification adapters (SMS, DHIS2, surveillance endpoint APIs).
247
- 9. Add high-availability deployment and disaster recovery plan.
248
- 10. Add unit/integration/regression tests to CI/CD gates.
249
-
250
- ## 11) Complete Python Code
251
-
252
- All complete runnable code is included in this repository under:
253
- - `app.py`
254
- - `evd_agent/*.py`
255
-
256
- ## Notes on Clinical Scope
257
-
258
- - This system is a surveillance decision-support assistant and should be used under official public health protocols.
259
- - Confirmed case classification is intentionally excluded, pending laboratory diagnostics.
 
1
  ---
2
  title: Ebola Case Detection
3
+ emoji: 🏃
4
+ colorFrom: green
5
+ colorTo: green
6
  sdk: gradio
7
  sdk_version: 6.16.0
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference