Update README.md
Browse files
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
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
* **
|
| 22 |
-
* **Structured
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
*
|
| 27 |
-
*
|
| 28 |
-
*
|
| 29 |
-
*
|
| 30 |
-
* `
|
| 31 |
-
|
| 32 |
-
*
|
| 33 |
-
* `
|
| 34 |
-
*
|
| 35 |
-
* **
|
| 36 |
-
|
| 37 |
-
|
| 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:**
|
| 48 |
-
* **Tavily Search API:**
|
| 49 |
-
* **
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
-
|
| 108 |
|
| 109 |
-
|
| 110 |
|
| 111 |
-
|
|
|
|
|
|
|
| 112 |
|
| 113 |
-
|
| 114 |
-
export TAVILY_API_KEY="your_tavily_api_key"
|
| 115 |
-
Use code with caution.
|
| 116 |
-
Bash
|
| 117 |
-
Windows (Command Prompt):
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
|
| 124 |
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
|
|
|
|
|
|
| 130 |
|
| 131 |
-
|
| 132 |
-
TAVILY_API_KEY
|
| 133 |
-
Use code with caution.
|
| 134 |
-
And load it in your Python script using python-dotenv:
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 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 |
-
|
|
|
|
| 145 |
Use code with caution.
|
| 146 |
-
|
| 147 |
The application should open in your web browser.
|
| 148 |
|
| 149 |
๐ How to Use
|
| 150 |
-
Patient Intake: Fill out the
|
| 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 |
-
|
| 155 |
|
| 156 |
-
|
| 157 |
|
| 158 |
-
|
| 159 |
|
| 160 |
-
|
| 161 |
|
| 162 |
-
|
| 163 |
|
| 164 |
-
|
| 165 |
|
| 166 |
-
|
| 167 |
|
| 168 |
-
Structured JSON output
|
| 169 |
|
| 170 |
-
|
| 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
|
| 176 |
|
| 177 |
-
VERIFY ALL OUTPUT: All information, suggestions,
|
| 178 |
|
| 179 |
-
|
| 180 |
|
| 181 |
-
|
| 182 |
|
| 183 |
-
NO LIABILITY: The creators assume no responsibility for any decisions made based on
|
| 184 |
|
| 185 |
-
Always rely on your professional training and judgment
|
| 186 |
|
| 187 |
๐ฎ Future Enhancements
|
| 188 |
-
|
| 189 |
|
| 190 |
-
|
| 191 |
|
| 192 |
-
|
| 193 |
|
| 194 |
-
User Feedback
|
| 195 |
|
| 196 |
-
|
| 197 |
|
| 198 |
-
|
| 199 |
|
| 200 |
๐ License
|
| 201 |
(Optional: Specify a license, e.g., MIT, Apache 2.0, or state if it's proprietary)
|
| 202 |
|
| 203 |
-
**
|
| 204 |
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
|
|
|
|
|
|
|
|
|
| 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
|