Spaces:
Sleeping
Sleeping
lmbarak01 commited on
Commit ·
f398215
1
Parent(s): 60d0ce1
Update README and deployment documentation
Browse files- .gitignore +4 -0
- README.md +127 -137
- static/app.js +1 -1
.gitignore
CHANGED
|
@@ -2,3 +2,7 @@
|
|
| 2 |
.venv/
|
| 3 |
__pycache__/
|
| 4 |
*.pyc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
.venv/
|
| 3 |
__pycache__/
|
| 4 |
*.pyc
|
| 5 |
+
.playwright-mcp/
|
| 6 |
+
hf-chatkit-domain-error.png
|
| 7 |
+
workflow_agent builder.png
|
| 8 |
+
pharma_complaints_agentic_en rev 4.drawio.png
|
README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
---
|
| 2 |
title: MIT Summer 2026 Pharma Agent
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: docker
|
|
@@ -8,210 +8,200 @@ app_port: 7860
|
|
| 8 |
pinned: false
|
| 9 |
---
|
| 10 |
|
| 11 |
-
#
|
| 12 |
|
| 13 |
-
|
| 14 |
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
-
|
|
|
|
|
|
|
|
|
|
| 22 |
- `OPENAI_API_KEY`
|
| 23 |
- `WORKFLOW_ID`
|
| 24 |
-
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
|
| 29 |
```powershell
|
| 30 |
-
|
|
|
|
| 31 |
```
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
Create the virtual environment:
|
| 36 |
|
| 37 |
```powershell
|
| 38 |
-
|
| 39 |
```
|
| 40 |
|
| 41 |
-
|
| 42 |
|
| 43 |
-
```
|
| 44 |
-
.
|
|
|
|
| 45 |
```
|
| 46 |
|
| 47 |
-
|
| 48 |
|
| 49 |
```powershell
|
| 50 |
-
|
| 51 |
-
.\.venv\Scripts\Activate.ps1
|
| 52 |
```
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
With the environment activated:
|
| 57 |
|
| 58 |
-
```
|
| 59 |
-
|
| 60 |
```
|
| 61 |
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
|
| 65 |
|
| 66 |
-
```
|
| 67 |
-
|
| 68 |
-
WORKFLOW_ID=wf_...
|
| 69 |
```
|
| 70 |
|
| 71 |
-
|
| 72 |
-
- `WORKFLOW_ID` must match a published workflow.
|
| 73 |
-
- The backend always uses the latest published version for that workflow ID.
|
| 74 |
-
- The API key is used only by the backend and is never exposed to the browser.
|
| 75 |
|
| 76 |
-
|
| 77 |
|
| 78 |
-
|
| 79 |
|
| 80 |
-
|
| 81 |
-
uvicorn app:app --reload --port 8000
|
| 82 |
-
```
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
|
| 88 |
-
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
- ChatKit session:
|
| 94 |
-
- The frontend automatically calls `POST /api/chatkit/session`.
|
| 95 |
|
| 96 |
-
|
| 97 |
|
| 98 |
-
|
|
|
|
|
|
|
| 99 |
|
| 100 |
-
|
| 101 |
-
- Frames the demo as an 8-agent pharmacovigilance and complaints workflow.
|
| 102 |
-
- Highlights the three routing paths and the 15-day EU BfArM PV deadline.
|
| 103 |
|
| 104 |
-
|
| 105 |
-
- Shows the latest 8 agents now represented on the site:
|
| 106 |
-
- Agent 1: Intake and Normalization
|
| 107 |
-
- Agent 2: Classifier and Router
|
| 108 |
-
- Agent 3: Economic Flow
|
| 109 |
-
- Agent 4: Product Information Flow
|
| 110 |
-
- Agent 5: PV Triage
|
| 111 |
-
- Agent 6: Interview and Follow-up
|
| 112 |
-
- Agent 7: HITL Gatekeeper
|
| 113 |
-
- Agent 8: Q&A User
|
| 114 |
-
- Agent 8 is the loop that keeps asking for missing PV follow-up data, especially a contact email, until follow-up can continue.
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
|
| 121 |
-
|
| 122 |
-
- Security guardrails at intake
|
| 123 |
-
- Grounding expectations for product-information answers
|
| 124 |
-
- Output moderation before closure
|
| 125 |
-
- Mandatory HITL handling for serious safety cases
|
| 126 |
|
| 127 |
-
|
| 128 |
-
- Replaced the old mixed examples with the canonical `Use Case Guide` scenarios:
|
| 129 |
-
- `UC-1` crushed shipment economic claim
|
| 130 |
-
- `UC-2` renal dosing product-information question
|
| 131 |
-
- `UC-3` serious adverse-event pharmacovigilance case
|
| 132 |
-
- `UC-4` serious adverse-event case where the patient already provides `pv_test@gmail.com`, so Agent 8 does not activate
|
| 133 |
-
- Each scenario shows:
|
| 134 |
-
- expected route
|
| 135 |
-
- expected decision
|
| 136 |
-
- workflow evidence
|
| 137 |
-
- operational actions
|
| 138 |
-
- The prompt can still be prefilled into ChatKit.
|
| 139 |
|
| 140 |
-
|
| 141 |
-
- Educational state view of:
|
| 142 |
-
- input guardrail
|
| 143 |
-
- intake
|
| 144 |
-
- triage
|
| 145 |
-
- specialist handling
|
| 146 |
-
- follow-up / Q&A
|
| 147 |
-
- output guardrail / HITL
|
| 148 |
-
- outcome
|
| 149 |
|
| 150 |
-
|
| 151 |
-
- Embedded ChatKit component
|
| 152 |
-
- Real conversation connected to the OpenAI workflow via `WORKFLOW_ID` (latest published version).
|
| 153 |
-
- Backend creates a secure session and returns `client_secret`
|
| 154 |
|
| 155 |
-
|
|
|
|
|
|
|
| 156 |
|
| 157 |
-
|
| 158 |
-
- `WORKFLOW_ID` only
|
| 159 |
|
| 160 |
-
|
|
|
|
|
|
|
| 161 |
|
| 162 |
-
|
| 163 |
|
| 164 |
-
|
| 165 |
|
| 166 |
-
|
| 167 |
-
- `POST /api/chatkit/session` in `app.py`
|
| 168 |
-
- the session payload shape sent to `/v1/chatkit/sessions`
|
| 169 |
-
- workflow latest-version behavior
|
| 170 |
-
- the ChatKit initialization flow in `static/app.js`
|
| 171 |
|
| 172 |
-
|
|
|
|
|
|
|
| 173 |
|
| 174 |
-
|
| 175 |
-
- Check that `.env` exists and contains both required values.
|
| 176 |
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
|
|
|
|
|
|
| 180 |
|
| 181 |
-
|
| 182 |
-
- Check internet access (ChatKit CDN and OpenAI API).
|
| 183 |
-
- Check browser console and Uvicorn logs.
|
| 184 |
-
|
| 185 |
-
## 12) Stop the application
|
| 186 |
-
|
| 187 |
-
- In terminal: `Ctrl + C`
|
| 188 |
-
- To exit the virtual environment:
|
| 189 |
|
| 190 |
```powershell
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
```
|
| 193 |
|
| 194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
```text
|
| 197 |
MIT Agent Builder/
|
| 198 |
|-- app.py
|
|
|
|
| 199 |
|-- requirements.txt
|
| 200 |
|-- .env.example
|
| 201 |
-
|-- .
|
| 202 |
|-- README.md
|
| 203 |
`-- static/
|
| 204 |
|-- index.html
|
| 205 |
|-- styles.css
|
| 206 |
-
|
|
|
|
|
|
|
| 207 |
```
|
| 208 |
|
| 209 |
-
|
| 210 |
-
- `requirements.txt`: Python dependencies required to run the app.
|
| 211 |
-
- `.env.example`: Template for required environment variables.
|
| 212 |
-
- `.gitignore`: Ignores local environment and cache files.
|
| 213 |
-
- `README.md`: Setup, run, troubleshooting, and updated site description.
|
| 214 |
-
- `static/index.html`: Main web page structure and content sections.
|
| 215 |
-
- `static/styles.css`: Visual styling, layout, and responsive behavior.
|
| 216 |
-
- `static/app.js`: Scenario selector, workflow-state rendering, and ChatKit initialization.
|
| 217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
title: MIT Summer 2026 Pharma Agent
|
| 3 |
+
emoji: 🧬
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: docker
|
|
|
|
| 8 |
pinned: false
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# MIT AI System Architecture LLMs Pharma Team
|
| 12 |
|
| 13 |
+
FastAPI website for a classroom pharmacovigilance and complaints demo. The site presents an 8-agent workflow, scenario lab, governance map, downloadable architecture diagrams, and a live OpenAI ChatKit conversation connected to a published Agent Builder workflow.
|
| 14 |
|
| 15 |
+
## Features
|
| 16 |
|
| 17 |
+
- 8-agent pharmacovigilance, product-information, and claims/returns architecture.
|
| 18 |
+
- Scenario lab with canonical use cases and prompt prefill into ChatKit.
|
| 19 |
+
- Workflow state map for route and governance visualization.
|
| 20 |
+
- Download buttons for the original architecture images:
|
| 21 |
+
- `static/agent-builder-multiagent-schema.png`
|
| 22 |
+
- `static/pharma_complaints_agentic_en_rev_4_sin_fondo.png`
|
| 23 |
+
- Live ChatKit component backed by `POST /api/chatkit/session`.
|
| 24 |
+
- Docker configuration for Hugging Face Spaces.
|
| 25 |
|
| 26 |
+
## Requirements
|
| 27 |
+
|
| 28 |
+
- Python 3.11 or higher for local development.
|
| 29 |
+
- Internet access for the OpenAI API and ChatKit CDN.
|
| 30 |
+
- Published OpenAI Agent Builder workflow.
|
| 31 |
+
- OpenAI credentials:
|
| 32 |
- `OPENAI_API_KEY`
|
| 33 |
- `WORKFLOW_ID`
|
| 34 |
+
- Git LFS for PNG assets when pushing to Hugging Face.
|
| 35 |
+
|
| 36 |
+
## Local Setup
|
| 37 |
|
| 38 |
+
Create and activate a virtual environment:
|
| 39 |
|
| 40 |
```powershell
|
| 41 |
+
python -m venv .venv
|
| 42 |
+
.\.venv\Scripts\Activate.ps1
|
| 43 |
```
|
| 44 |
|
| 45 |
+
Install dependencies:
|
|
|
|
|
|
|
| 46 |
|
| 47 |
```powershell
|
| 48 |
+
pip install -r requirements.txt
|
| 49 |
```
|
| 50 |
|
| 51 |
+
Create `.env` from `.env.example`:
|
| 52 |
|
| 53 |
+
```env
|
| 54 |
+
OPENAI_API_KEY=sk-proj-...
|
| 55 |
+
WORKFLOW_ID=wf_...
|
| 56 |
```
|
| 57 |
|
| 58 |
+
Run the app locally:
|
| 59 |
|
| 60 |
```powershell
|
| 61 |
+
uvicorn app:app --reload --port 8000
|
|
|
|
| 62 |
```
|
| 63 |
|
| 64 |
+
Open:
|
|
|
|
|
|
|
| 65 |
|
| 66 |
+
```text
|
| 67 |
+
http://127.0.0.1:8000
|
| 68 |
```
|
| 69 |
|
| 70 |
+
Health check:
|
| 71 |
+
|
| 72 |
+
```text
|
| 73 |
+
http://127.0.0.1:8000/health
|
| 74 |
+
```
|
| 75 |
|
| 76 |
+
Expected response:
|
| 77 |
|
| 78 |
+
```json
|
| 79 |
+
{"status":"ok"}
|
|
|
|
| 80 |
```
|
| 81 |
|
| 82 |
+
## Hugging Face Space Deployment
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
+
This repository is configured as a Docker Space through the README metadata and `Dockerfile`.
|
| 85 |
|
| 86 |
+
### 1. Create or Use a Space
|
| 87 |
|
| 88 |
+
Create a public Hugging Face Space with:
|
|
|
|
|
|
|
| 89 |
|
| 90 |
+
- SDK: `Docker`
|
| 91 |
+
- Visibility: `Public`
|
| 92 |
+
- Repository name example: `pharma-IA/MIT_Summer_2026`
|
| 93 |
|
| 94 |
+
The deployed direct app URL will follow this pattern:
|
| 95 |
|
| 96 |
+
```text
|
| 97 |
+
https://<owner>-<space-name>.hf.space
|
| 98 |
+
```
|
|
|
|
|
|
|
| 99 |
|
| 100 |
+
For this project:
|
| 101 |
|
| 102 |
+
```text
|
| 103 |
+
https://pharma-ia-mit-summer-2026.hf.space
|
| 104 |
+
```
|
| 105 |
|
| 106 |
+
### 2. Configure Secrets
|
|
|
|
|
|
|
| 107 |
|
| 108 |
+
In the Hugging Face Space settings, add these as **Secrets**:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
+
```text
|
| 111 |
+
OPENAI_API_KEY
|
| 112 |
+
WORKFLOW_ID
|
| 113 |
+
```
|
| 114 |
|
| 115 |
+
Do not commit `.env`. Hugging Face reads secrets from runtime environment variables.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
+
### 3. Allowlist the Space Domain in OpenAI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
+
ChatKit production domains must be allowlisted in OpenAI Platform.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
+
Add the exact direct Space domain:
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
+
```text
|
| 124 |
+
https://pharma-ia-mit-summer-2026.hf.space
|
| 125 |
+
```
|
| 126 |
|
| 127 |
+
OpenAI settings:
|
|
|
|
| 128 |
|
| 129 |
+
```text
|
| 130 |
+
https://platform.openai.com/settings/organization/security/domain-allowlist
|
| 131 |
+
```
|
| 132 |
|
| 133 |
+
Use the direct `.hf.space` URL for testing the app. The `huggingface.co/spaces/...` page embeds the app in an iframe and may behave differently for external widgets.
|
| 134 |
|
| 135 |
+
### 4. Push to Hugging Face
|
| 136 |
|
| 137 |
+
Add the Space remote:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
+
```powershell
|
| 140 |
+
git remote add hfspace https://user:<HF_TOKEN>@huggingface.co/spaces/pharma-IA/MIT_Summer_2026
|
| 141 |
+
```
|
| 142 |
|
| 143 |
+
Install and initialize Git LFS if needed:
|
|
|
|
| 144 |
|
| 145 |
+
```powershell
|
| 146 |
+
git lfs install
|
| 147 |
+
git lfs track "*.png"
|
| 148 |
+
git add .gitattributes
|
| 149 |
+
```
|
| 150 |
|
| 151 |
+
Push:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
```powershell
|
| 154 |
+
git push hfspace main
|
| 155 |
+
```
|
| 156 |
+
|
| 157 |
+
Hugging Face will rebuild the Docker Space automatically.
|
| 158 |
+
|
| 159 |
+
## Runtime Behavior
|
| 160 |
+
|
| 161 |
+
The backend creates ChatKit sessions with:
|
| 162 |
+
|
| 163 |
+
```json
|
| 164 |
+
{
|
| 165 |
+
"workflow": {"id": "WORKFLOW_ID"},
|
| 166 |
+
"user": "stable_user_id"
|
| 167 |
+
}
|
| 168 |
```
|
| 169 |
|
| 170 |
+
OpenAI resolves the workflow ID to the latest published workflow version. No workflow version is hardcoded in this repository.
|
| 171 |
+
|
| 172 |
+
## Troubleshooting
|
| 173 |
+
|
| 174 |
+
- `Missing required environment variable(s)`: set `OPENAI_API_KEY` and `WORKFLOW_ID` locally or in HF Space Secrets.
|
| 175 |
+
- `workflow not found`: confirm the workflow is published and belongs to the same OpenAI project as the API key.
|
| 176 |
+
- Chat area is blank in HF: open the direct `.hf.space` URL and confirm that domain is in the OpenAI domain allowlist.
|
| 177 |
+
- PNG push rejected by Hugging Face: use Git LFS for image assets.
|
| 178 |
+
- Local CSS looks stale: hard refresh the browser with `Ctrl+F5`.
|
| 179 |
+
|
| 180 |
+
## Project Tree
|
| 181 |
|
| 182 |
```text
|
| 183 |
MIT Agent Builder/
|
| 184 |
|-- app.py
|
| 185 |
+
|-- Dockerfile
|
| 186 |
|-- requirements.txt
|
| 187 |
|-- .env.example
|
| 188 |
+
|-- .gitattributes
|
| 189 |
|-- README.md
|
| 190 |
`-- static/
|
| 191 |
|-- index.html
|
| 192 |
|-- styles.css
|
| 193 |
+
|-- app.js
|
| 194 |
+
|-- agent-builder-multiagent-schema.png
|
| 195 |
+
`-- pharma_complaints_agentic_en_rev_4_sin_fondo.png
|
| 196 |
```
|
| 197 |
|
| 198 |
+
## File Roles
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
+
- `app.py`: FastAPI backend. Serves the site, health check, static assets, and ChatKit session endpoint.
|
| 201 |
+
- `Dockerfile`: Runtime image for Hugging Face Docker Spaces.
|
| 202 |
+
- `requirements.txt`: Python dependencies.
|
| 203 |
+
- `.env.example`: Local environment template.
|
| 204 |
+
- `.gitattributes`: Git LFS tracking for PNG assets.
|
| 205 |
+
- `static/index.html`: Website content and layout.
|
| 206 |
+
- `static/styles.css`: Visual styling and responsive behavior.
|
| 207 |
+
- `static/app.js`: Scenario logic, ChatKit initialization, and error handling.
|
static/app.js
CHANGED
|
@@ -108,7 +108,7 @@ const scenarios = [
|
|
| 108 |
actions: [
|
| 109 |
"Run ICSR minimum-criteria and seriousness screening.",
|
| 110 |
"Ask patient follow-up questions and capture missing safety fields.",
|
| 111 |
-
"Escalate through the HITL gatekeeper and flag the
|
| 112 |
],
|
| 113 |
stepStates: {
|
| 114 |
input: "active",
|
|
|
|
| 108 |
actions: [
|
| 109 |
"Run ICSR minimum-criteria and seriousness screening.",
|
| 110 |
"Ask patient follow-up questions and capture missing safety fields.",
|
| 111 |
+
"Escalate through the HITL gatekeeper and flag the applicable regulatory timeline.",
|
| 112 |
],
|
| 113 |
stepStates: {
|
| 114 |
input: "active",
|