Update README.md
Browse files
README.md
CHANGED
@@ -4,9 +4,205 @@ emoji: ๐
|
|
4 |
colorFrom: yellow
|
5 |
colorTo: green
|
6 |
sdk: streamlit
|
7 |
-
sdk_version: 1.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
|
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
colorFrom: yellow
|
5 |
colorTo: green
|
6 |
sdk: streamlit
|
7 |
+
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 |
+
|
53 |
+
### Prerequisites
|
54 |
+
|
55 |
+
* Python 3.8+
|
56 |
+
* `pip` (Python package installer)
|
57 |
+
* Git (for cloning the repository)
|
58 |
+
|
59 |
+
### Installation Steps
|
60 |
+
|
61 |
+
1. **Clone the Repository:**
|
62 |
+
```bash
|
63 |
+
git clone <your-repository-url> # Replace with your repo URL
|
64 |
+
cd <your-repository-directory>
|
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
|