Ruurd commited on
Commit
2ad2507
·
1 Parent(s): ab270d0

Update interface - three columns (and force recent

Browse files
Files changed (2) hide show
  1. app.py +70 -16
  2. requirements.txt +1 -1
app.py CHANGED
@@ -242,26 +242,82 @@ model_choices = [
242
  "mistralai/Mistral-Small-3.1-24B-Instruct-2503"
243
  ]
244
 
245
- with gr.Blocks() as demo:
246
- gr.Markdown("## Clinical Chatbot (Streaming)")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
 
248
  default_model = gr.State(model_choices[0])
249
 
250
- with gr.Row():
251
- mode = gr.Radio(["Choose from list", "Enter custom model"], value="Choose from list", label="Model Input Mode")
252
- model_selector = gr.Dropdown(choices=model_choices, label="Select Predefined Model")
253
- model_textbox = gr.Textbox(label="Or Enter HF Model Name")
254
-
255
- model_status = gr.Textbox(label="Model Status", interactive=False)
256
- chatbot = gr.Chatbot(label="Chat", type="messages")
257
- msg = gr.Textbox(label="Your message", placeholder="Enter clinical input...", show_label=False)
258
- with gr.Row():
259
- submit_btn = gr.Button("Submit", variant="primary")
260
- clear_btn = gr.Button("Clear", variant="secondary")
261
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  def resolve_model_choice(mode, dropdown_value, textbox_value):
263
  return textbox_value.strip() if mode == "Enter custom model" else dropdown_value
264
 
 
 
 
 
 
 
 
265
  # Load on launch
266
  demo.load(fn=load_model_on_selection, inputs=default_model, outputs=model_status)
267
 
@@ -286,6 +342,4 @@ with gr.Blocks() as demo:
286
 
287
  clear_btn.click(lambda: [], None, chatbot, queue=False)
288
 
289
-
290
-
291
  demo.launch()
 
242
  "mistralai/Mistral-Small-3.1-24B-Instruct-2503"
243
  ]
244
 
245
+ # Example patient database
246
+ patient_db = {
247
+ "001 - John Doe": {
248
+ "name": "John Doe",
249
+ "age": "45",
250
+ "id": "001",
251
+ "notes": "History of chest pain and hypertension. No prior surgeries."
252
+ },
253
+ "002 - Maria Sanchez": {
254
+ "name": "Maria Sanchez",
255
+ "age": "62",
256
+ "id": "002",
257
+ "notes": "Suspected pulmonary embolism. Shortness of breath, tachycardia."
258
+ },
259
+ "003 - Ahmed Al-Farsi": {
260
+ "name": "Ahmed Al-Farsi",
261
+ "age": "29",
262
+ "id": "003",
263
+ "notes": "Persistent migraines. MRI scheduled for brain imaging."
264
+ },
265
+ "004 - Lin Wei": {
266
+ "name": "Lin Wei",
267
+ "age": "51",
268
+ "id": "004",
269
+ "notes": "Annual screening. Family history of breast cancer."
270
+ }
271
+ }
272
+
273
+ def autofill_patient(patient_key):
274
+ if patient_key in patient_db:
275
+ info = patient_db[patient_key]
276
+ return info["name"], info["age"], info["id"], info["notes"]
277
+ return "", "", "", ""
278
+
279
+ with gr.Blocks(css=".gradio-container {height: 100vh; overflow: hidden;}") as demo:
280
+ gr.Markdown("## Radiologist's Companion")
281
 
282
  default_model = gr.State(model_choices[0])
283
 
284
+ with gr.Row(equal_height=True): # <-- make columns same height
285
+ with gr.Column(scale=1):
286
+ gr.Markdown("### Patient Information")
287
+ patient_selector = gr.Dropdown(
288
+ choices=list(patient_db.keys()), label="Select Patient", allow_custom_value=False
289
+ )
290
+ patient_name = gr.Textbox(label="Name", placeholder="e.g., John Doe")
291
+ patient_age = gr.Textbox(label="Age", placeholder="e.g., 45")
292
+ patient_id = gr.Textbox(label="Patient ID", placeholder="e.g., 123456")
293
+ patient_notes = gr.Textbox(label="Clinical Notes", lines=10, placeholder="e.g., History of chest pain...")
294
+
295
+ with gr.Column(scale=2):
296
+ gr.Markdown("### Chat")
297
+ chatbot = gr.Chatbot(label="Chat", type="messages", height=500) # <-- fixed height
298
+ msg = gr.Textbox(label="Your message", placeholder="Enter your chat message...", show_label=False)
299
+ with gr.Row():
300
+ submit_btn = gr.Button("Submit", variant="primary")
301
+ clear_btn = gr.Button("Clear", variant="secondary")
302
+
303
+ with gr.Column(scale=1):
304
+ gr.Markdown("### Model Settings")
305
+ mode = gr.Radio(["Choose from list", "Enter custom model"], value="Choose from list", label="Model Input Mode")
306
+ model_selector = gr.Dropdown(choices=model_choices, label="Select Predefined Model")
307
+ model_textbox = gr.Textbox(label="Or Enter HF Model Name")
308
+ model_status = gr.Textbox(label="Model Status", interactive=False)
309
+
310
+ # Functions for resolving model choice
311
  def resolve_model_choice(mode, dropdown_value, textbox_value):
312
  return textbox_value.strip() if mode == "Enter custom model" else dropdown_value
313
 
314
+ # Link patient selector
315
+ patient_selector.change(
316
+ autofill_patient,
317
+ inputs=[patient_selector],
318
+ outputs=[patient_name, patient_age, patient_id, patient_notes]
319
+ )
320
+
321
  # Load on launch
322
  demo.load(fn=load_model_on_selection, inputs=default_model, outputs=model_status)
323
 
 
342
 
343
  clear_btn.click(lambda: [], None, chatbot, queue=False)
344
 
 
 
345
  demo.launch()
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- transformers
2
  accelerate
3
  torch
4
  gradio
 
1
+ transformers>=4.40.0
2
  accelerate
3
  torch
4
  gradio