Francesco commited on
Commit
4a50ad1
1 Parent(s): ca72837

added more settings to patients

Browse files
Files changed (2) hide show
  1. data/patients.json +29 -34
  2. main.py +62 -21
data/patients.json CHANGED
@@ -1,50 +1,45 @@
1
  [
2
- {
 
3
  "presentingComplaint": "Abdominal pain",
4
  "matchedCondition": "Gastritis",
5
  "name": "Emma Thompson",
6
  "age": 28,
7
- "characterSummary": "Spirited graphic designer, curious, empathetic",
8
  "levelOfUnderstanding": 2,
9
- "rangeOfMedicalUnderstanding": "Limited knowledge of common illnesses",
10
  "communicative": 5,
11
  "difficulty": "easy",
12
- "mood": "pain"
13
- },
14
- {
 
 
15
  "presentingComplaint": "Chest pain",
16
- "matchedCondition": "Angina",
17
  "name": "James Wilson",
18
  "age": 45,
19
- "characterSummary": "Seasoned entrepreneur, strategic, mentoring spirit",
20
- "levelOfUnderstanding": 4,
21
- "rangeOfMedicalUnderstanding": "Basic understanding of health and wellness"
22
- },
23
- {
 
 
 
 
 
24
  "presentingComplaint": "Headache",
25
- "matchedCondition": "Migraine",
26
  "name": "Olivia Patel",
27
  "age": 52,
28
  "characterSummary": "Compassionate nurse, nurturing, animal lover",
29
  "levelOfUnderstanding": 8,
30
- "rangeOfMedicalUnderstanding": "Proficient in healthcare terminology"
31
- },
32
- {
33
- "presentingComplaint": "Shortness of breath",
34
- "matchedCondition": "Asthma",
35
- "name": "Noah Collins",
36
- "age": 36,
37
- "characterSummary": "Adventurous thrill-seeker, introspective",
38
- "levelOfUnderstanding": 2,
39
- "rangeOfMedicalUnderstanding": "Limited understanding of medical issues"
40
- },
41
- {
42
- "presentingComplaint": "Fever",
43
- "matchedCondition": "Influenza",
44
- "name": "Ava Mitchell",
45
- "age": 19,
46
- "characterSummary": "Ambitious computer science student, talented pianist",
47
- "levelOfUnderstanding": 3,
48
- "rangeOfMedicalUnderstanding": "Familiar with basic medical concepts"
49
- }
50
- ]
 
1
  [
2
+ {
3
+ "patientId": 1,
4
  "presentingComplaint": "Abdominal pain",
5
  "matchedCondition": "Gastritis",
6
  "name": "Emma Thompson",
7
  "age": 28,
8
+ "characterSummary": "Spirited graphic designer, curious, empathetic, smoker, takes psychedelics and smokes marijuana, drinks alcohol",
9
  "levelOfUnderstanding": 2,
10
+ "rangeOfMedicalUnderstanding": 2,
11
  "communicative": 5,
12
  "difficulty": "easy",
13
+ "mood": "pain",
14
+ "familyHistory": "none known"
15
+ },
16
+ {
17
+ "patientId": 2,
18
  "presentingComplaint": "Chest pain",
19
+ "matchedCondition": "myocardial infarction",
20
  "name": "James Wilson",
21
  "age": 45,
22
+ "characterSummary": "Seasoned entrepreneur, strategic, mentoring spirit, ultramarathon runner, non smoker, non drinker",
23
+ "levelOfUnderstanding": 8,
24
+ "rangeOfMedicalUnderstanding": 4,
25
+ "communicative": 3,
26
+ "difficulty": "hard",
27
+ "mood": "severe pain",
28
+ "familyHistory": "Father died of heart attack at 48, uncle died of heart attack at 54."
29
+ },
30
+ {
31
+ "patientId": 3,
32
  "presentingComplaint": "Headache",
33
+ "matchedCondition": "subarachnoid haemorrhage",
34
  "name": "Olivia Patel",
35
  "age": 52,
36
  "characterSummary": "Compassionate nurse, nurturing, animal lover",
37
  "levelOfUnderstanding": 8,
38
+ "rangeOfMedicalUnderstanding": 9,
39
+ "communicative": 3,
40
+ "difficulty": "hard",
41
+ "mood": "pain but can talk easily",
42
+ "familyHistory": "none known"
43
+ }
44
+ ]
45
+
 
 
 
 
 
 
 
 
 
 
 
 
 
main.py CHANGED
@@ -60,6 +60,7 @@ def message_handler(
60
  if chat is None:
61
  # in the queue we will store our streamed tokens
62
  queue = Queue()
 
63
  # let's create our default chat
64
  chat = ChatOpenAI(
65
  model_name=MODELS_NAMES[0],
@@ -71,7 +72,6 @@ def message_handler(
71
  # hacky way to get the queue back
72
  queue = chat.callbacks[0].queue
73
  job_done = object()
74
-
75
  logging.info("asking question to GPT")
76
  # let's add the messages to our stuff
77
  messages.append(HumanMessage(content=f"Doctor:{message}"))
@@ -104,8 +104,9 @@ def message_handler(
104
  return chat, "", chatbot_messages, messages
105
 
106
 
107
- def on_clear_click() -> Tuple[str, List, List]:
108
- return "", [], []
 
109
 
110
 
111
  def on_done_click(
@@ -115,10 +116,16 @@ def on_done_click(
115
  add_chat_by_uid(
116
  client, Chat(patient=patient, messages=chatbot_messages), user["uid"]
117
  )
118
- return on_clear_click()
119
 
120
 
121
- def on_apply_settings_click(model_name: str, temperature: float):
 
 
 
 
 
 
122
  logging.info(
123
  f"Applying settings: model_name={model_name}, temperature={temperature}"
124
  )
@@ -130,7 +137,11 @@ def on_apply_settings_click(model_name: str, temperature: float):
130
  )
131
  # don't forget to nuke our queue
132
  chat.callbacks[0].queue.empty()
133
- return chat, *on_clear_click()
 
 
 
 
134
 
135
 
136
  def on_drop_down_change(selected_item, messages):
@@ -138,7 +149,15 @@ def on_drop_down_change(selected_item, messages):
138
  patient = patiens[index]
139
  messages = [system_message_prompt.format(patient=patient)]
140
  print(f"You selected: {selected_item}", index)
141
- return patient, patient, [], messages
 
 
 
 
 
 
 
 
142
 
143
 
144
  def on_demo_load(url_params, request: gr.Request):
@@ -192,12 +211,12 @@ with gr.Blocks(
192
  [chat, message, chatbot, messages],
193
  [chat, message, chatbot, messages],
194
  )
195
-
196
  with gr.Row():
197
  with gr.Column():
198
  js = "(x) => confirm('Press a button!')"
199
 
200
- done = gr.Button("Done", variant="stop")
201
  done.click(
202
  on_done_click,
203
  [chatbot, patient, user],
@@ -215,12 +234,22 @@ with gr.Blocks(
215
  label="temperature",
216
  interactive=True,
217
  )
218
- apply_settings = gr.Button("Apply")
219
- apply_settings.click(
220
- on_apply_settings_click,
221
- [model_name, temperature],
222
- [chat, message, chatbot, messages],
 
 
 
 
 
 
 
 
223
  )
 
 
224
  with gr.Column():
225
  patients_names = [el["name"] for el in patiens]
226
  dropdown = gr.Dropdown(
@@ -229,15 +258,25 @@ with gr.Blocks(
229
  interactive=True,
230
  label="Patient",
231
  )
232
-
233
  patient_card = gr.JSON(patient.value, visible=True, label="Patient card")
 
 
 
 
 
234
  dropdown.change(
235
  fn=on_drop_down_change,
236
  inputs=[dropdown, messages],
237
- outputs=[patient_card, patient, chatbot, messages],
 
 
 
 
 
 
 
238
  )
239
 
240
-
241
  # app = FastAPI()
242
  # os.makedirs("static", exist_ok=True)
243
  # app.mount("/static", StaticFiles(directory="static"), name="static")
@@ -246,15 +285,17 @@ with gr.Blocks(
246
  # async def home(request: Request):
247
  # return templates.TemplateResponse(
248
  # "home.html", {"request": request, "videos": []})
 
 
249
  def auth_handler(username: str, password: str) -> bool:
250
  if password != os.environ["GRADIO_PASSWORD"]:
251
  return False
252
-
253
  return True
254
 
 
255
  demo.queue()
256
  demo.launch(auth=auth_handler)
257
 
258
- # gradio_app = gr.routes.App.create_app(demo)
259
- # app.mount("/gradio", gradio_app)
260
-
 
60
  if chat is None:
61
  # in the queue we will store our streamed tokens
62
  queue = Queue()
63
+ print("Creating new chat")
64
  # let's create our default chat
65
  chat = ChatOpenAI(
66
  model_name=MODELS_NAMES[0],
 
72
  # hacky way to get the queue back
73
  queue = chat.callbacks[0].queue
74
  job_done = object()
 
75
  logging.info("asking question to GPT")
76
  # let's add the messages to our stuff
77
  messages.append(HumanMessage(content=f"Doctor:{message}"))
 
104
  return chat, "", chatbot_messages, messages
105
 
106
 
107
+ def on_clear_click(patient: str) -> Tuple[str, List, List]:
108
+ messages = [system_message_prompt.format(patient=patient)]
109
+ return "", [], messages
110
 
111
 
112
  def on_done_click(
 
116
  add_chat_by_uid(
117
  client, Chat(patient=patient, messages=chatbot_messages), user["uid"]
118
  )
119
+ return on_clear_click(patient)
120
 
121
 
122
+ def on_apply_settings_click(
123
+ model_name: str,
124
+ temperature: float,
125
+ patient: str,
126
+ difficulty: str,
127
+ communicative: str,
128
+ ):
129
  logging.info(
130
  f"Applying settings: model_name={model_name}, temperature={temperature}"
131
  )
 
137
  )
138
  # don't forget to nuke our queue
139
  chat.callbacks[0].queue.empty()
140
+ patient["difficulty"] = difficulty
141
+ patient["communicative"] = communicative
142
+ print("patient", patient)
143
+ message, chatbot, messages = on_clear_click(patient)
144
+ return chat, message, chatbot, messages, patient
145
 
146
 
147
  def on_drop_down_change(selected_item, messages):
 
149
  patient = patiens[index]
150
  messages = [system_message_prompt.format(patient=patient)]
151
  print(f"You selected: {selected_item}", index)
152
+ print(f"on_drop_down_change {patient}")
153
+ return (
154
+ patient,
155
+ patient,
156
+ [],
157
+ messages,
158
+ patient["difficulty"],
159
+ patient["communicative"],
160
+ )
161
 
162
 
163
  def on_demo_load(url_params, request: gr.Request):
 
211
  [chat, message, chatbot, messages],
212
  [chat, message, chatbot, messages],
213
  )
214
+
215
  with gr.Row():
216
  with gr.Column():
217
  js = "(x) => confirm('Press a button!')"
218
 
219
+ done = gr.Button("Done", variant="stop")
220
  done.click(
221
  on_done_click,
222
  [chatbot, patient, user],
 
234
  label="temperature",
235
  interactive=True,
236
  )
237
+ difficulty = gr.Dropdown(
238
+ choices=["easy", "medium", "hard"],
239
+ value=patient.value["difficulty"],
240
+ label="difficulty",
241
+ interactive=True,
242
+ )
243
+ communicative = gr.Slider(
244
+ minimum=0,
245
+ maximum=5,
246
+ value=patient.value["communicative"],
247
+ step=1,
248
+ label="communicative",
249
+ interactive=True,
250
  )
251
+ apply_settings = gr.Button("Apply")
252
+
253
  with gr.Column():
254
  patients_names = [el["name"] for el in patiens]
255
  dropdown = gr.Dropdown(
 
258
  interactive=True,
259
  label="Patient",
260
  )
 
261
  patient_card = gr.JSON(patient.value, visible=True, label="Patient card")
262
+ apply_settings.click(
263
+ on_apply_settings_click,
264
+ [model_name, temperature, patient, difficulty, communicative],
265
+ [chat, message, chatbot, messages, patient_card],
266
+ )
267
  dropdown.change(
268
  fn=on_drop_down_change,
269
  inputs=[dropdown, messages],
270
+ outputs=[
271
+ patient_card,
272
+ patient,
273
+ chatbot,
274
+ messages,
275
+ difficulty,
276
+ communicative,
277
+ ],
278
  )
279
 
 
280
  # app = FastAPI()
281
  # os.makedirs("static", exist_ok=True)
282
  # app.mount("/static", StaticFiles(directory="static"), name="static")
 
285
  # async def home(request: Request):
286
  # return templates.TemplateResponse(
287
  # "home.html", {"request": request, "videos": []})
288
+
289
+
290
  def auth_handler(username: str, password: str) -> bool:
291
  if password != os.environ["GRADIO_PASSWORD"]:
292
  return False
293
+
294
  return True
295
 
296
+
297
  demo.queue()
298
  demo.launch(auth=auth_handler)
299
 
300
+ # gradio_app = gr.routes.App.create_app(demo)
301
+ # app.mount("/gradio", gradio_app)