Ruurd commited on
Commit
37370ba
·
1 Parent(s): ac7ee41

Load patient conversations each time

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -135,9 +135,6 @@ def chat_with_model(messages):
135
  }
136
  ]
137
 
138
- # Remove welcome message (only once shown)
139
- # filtered_messages = [msg for msg in messages if not (msg["role"] == "assistant" and "Welcome to the Radiologist's Companion" in msg["content"])]
140
-
141
  # FULL conversation
142
  full_messages = system_messages + messages
143
 
@@ -323,6 +320,14 @@ def load_patient_conversation(patient_key):
323
  return [welcome_message] + history
324
  return []
325
 
 
 
 
 
 
 
 
 
326
  # --- Gradio App ---
327
 
328
  with gr.Blocks(css=".gradio-container {height: 100vh; overflow: hidden;}") as demo:
@@ -400,14 +405,19 @@ with gr.Blocks(css=".gradio-container {height: 100vh; overflow: hidden;}") as de
400
  load_model_on_selection, inputs=default_model, outputs=model_status
401
  )
402
 
403
- # Submit message
404
  msg.submit(add_user_message, [msg, chatbot], [msg, chatbot], queue=False).then(
 
 
405
  chat_with_model, chatbot, chatbot
406
  )
 
407
  submit_btn.click(add_user_message, [msg, chatbot], [msg, chatbot], queue=False).then(
 
 
408
  chat_with_model, chatbot, chatbot
409
  )
410
 
 
411
  # Clear chat
412
  clear_btn.click(lambda: [], None, chatbot, queue=False)
413
 
 
135
  }
136
  ]
137
 
 
 
 
138
  # FULL conversation
139
  full_messages = system_messages + messages
140
 
 
320
  return [welcome_message] + history
321
  return []
322
 
323
+
324
+ def get_patient_conversation():
325
+ current_id = patient_id.value
326
+ if not current_id:
327
+ return []
328
+ return patient_conversations.get(current_id, [])
329
+
330
+
331
  # --- Gradio App ---
332
 
333
  with gr.Blocks(css=".gradio-container {height: 100vh; overflow: hidden;}") as demo:
 
405
  load_model_on_selection, inputs=default_model, outputs=model_status
406
  )
407
 
 
408
  msg.submit(add_user_message, [msg, chatbot], [msg, chatbot], queue=False).then(
409
+ get_patient_conversation, None, chatbot
410
+ ).then(
411
  chat_with_model, chatbot, chatbot
412
  )
413
+
414
  submit_btn.click(add_user_message, [msg, chatbot], [msg, chatbot], queue=False).then(
415
+ get_patient_conversation, None, chatbot
416
+ ).then(
417
  chat_with_model, chatbot, chatbot
418
  )
419
 
420
+
421
  # Clear chat
422
  clear_btn.click(lambda: [], None, chatbot, queue=False)
423