xiaosuhu86 commited on
Commit
11df046
·
1 Parent(s): b487b99

update: app.py debug purpose, still having problem

Browse files
Files changed (3) hide show
  1. .vscode/launch.json +17 -0
  2. app.py +7 -0
  3. paintrek-chat-v2.ipynb +24 -71
.vscode/launch.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Attach to Streamlit (debugpy)",
9
+ "type": "debugpy",
10
+ "request": "attach",
11
+ "connect": {
12
+ "host": "localhost",
13
+ "port": 8501
14
+ }
15
+ }
16
+ ]
17
+ }
app.py CHANGED
@@ -6,6 +6,13 @@ from langchain_core.messages import AIMessage, HumanMessage
6
  from modules.graph import invoke_our_graph
7
  from modules.st_callable_util import get_streamlit_cb # Utility function to get a Streamlit callback handler with context
8
 
 
 
 
 
 
 
 
9
 
10
  # Streamlit UI
11
  st.title("Paintrek Medical Assistant")
 
6
  from modules.graph import invoke_our_graph
7
  from modules.st_callable_util import get_streamlit_cb # Utility function to get a Streamlit callback handler with context
8
 
9
+ # This section is for debugging purpose
10
+ import debugpy
11
+
12
+ debugpy.listen(("localhost", 5678)) # Set the port for the debugger
13
+ print("Waiting for debugger attach...")
14
+ debugpy.wait_for_client() # Pause execution until debugger is attached
15
+
16
 
17
  # Streamlit UI
18
  st.title("Paintrek Medical Assistant")
paintrek-chat-v2.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": null,
6
  "metadata": {
7
  "execution": {
8
  "iopub.execute_input": "2025-01-29T20:09:11.440091Z",
@@ -36,7 +36,7 @@
36
  },
37
  {
38
  "cell_type": "code",
39
- "execution_count": null,
40
  "metadata": {
41
  "execution": {
42
  "iopub.execute_input": "2025-01-29T20:09:11.906458Z",
@@ -86,7 +86,7 @@
86
  },
87
  {
88
  "cell_type": "code",
89
- "execution_count": null,
90
  "metadata": {
91
  "execution": {
92
  "iopub.execute_input": "2025-01-29T20:09:38.185616Z",
@@ -106,77 +106,32 @@
106
  "Executing the chatbot graph...\n",
107
  "Model: Welcome to the Paintrek world. I am a health assistant, an interactive clinical recording system. I will ask you questions about your pain and related symptoms and record your responses. I will then store this information securely. At any time, you can type `q` to quit.\n",
108
  "User: Let's start\n",
109
- "Model: First, I'll need some basic information for identification. What is your full name, date of birth, gender, and contact number? Also, please provide the name and contact information for an emergency contact.\n",
110
  "User: I am Frank, DOB 1986-01-01, male, phone number is 12345, emergency name is Zoe, number is 67890.\n",
111
  "Model: Thank you. Now, can you describe your main symptom and how long you've been experiencing it?\n",
112
  "User: I had a headache, and it started two days ago.\n",
113
- "Model: Okay. Let's move on to a pain assessment. To help me understand your headache, please tell me:\n",
114
- "\n",
115
- "1. Where is the pain located on your head? (e.g., forehead, temple, back of head)\n",
116
- "2. On which side of your head is the pain located? (left, right, or both)\n",
117
- "3. On a scale of 0 to 10, with 0 being no pain and 10 being the worst pain imaginable, how intense is your headache right now?\n",
118
- "4. Can you describe the characteristics of your pain? (e.g., sharp, dull, throbbing, aching)\n",
119
- "5. When did the headache begin?\n",
120
- "6. Does the pain radiate to any other areas? If so, where?\n",
121
- "7. Are there any triggers that seem to make the headache worse?\n",
122
- "8. Do you have any other symptoms associated with the headache? (e.g., nausea, vomiting, sensitivity to light or sound)\n",
123
- "\n",
124
- "Please answer as accurately as possible. Remember, there are no wrong answers.\n",
125
  "User: My pain is located on the right head, and the scale is 2, the pain is sharp, the pain started 2 days ago, and the pain is not radiating. Cold will trigger the pain, and no other symptoms. \n",
126
- "Model: Excellent. Now, let's gather some information about your medical history. Do you have any existing medical conditions, allergies, current medications, or a history of surgeries? Please include dates where applicable.\n",
127
  "User: I had sinus, diagnosed in 2001-01-01, I did not have any surgery. I am taking ibprofin, no allergies.\n",
128
- "Model: We're making good progress. Next, I need some information about your family medical history, social history, and a brief systems review. Could you tell me about any significant medical conditions in your family? What is your occupation, and are there any lifestyle factors like smoking, alcohol, or drug use that I should be aware of? Also, describe your living situation and support system. Finally, have you experienced any recent changes in your weight, sleep patterns, gastrointestinal or urinary function, or any constitutional symptoms like fever, chills, or night sweats?\n",
129
  "User: My mom had a lung cancer at 45.\n",
130
- "Model: Thank you. Could you please answer the rest of the questions regarding your social history and systems review? This information is crucial for a complete picture of your health.\n",
131
  "User: I am a data scientist, I am a viggie. I don't use tobbaco or alcohol. My stress level is midium. \n",
132
- "Model: Okay. And what about your sleep patterns, gastrointestinal and urinary function, and any constitutional symptoms?\n",
133
  "User: I sleep well, and no other symptoms.\n",
134
- "Model: To complete the intake, let's briefly discuss your pain management history and functional assessment. Are you currently taking any pain medication for your headache? Have you consulted any specialists for your headache or explored any alternative therapies? How would you rate the effectiveness of any treatments you've tried? Finally, how has this headache affected your quality of life, your ability to perform daily activities, and your overall mood?\n",
135
  "User: No, I am not taking any other medication, and I haven't tried any alternative therapies. \n",
136
- "Model: And how has this headache impacted your daily life, activities, and mood?\n",
137
  "User: I am okay on my mood, and my quality of life is also good. I want to fix my headache.\n",
138
- "Model: Finally, let's talk about your treatment goals and expectations. What are your hopes for resolving this headache? Are there any alternative treatments you'd consider?\n",
139
- "User: I want to fix my headache.\n",
140
- "Model: Before we finalize this record, let me summarize the information we've gathered. Please confirm if everything is accurate:\n",
141
- "\n",
142
- "Patient Name: Frank\n",
143
- "DOB: 1986-01-01\n",
144
- "Gender: Male\n",
145
- "Contact: 12345\n",
146
- "Emergency Contact: Zoe, 67890\n",
147
- "\n",
148
- "Main Symptom: Headache\n",
149
- "Symptom Duration: Two days\n",
150
- "\n",
151
- "Pain Location: Right head\n",
152
- "Pain Intensity: 2/10\n",
153
- "Pain Characteristics: Sharp\n",
154
- "Pain Onset: Two days ago\n",
155
- "Radiation: No\n",
156
- "Triggers: Cold\n",
157
- "Associated Symptoms: None\n",
158
- "\n",
159
- "Medical History: Sinus (diagnosed 2001-01-01), taking ibuprofen, no allergies, no surgeries.\n",
160
- "\n",
161
- "Family History: Mother had lung cancer at age 45.\n",
162
- "\n",
163
- "Social History: Data scientist, no smoking, alcohol, or drug use. Living situation and support system unknown. Moderate stress levels.\n",
164
- "\n",
165
- "Systems Review: Good sleep, normal gastrointestinal and urinary function, no fever, chills, or night sweats, no recent weight changes.\n",
166
- "\n",
167
- "Pain Management History: No current pain medication, no specialist consultations, no alternative therapies.\n",
168
- "\n",
169
- "Functional Assessment: Good quality of life, no activity limitations, okay mood.\n",
170
- "\n",
171
- "Treatment Goals: Resolve headache. No alternative treatment considerations.\n",
172
- "\n",
173
- "\n",
174
- "Is all of this information correct? Please let me know if any corrections are needed.\n",
175
- "User: Yes\n",
176
  "Your input data:\n",
177
- "{'ID': {'name': 'Frank', 'DOB': '1986-01-01', 'gender': 'male', 'contact': '12345', 'emergency_contact': 'Zoe, 67890'}, 'symptom': {'main_symptom': 'headache', 'symptom_length': 'two days'}, 'pain': {'pain_location': 'right head', 'pain_side': 'right', 'pain_intensity': 2.0, 'pain_description': 'sharp', 'start_time': '2 days ago', 'radiation': False, 'triggers': 'cold', 'symptom': 'headache'}, 'medical_hist': {'medical_condition': 'sinus', 'first_time': '2001-01-01', 'surgery_history': 'None', 'medication': 'ibprofin', 'allergy': 'None'}, 'family_hist': {'family_history': 'Mom had lung cancer at 45'}, 'social_hist': {'occupation': 'data scientist', 'smoke': False, 'alcohol': False, 'drug': False, 'support_system': 'unknown', 'living_condition': 'unknown'}, 'review_system': {'weight_change': 'None', 'fever': False, 'chill': False, 'night_sweats': False, 'sleep': 'well', 'gastrointestinal': 'normal', 'urinary': 'normal'}, 'pain_manage': {'pain_medication': 'None', 'specialist': False, 'other_therapy': 'None', 'effectiveness': 'unknown'}, 'functional': {'life_quality': 'good', 'limit_activity': 'None', 'mood': 'okay'}, 'plan': {'goal': 'fix headache', 'expectation': 'fix headache', 'alternative_treatment': 'None'}}\n",
178
  "Saving the data!\n",
179
- "{'ID': {'name': 'Frank', 'DOB': '1986-01-01', 'gender': 'male', 'contact': '12345', 'emergency_contact': 'Zoe, 67890'}, 'symptom': {'main_symptom': 'headache', 'symptom_length': 'two days'}, 'pain': {'pain_location': 'right head', 'pain_side': 'right', 'pain_intensity': 2.0, 'pain_description': 'sharp', 'start_time': '2 days ago', 'radiation': False, 'triggers': 'cold', 'symptom': 'headache'}, 'medical_hist': {'medical_condition': 'sinus', 'first_time': '2001-01-01', 'surgery_history': 'None', 'medication': 'ibprofin', 'allergy': 'None'}, 'family_hist': {'family_history': 'Mom had lung cancer at 45'}, 'social_hist': {'occupation': 'data scientist', 'smoke': False, 'alcohol': False, 'drug': False, 'support_system': 'unknown', 'living_condition': 'unknown'}, 'review_system': {'weight_change': 'None', 'fever': False, 'chill': False, 'night_sweats': False, 'sleep': 'well', 'gastrointestinal': 'normal', 'urinary': 'normal'}, 'pain_manage': {'pain_medication': 'None', 'specialist': False, 'other_therapy': 'None', 'effectiveness': 'unknown'}, 'functional': {'life_quality': 'good', 'limit_activity': 'None', 'mood': 'okay'}, 'plan': {'goal': 'fix headache', 'expectation': 'fix headache', 'alternative_treatment': 'None'}}\n"
180
  ]
181
  }
182
  ],
@@ -212,7 +167,7 @@
212
  " 'DOB': '1986-01-01',\n",
213
  " 'gender': 'male',\n",
214
  " 'contact': '12345',\n",
215
- " 'emergency_contact': 'Zoe, 67890'},\n",
216
  " 'symptom': {'main_symptom': 'headache', 'symptom_length': 'two days'},\n",
217
  " 'pain': {'pain_location': 'right head',\n",
218
  " 'pain_side': 'right',\n",
@@ -227,30 +182,28 @@
227
  " 'surgery_history': 'None',\n",
228
  " 'medication': 'ibprofin',\n",
229
  " 'allergy': 'None'},\n",
230
- " 'family_hist': {'family_history': 'Mom had lung cancer at 45'},\n",
231
  " 'social_hist': {'occupation': 'data scientist',\n",
232
  " 'smoke': False,\n",
233
  " 'alcohol': False,\n",
234
  " 'drug': False,\n",
235
  " 'support_system': 'unknown',\n",
236
- " 'living_condition': 'unknown'},\n",
237
  " 'review_system': {'weight_change': 'None',\n",
238
  " 'fever': False,\n",
239
  " 'chill': False,\n",
240
  " 'night_sweats': False,\n",
241
  " 'sleep': 'well',\n",
242
- " 'gastrointestinal': 'normal',\n",
243
- " 'urinary': 'normal'},\n",
244
  " 'pain_manage': {'pain_medication': 'None',\n",
245
  " 'specialist': False,\n",
246
  " 'other_therapy': 'None',\n",
247
- " 'effectiveness': 'unknown'},\n",
248
  " 'functional': {'life_quality': 'good',\n",
249
  " 'limit_activity': 'None',\n",
250
  " 'mood': 'okay'},\n",
251
- " 'plan': {'goal': 'fix headache',\n",
252
- " 'expectation': 'fix headache',\n",
253
- " 'alternative_treatment': 'None'}}"
254
  ]
255
  },
256
  "execution_count": 4,
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 1,
6
  "metadata": {
7
  "execution": {
8
  "iopub.execute_input": "2025-01-29T20:09:11.440091Z",
 
36
  },
37
  {
38
  "cell_type": "code",
39
+ "execution_count": 2,
40
  "metadata": {
41
  "execution": {
42
  "iopub.execute_input": "2025-01-29T20:09:11.906458Z",
 
86
  },
87
  {
88
  "cell_type": "code",
89
+ "execution_count": 3,
90
  "metadata": {
91
  "execution": {
92
  "iopub.execute_input": "2025-01-29T20:09:38.185616Z",
 
106
  "Executing the chatbot graph...\n",
107
  "Model: Welcome to the Paintrek world. I am a health assistant, an interactive clinical recording system. I will ask you questions about your pain and related symptoms and record your responses. I will then store this information securely. At any time, you can type `q` to quit.\n",
108
  "User: Let's start\n",
109
+ "Model: First, let's collect some basic information for identification. What is your full name, date of birth (YYYY-MM-DD), gender, and contact number?\n",
110
  "User: I am Frank, DOB 1986-01-01, male, phone number is 12345, emergency name is Zoe, number is 67890.\n",
111
  "Model: Thank you. Now, can you describe your main symptom and how long you've been experiencing it?\n",
112
  "User: I had a headache, and it started two days ago.\n",
113
+ "Model: Okay. Let's move on to your pain. Can you tell me about the location, side (left, right, or both), and intensity (on a scale of 0-10, with 0 being no pain and 10 being the worst pain imaginable) of your headache? Also, please describe the characteristics of your pain (e.g., sharp, dull, throbbing), when it started, if it radiates to other areas, what triggers it, and if there are any associated symptoms.\n",
 
 
 
 
 
 
 
 
 
 
 
114
  "User: My pain is located on the right head, and the scale is 2, the pain is sharp, the pain started 2 days ago, and the pain is not radiating. Cold will trigger the pain, and no other symptoms. \n",
115
+ "Model: To continue, could you provide information on your medical history, including any existing medical conditions, when they first appeared, any surgeries you've had and when, your current medications, and any allergies you have?\n",
116
  "User: I had sinus, diagnosed in 2001-01-01, I did not have any surgery. I am taking ibprofin, no allergies.\n",
117
+ "Model: Thank you. Now, let's discuss your family history. Are there any significant medical conditions that run in your family?\n",
118
  "User: My mom had a lung cancer at 45.\n",
119
+ "Model: Could you share some information about your social history, including your occupation, whether you smoke or drink alcohol, your living situation, and your support system?\n",
120
  "User: I am a data scientist, I am a viggie. I don't use tobbaco or alcohol. My stress level is midium. \n",
121
+ "Model: Let's proceed with a systems review. Have you experienced any recent weight changes, fever, chills, night sweats, changes in sleep patterns, gastrointestinal issues, or urinary problems?\n",
122
  "User: I sleep well, and no other symptoms.\n",
123
+ "Model: Now, let's discuss your pain management history. What pain medications are you currently using, have you consulted any specialists for your pain, have you tried any alternative therapies, and how effective have these treatments been?\n",
124
  "User: No, I am not taking any other medication, and I haven't tried any alternative therapies. \n",
125
+ "Model: Finally, let's assess your functional status. How has this pain affected your quality of life, what activities have you been limited in, and how would you describe your current mood and emotional state?\n",
126
  "User: I am okay on my mood, and my quality of life is also good. I want to fix my headache.\n",
127
+ "Model: Before we conclude, could you please confirm that all the information I have gathered is accurate? If there are any corrections or additions, please let me know now.\n",
128
+ "User: Can you print the data you have already collected?\n",
129
+ "Model: Okay, everything seems correct.\n",
130
+ "User: \n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  "Your input data:\n",
132
+ "{'ID': {'name': 'Frank', 'DOB': '1986-01-01', 'gender': 'male', 'contact': '12345', 'emergency_contact': '67890'}, 'symptom': {'main_symptom': 'headache', 'symptom_length': 'two days'}, 'pain': {'pain_location': 'right head', 'pain_side': 'right', 'pain_intensity': 2.0, 'pain_description': 'sharp', 'start_time': '2 days ago', 'radiation': False, 'triggers': 'cold', 'symptom': 'headache'}, 'medical_hist': {'medical_condition': 'sinus', 'first_time': '2001-01-01', 'surgery_history': 'None', 'medication': 'ibprofin', 'allergy': 'None'}, 'family_hist': {'family_history': 'Mother had lung cancer at 45'}, 'social_hist': {'occupation': 'data scientist', 'smoke': False, 'alcohol': False, 'drug': False, 'support_system': 'unknown', 'living_condition': 'medium stress'}, 'review_system': {'weight_change': 'None', 'fever': False, 'chill': False, 'night_sweats': False, 'sleep': 'well', 'gastrointestinal': 'None', 'urinary': 'None'}, 'pain_manage': {'pain_medication': 'None', 'specialist': False, 'other_therapy': 'None', 'effectiveness': False}, 'functional': {'life_quality': 'good', 'limit_activity': 'None', 'mood': 'okay'}, 'plan': {'goal': '', 'expectation': '', 'alternative_treatment': ''}}\n",
133
  "Saving the data!\n",
134
+ "{'ID': {'name': 'Frank', 'DOB': '1986-01-01', 'gender': 'male', 'contact': '12345', 'emergency_contact': '67890'}, 'symptom': {'main_symptom': 'headache', 'symptom_length': 'two days'}, 'pain': {'pain_location': 'right head', 'pain_side': 'right', 'pain_intensity': 2.0, 'pain_description': 'sharp', 'start_time': '2 days ago', 'radiation': False, 'triggers': 'cold', 'symptom': 'headache'}, 'medical_hist': {'medical_condition': 'sinus', 'first_time': '2001-01-01', 'surgery_history': 'None', 'medication': 'ibprofin', 'allergy': 'None'}, 'family_hist': {'family_history': 'Mother had lung cancer at 45'}, 'social_hist': {'occupation': 'data scientist', 'smoke': False, 'alcohol': False, 'drug': False, 'support_system': 'unknown', 'living_condition': 'medium stress'}, 'review_system': {'weight_change': 'None', 'fever': False, 'chill': False, 'night_sweats': False, 'sleep': 'well', 'gastrointestinal': 'None', 'urinary': 'None'}, 'pain_manage': {'pain_medication': 'None', 'specialist': False, 'other_therapy': 'None', 'effectiveness': False}, 'functional': {'life_quality': 'good', 'limit_activity': 'None', 'mood': 'okay'}, 'plan': {'goal': '', 'expectation': '', 'alternative_treatment': ''}}\n"
135
  ]
136
  }
137
  ],
 
167
  " 'DOB': '1986-01-01',\n",
168
  " 'gender': 'male',\n",
169
  " 'contact': '12345',\n",
170
+ " 'emergency_contact': '67890'},\n",
171
  " 'symptom': {'main_symptom': 'headache', 'symptom_length': 'two days'},\n",
172
  " 'pain': {'pain_location': 'right head',\n",
173
  " 'pain_side': 'right',\n",
 
182
  " 'surgery_history': 'None',\n",
183
  " 'medication': 'ibprofin',\n",
184
  " 'allergy': 'None'},\n",
185
+ " 'family_hist': {'family_history': 'Mother had lung cancer at 45'},\n",
186
  " 'social_hist': {'occupation': 'data scientist',\n",
187
  " 'smoke': False,\n",
188
  " 'alcohol': False,\n",
189
  " 'drug': False,\n",
190
  " 'support_system': 'unknown',\n",
191
+ " 'living_condition': 'medium stress'},\n",
192
  " 'review_system': {'weight_change': 'None',\n",
193
  " 'fever': False,\n",
194
  " 'chill': False,\n",
195
  " 'night_sweats': False,\n",
196
  " 'sleep': 'well',\n",
197
+ " 'gastrointestinal': 'None',\n",
198
+ " 'urinary': 'None'},\n",
199
  " 'pain_manage': {'pain_medication': 'None',\n",
200
  " 'specialist': False,\n",
201
  " 'other_therapy': 'None',\n",
202
+ " 'effectiveness': False},\n",
203
  " 'functional': {'life_quality': 'good',\n",
204
  " 'limit_activity': 'None',\n",
205
  " 'mood': 'okay'},\n",
206
+ " 'plan': {'goal': '', 'expectation': '', 'alternative_treatment': ''}}"
 
 
207
  ]
208
  },
209
  "execution_count": 4,