mgbam commited on
Commit
53eb85a
ยท
verified ยท
1 Parent(s): bb53fca

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +115 -126
README.md CHANGED
@@ -8,45 +8,45 @@ sdk_version: 1.44.1
8
  app_file: app.py
9
  pinned: false
10
  ---
11
- # ๐Ÿฉบ SynapseAI: Interactive Clinical Decision Support Assistant
12
-
13
- **SynapseAI** is an advanced prototype demonstrating an AI-powered clinical decision support system built with Streamlit, Langchain, LangGraph, Groq (running Llama 3), and Tavily Search. It simulates an interactive consultation where an AI assistant helps analyze patient data, suggests differential diagnoses, proposes management plans, checks for drug interactions, flags risks, and integrates clinical guideline information.
14
-
15
- **This is a proof-of-concept application intended for demonstration and educational purposes only. It is NOT a certified medical device and should NEVER be used for actual clinical decision-making.**
16
-
17
- ## โœจ Key Features
18
-
19
- * **Interactive Conversational Interface:** Utilizes LangGraph to manage multi-turn interactions, allowing the AI to process information sequentially, ask clarifying questions, and respond to user input dynamically.
20
- * **Structured Clinical Data Input:** Comprehensive sidebar form for inputting patient demographics, HPI, past history, medications, allergies, vitals, and basic exam findings.
21
- * **Advanced AI Analysis (Llama 3 via Groq):** Leverages a powerful Large Language Model for clinical reasoning.
22
- * **Structured AI Output:** The AI is prompted to provide its final analysis in a structured JSON format, including:
23
- * Clinical Assessment Summary
24
- * Differential Diagnosis (with likelihood & rationale)
25
- * Risk Assessment (Red Flags, Concerns, Complications)
26
- * Recommended Plan (Investigations, Therapeutics, Consults, Education)
27
- * Rationale Summary (Justification for the plan)
28
- * Interaction Check Summary
29
- * **Intelligent Tool Use:** Employs Langchain tools for specific actions:
30
- * `order_lab_test`: Simulates ordering labs with reason and priority.
31
- * `prescribe_medication`: Simulates preparing prescriptions with details (requires prior interaction check).
32
- * `check_drug_interactions`: **Mandatory safety check** performed before prescription suggestions, considering current meds and allergies (using a mock database).
33
- * `flag_risk`: Allows the AI to highlight critical risks immediately.
34
- * `tavily_search_results`: Enables the AI to search for external information, specifically prompted to look up **current clinical practice guidelines**.
35
- * **Safety Protocols:**
36
- * **Mandatory Interaction Checks:** The system enforces (via LangGraph logic) that an interaction check must be requested before a prescription tool call is executed.
37
- * **Red Flagging:** Includes both client-side initial checks and AI-driven risk flagging.
38
- * **Guideline Awareness:** The AI is explicitly prompted to use web search (Tavily) to find and reference relevant clinical guidelines (e.g., ACC/AHA, Surviving Sepsis) in its rationale.
39
- * **Robust Error Handling:** Implemented within the LangGraph `tool_node` to gracefully handle individual tool failures without crashing the application.
40
- * **Clear User Interface:** Built with Streamlit for an intuitive web-based experience, separating data input, chat interaction, and results display.
41
 
42
  ## ๐Ÿš€ Technology Stack
43
 
44
  * **Python:** Core programming language.
45
  * **Streamlit:** Web application framework for the UI.
46
  * **Langchain & LangGraph:** Framework for building LLM applications, managing conversation state, and orchestrating tool use.
47
- * **Groq API:** Provides fast inference for the Llama 3 LLM (or other supported models).
48
- * **Tavily Search API:** Enables the AI to perform web searches for guidelines and information.
49
- * **Pydantic:** Used for data validation in tool inputs.
 
 
 
50
 
51
  ## โš™๏ธ Setup and Installation
52
 
@@ -55,6 +55,7 @@ pinned: false
55
  * Python 3.8+
56
  * `pip` (Python package installer)
57
  * Git (for cloning the repository)
 
58
 
59
  ### Installation Steps
60
 
@@ -65,144 +66,132 @@ pinned: false
65
  ```
66
 
67
  2. **Create and Activate a Virtual Environment (Recommended):**
68
- * **macOS / Linux:**
69
- ```bash
70
- python3 -m venv venv
71
- source venv/bin/activate
72
- ```
73
- * **Windows:**
74
- ```bash
75
- python -m venv venv
76
- .\venv\Scripts\activate
77
- ```
78
-
79
- 3. **Install Dependencies:**
80
  ```bash
81
- pip install -r requirements.txt
 
 
 
 
 
82
  ```
83
- *(You'll need to create a `requirements.txt` file containing necessary libraries. See example below)*
84
-
85
- ### `requirements.txt` Example
86
-
87
- ```txt
88
- streamlit
89
- langchain
90
- langchain-groq
91
- langchain-community # For Tavily Search tool
92
- langgraph
93
- langchain-core
94
- pydantic>=1,<2 # Langchain often has specific Pydantic version needs
95
- groq
96
- tavily-python
97
- python-dotenv # Optional: For managing environment variables from a .env file
98
- Use code with caution.
99
- Markdown
100
- (Adjust versions as needed based on compatibility)
101
 
102
- API Keys
103
- This application requires API keys for Groq and Tavily Search.
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
- Groq API Key: Obtain from GroqCloud.
 
 
 
106
 
107
- Tavily API Key: Obtain from Tavily AI.
108
 
109
- Set these keys as environment variables. Do NOT hardcode them in your script.
110
 
111
- macOS / Linux:
 
 
112
 
113
- export GROQ_API_KEY="your_groq_api_key"
114
- export TAVILY_API_KEY="your_tavily_api_key"
115
- Use code with caution.
116
- Bash
117
- Windows (Command Prompt):
118
 
119
- set GROQ_API_KEY=your_groq_api_key
120
- set TAVILY_API_KEY=your_tavily_api_key
121
- Use code with caution.
122
- Bash
123
- Windows (PowerShell):
 
 
124
 
125
- $env:GROQ_API_KEY="your_groq_api_key"
126
- $env:TAVILY_API_KEY="your_tavily_api_key"
127
- Use code with caution.
128
- Bash
129
- Alternative: Create a .env file in the project root:
 
 
130
 
131
- GROQ_API_KEY="your_groq_api_key"
132
- TAVILY_API_KEY="your_tavily_api_key"
133
- Use code with caution.
134
- And load it in your Python script using python-dotenv:
135
 
136
- # Add near the top of your main script (e.g., app.py)
137
- from dotenv import load_dotenv
138
- load_dotenv()
139
- Use code with caution.
140
- Python
141
- โ–ถ๏ธ Running the Application
142
- Ensure your virtual environment is activated and API keys are set. Then run:
143
 
144
- streamlit run your_script_name.py # Replace 'your_script_name.py' with the actual filename
 
145
  Use code with caution.
146
- Bash
147
  The application should open in your web browser.
148
 
149
  ๐Ÿ“– How to Use
150
- Patient Intake: Fill out the detailed patient information form in the left sidebar.
151
-
152
- Start Consultation: Click the "Start/Update Consultation" button at the bottom of the sidebar. This loads the data and performs initial red flag checks.
153
 
154
- Interact with AI: Use the chat input box at the bottom of the main screen to:
155
 
156
- Ask the AI to analyze the loaded patient data (e.g., "Please analyze this patient.").
157
 
158
- Ask follow-up questions.
159
 
160
- Provide additional information requested by the AI.
161
 
162
- Review Responses: Observe the AI's responses in the chat interface. Pay attention to:
163
 
164
- Natural language replies or questions.
165
 
166
- Tool execution messages (indicated by ๐Ÿ› ๏ธ).
167
 
168
- Structured JSON output containing the full clinical assessment and plan (when the AI determines it's ready).
169
 
170
- Any safety warnings or flagged risks.
171
 
172
  โš ๏ธ Important Disclaimer
173
  SynapseAI is an experimental AI assistant demonstration.
174
 
175
- NOT FOR CLINICAL USE: It is NOT a substitute for professional medical advice, diagnosis, or treatment provided by a qualified healthcare provider.
176
 
177
- VERIFY ALL OUTPUT: All information, suggestions, differential diagnoses, medication recommendations, dosages, and interaction checks generated by the AI MUST be independently verified using standard, reliable medical resources and clinical judgment.
178
 
179
- AI LIMITATIONS: LLMs can hallucinate, make errors, and may not have access to the absolute latest medical knowledge or specific patient context beyond what is provided.
180
 
181
- MOCK DATA: Features like drug interaction checks currently rely on a limited, hardcoded mock database.
182
 
183
- NO LIABILITY: The creators assume no responsibility for any decisions made based on the output of this application.
184
 
185
- Always rely on your professional training and judgment when caring for patients.
186
 
187
  ๐Ÿ”ฎ Future Enhancements
188
- True Multi-Turn Refinement: Implement more sophisticated state management (e.g., LangGraph checkpointers) to allow the AI to refine its plan based on tool results within a single logical turn.
189
 
190
- Real Databases: Integrate with actual drug interaction databases (e.g., OpenFDA, RxNorm APIs) and potentially medical knowledge graphs.
191
 
192
- EMR Integration Concepts: Simulate reading/writing structured data in formats compatible with EMR/EHR systems (e.g., FHIR resources).
193
 
194
- User Feedback Loop: Allow clinicians to edit/approve/reject AI suggestions and potentially use this feedback for evaluation or fine-tuning (requires significant infrastructure).
195
 
196
- Improved NLP: Enhance extraction of structured data from free-text inputs (e.g., HPI, PMH notes).
197
 
198
- Context Window Management: Implement strategies (summarization, sliding window) for handling very long conversations.
199
 
200
  ๐Ÿ“„ License
201
  (Optional: Specify a license, e.g., MIT, Apache 2.0, or state if it's proprietary)
202
 
203
- **Remember to:**
204
 
205
- 1. Replace `app.py` with the name of your main Python file.
206
- 2. Create the `requirements.txt` file based on the example provided and your actual dependencies.
207
- 3. Consider adding a `LICENSE` file if you choose an open-source license.
 
 
 
208
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
8
  app_file: app.py
9
  pinned: false
10
  ---
11
+ # ๐Ÿฉบ SynapseAI: Interactive Clinical Decision Support Assistant (v2 - UMLS/FDA Integrated)
12
+
13
+ **SynapseAI** is an enhanced prototype demonstrating an AI-powered clinical decision support system. Built with a modular structure (`app.py` for UI, `agent.py` for logic), it uses Streamlit, Langchain, LangGraph, Groq (running Llama 3), Tavily Search, **UMLS/RxNorm API**, and **OpenFDA API**.
14
+
15
+ It simulates an interactive consultation where an AI assistant helps analyze patient data, suggests differential diagnoses, proposes management plans, performs **realistic drug interaction and allergy checks**, flags risks, incorporates clinical guideline information, and includes a **self-correction loop** based on interaction warnings.
16
+
17
+ **โš ๏ธ Disclaimer: This is a proof-of-concept application intended for demonstration and educational purposes only. It is NOT a certified medical device and should NEVER be used for actual clinical decision-making.**
18
+
19
+ ## โœจ Key Features (v2 Enhancements in Bold)
20
+
21
+ * **Interactive Conversational Interface:** Uses LangGraph for multi-turn interactions, sequential processing, and dynamic responses.
22
+ * **Structured Clinical Data Input:** Comprehensive sidebar form for patient intake.
23
+ * **Advanced AI Analysis:** Leverages Llama 3 via Groq for clinical reasoning.
24
+ * **Structured AI Output:** Provides analysis in JSON (Assessment, DDx, Risk, Plan, Rationale, Interaction Summary).
25
+ * **Intelligent Tool Use:** Employs Langchain tools:
26
+ * `order_lab_test`: Simulates ordering labs.
27
+ * `prescribe_medication`: Simulates preparing prescriptions (requires prior interaction check).
28
+ * **`check_drug_interactions` (Enhanced):** Performs **realistic drug-drug and drug-allergy checks** using **UMLS/RxNorm API** for drug normalization and **OpenFDA API** for retrieving contraindications, warnings, and interaction data from drug labels.
29
+ * `flag_risk`: Allows AI to highlight critical risks.
30
+ * `tavily_search_results`: Searches for external info, prompted for **current clinical guidelines**.
31
+ * **Enhanced Safety Protocols:**
32
+ * **Mandatory & Realistic Interaction Checks:** Enforces interaction checks before prescription; checks now use real-world APIs.
33
+ * **Self-Correction Loop:** Includes a dedicated step (`reflection_node`) in the LangGraph workflow where the agent specifically reviews significant interaction/allergy warnings and revises its therapeutic plan *before* presenting the final output.
34
+ * Red Flagging: Client-side initial checks and AI-driven risk flagging.
35
+ * **Guideline Awareness:** AI prompted to search for and reference clinical guidelines.
36
+ * **Modular Code Structure:** Separated UI (`app.py`) from core agent logic (`agent.py`) for better organization and maintainability.
37
+ * **Robust Error Handling:** Implemented within LangGraph nodes and API helpers.
 
 
 
38
 
39
  ## ๐Ÿš€ Technology Stack
40
 
41
  * **Python:** Core programming language.
42
  * **Streamlit:** Web application framework for the UI.
43
  * **Langchain & LangGraph:** Framework for building LLM applications, managing conversation state, and orchestrating tool use.
44
+ * **Groq API:** Fast inference for Llama 3 LLM.
45
+ * **Tavily Search API:** Web search for guidelines.
46
+ * **UMLS API (via RxNav/RxNorm):** Drug name normalization (finding RxCUIs). Requires UMLS Metathesaurus License and API Key.
47
+ * **OpenFDA API:** Retrieving drug label information (interactions, warnings, contraindications).
48
+ * **Requests:** For making HTTP calls to external APIs.
49
+ * **Pydantic:** Data validation in tool inputs.
50
 
51
  ## โš™๏ธ Setup and Installation
52
 
 
55
  * Python 3.8+
56
  * `pip` (Python package installer)
57
  * Git (for cloning the repository)
58
+ * **UMLS Metathesaurus License:** You **must** obtain a free license from the [NLM UMLS Website](https://uts.nlm.nih.gov/uts/signup-login) to get a UMLS API Key.
59
 
60
  ### Installation Steps
61
 
 
66
  ```
67
 
68
  2. **Create and Activate a Virtual Environment (Recommended):**
 
 
 
 
 
 
 
 
 
 
 
 
69
  ```bash
70
+ # macOS / Linux
71
+ python3 -m venv venv
72
+ source venv/bin/activate
73
+ # Windows
74
+ # python -m venv venv
75
+ # .\venv\Scripts\activate
76
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
+ 3. **Create `requirements.txt`:**
79
+ ```txt
80
+ streamlit
81
+ langchain
82
+ langchain-groq
83
+ langchain-community
84
+ langgraph
85
+ langchain-core
86
+ pydantic>=1,<2 # Check compatibility
87
+ groq
88
+ tavily-python
89
+ requests
90
+ python-dotenv
91
+ ```
92
 
93
+ 4. **Install Dependencies:**
94
+ ```bash
95
+ pip install -r requirements.txt
96
+ ```
97
 
98
+ ### API Keys
99
 
100
+ This application requires API keys for Groq, Tavily Search, and UMLS.
101
 
102
+ 1. **Groq API Key:** Obtain from [GroqCloud](https://console.groq.com/keys).
103
+ 2. **Tavily API Key:** Obtain from [Tavily AI](https://tavily.com/).
104
+ 3. **UMLS API Key:** Obtain after registering for a UMLS License via the [UTS NLM Website](https://uts.nlm.nih.gov/uts/profile).
105
 
106
+ **Set these keys as environment variables.**
 
 
 
 
107
 
108
+ * **Using a `.env` file (Recommended for Local):** Create a `.env` file in the project root:
109
+ ```
110
+ GROQ_API_KEY="your_groq_api_key"
111
+ TAVILY_API_KEY="your_tavily_api_key"
112
+ UMLS_API_KEY="your_umls_api_key"
113
+ ```
114
+ *(Ensure `.env` is in your `.gitignore`)*
115
 
116
+ * **Using System Environment Variables:** (Commands vary by OS)
117
+ ```bash
118
+ # Example for Linux/macOS
119
+ export GROQ_API_KEY="your_groq_api_key"
120
+ export TAVILY_API_KEY="your_tavily_api_key"
121
+ export UMLS_API_KEY="your_umls_api_key"
122
+ ```
123
 
124
+ * **Using Hugging Face Space Secrets (if deploying there):**
125
+ Go to your Space -> Settings -> Secrets and add secrets named `GROQ_API_KEY`, `TAVILY_API_KEY`, and `UMLS_API_KEY` with their respective values.
 
 
126
 
127
+ ## โ–ถ๏ธ Running the Application
128
+
129
+ Ensure your virtual environment is activated and API keys are accessible (either via `.env` or system environment). Then run:
 
 
 
 
130
 
131
+ ```bash
132
+ streamlit run app.py
133
  Use code with caution.
134
+ Markdown
135
  The application should open in your web browser.
136
 
137
  ๐Ÿ“– How to Use
138
+ Patient Intake: Fill out the patient information form in the sidebar.
 
 
139
 
140
+ Start Consultation: Click "Start/Update Consultation". Initial red flags (if any) will appear in the sidebar.
141
 
142
+ Interact with AI: Use the chat input. Start by asking the AI to analyze the patient (e.g., "Analyze this patient", "Proceed with assessment").
143
 
144
+ Review Responses: Observe the chat:
145
 
146
+ AI questions or conversational text.
147
 
148
+ Tool execution messages (๐Ÿ› ๏ธ).
149
 
150
+ Interaction Warnings/Alerts: Pay close attention to outputs from the check_drug_interactions tool.
151
 
152
+ Reflection Output: Notice when the AI explicitly mentions reviewing warnings and potentially revising its plan.
153
 
154
+ Final Structured JSON output with the comprehensive assessment.
155
 
156
+ Flagged risks shown as prominent errors (๐Ÿšจ).
157
 
158
  โš ๏ธ Important Disclaimer
159
  SynapseAI is an experimental AI assistant demonstration.
160
 
161
+ NOT FOR CLINICAL USE: It is NOT a substitute for professional medical advice, diagnosis, or treatment.
162
 
163
+ VERIFY ALL OUTPUT: All information, suggestions, diagnoses, medication recommendations, dosages, interaction checks, and guideline interpretations MUST be independently verified using standard medical resources and clinical judgment.
164
 
165
+ API LIMITATIONS: Relies on external APIs (RxNorm, OpenFDA, Tavily) which have their own limitations, potential downtimes, and data coverage gaps. Interaction checking is complex and may not catch everything.
166
 
167
+ AI LIMITATIONS: LLMs can hallucinate, make errors, and may misinterpret API results or guidelines.
168
 
169
+ NO LIABILITY: The creators assume no responsibility for any decisions made based on this application's output.
170
 
171
+ Always rely on your professional training and judgment.
172
 
173
  ๐Ÿ”ฎ Future Enhancements
174
+ Full Memory Implementation: Add LLM-based summarization to manage long conversation context.
175
 
176
+ Deeper EMR/FHIR Simulation: Allow parsing more complex FHIR resources and generating draft resources based on the plan.
177
 
178
+ Refined Guideline Extraction: Improve the extraction and application of specific recommendations from searched guidelines.
179
 
180
+ User Feedback Integration: Allow explicit clinician overrides/edits to the plan.
181
 
182
+ More Granular Tools: Add calculators (clinical scores, dosages), tools for specific disease pathways, etc.
183
 
184
+ Asynchronous Operations: Improve UI responsiveness during long API calls (more complex in Streamlit).
185
 
186
  ๐Ÿ“„ License
187
  (Optional: Specify a license, e.g., MIT, Apache 2.0, or state if it's proprietary)
188
 
189
+ **Key Updates in this README:**
190
 
191
+ * Reflects the **v2** status and highlights the integration of **UMLS/RxNorm and OpenFDA APIs** for realistic interaction checks.
192
+ * Explicitly mentions the **self-correction loop (`reflection_node`)** as a key feature.
193
+ * Includes instructions for obtaining a **UMLS License/API Key**.
194
+ * Updates the **Technology Stack** list.
195
+ * Emphasizes the reliance on **external APIs** and their limitations in the disclaimer.
196
+ * Reflects the **modular file structure** (`app.py`, `agent.py`).
197
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference