vaibhavm29 commited on
Commit
3c58ccd
Β·
1 Parent(s): f6ddac9
Files changed (1) hide show
  1. interface.py +52 -46
interface.py CHANGED
@@ -255,24 +255,24 @@ def create_demo(agent, tools_dict):
255
  with gr.Tabs():
256
  with gr.Tab(label="Image section"):
257
  image_display = gr.Image(
258
- label="Image", type="filepath", height=650, container=True
259
  )
 
 
 
 
 
 
 
 
 
260
  with gr.Row():
261
- upload_button = gr.UploadButton(
262
- "πŸ“Ž Upload X-Ray",
263
- file_types=["image"],
264
- )
265
- dicom_upload = gr.UploadButton(
266
- "πŸ“„ Upload DICOM",
267
- file_types=["file"],
268
- )
269
- with gr.Row():
270
- analyze_btn = gr.Button("Analyze", interactive=False)
271
- # ground_btn = gr.Button("Ground", interactive=False)
272
- segment_btn = gr.Button("Segment", interactive=False)
273
  with gr.Row():
274
  clear_btn = gr.Button("Clear Chat")
275
- new_thread_btn = gr.Button("New Thread")
276
 
277
  with gr.Tab(label="Report section"):
278
  generate_report_btn = gr.Button("Generate Report")
@@ -280,24 +280,24 @@ def create_demo(agent, tools_dict):
280
  # headers=["Disease", "Info"],
281
  # datatype=["str", "str"],
282
  # interactive=False, visible=False, max_height=220)
283
- conclusion_tb = gr.Textbox(label="Conclusion", interactive=False, visible=False)
284
  with gr.Row():
285
  approve_btn = gr.Button("Approve", visible=False)
286
- reject_btn = gr.Button("Reject", visible=False)
287
  download_pdf_btn = gr.DownloadButton(label="πŸ“₯ Download PDF", visible=False)
288
  # pdf_preview = gr.HTML(visible=False)
289
  # pdf_preview = gr.File(visible=False)
290
  pdf_preview = PDF(visible=False)
291
- rejection_text = gr.Textbox(
292
- show_label=False,
293
- visible=False,
294
- placeholder="Tell us what is wrong with the report",
295
- container=False,
296
- interactive=True
297
- )
298
- with gr.Row():
299
- submit_reject_btn = gr.Button("Submit", visible=False)
300
- cancel_reject_btn = gr.Button("Cancel", visible=False)
301
 
302
  # Event handlers
303
  def authenticate(username, password):
@@ -318,19 +318,25 @@ def create_demo(agent, tools_dict):
318
 
319
  def new_thread():
320
  interface.current_thread_id = str(time.time())
321
- return [], interface.display_file_path
 
 
 
 
 
 
 
 
322
 
323
  def handle_file_upload(file):
324
  return interface.handle_upload(file.name)
325
 
326
  def generate_report():
327
  result = interface.agent.summarize_message(interface.current_thread_id)
328
- # table = [[d["name"], d["info"]] for d in result["Disease"]]
329
  return (
330
- # gr.update(value=table, interactive=True, visible=True),
331
- gr.update(value=result["Conclusion"], lines=4, interactive=True, visible=True),
332
- gr.update(visible=True),
333
  gr.update(visible=True),
 
334
  )
335
 
336
  # def records_to_pdf(table, conclusion) -> Path:
@@ -407,15 +413,15 @@ def create_demo(agent, tools_dict):
407
  outputs=[chatbot, image_display, txt],
408
  ).then(lambda: gr.Textbox(interactive=True), None, [txt])
409
 
410
- # ground_btn.click(
411
- # lambda: gr.update(value="Ground the main disease in this CXR"), None, txt
412
- # ).then(
413
- # interface.add_message, inputs=[txt, image_display, chatbot], outputs=[chatbot, txt]
414
- # ).then(
415
- # interface.process_message,
416
- # inputs=[txt, image_display, chatbot],
417
- # outputs=[chatbot, image_display, txt],
418
- # ).then(lambda: gr.Textbox(interactive=True), None, [txt])
419
 
420
  segment_btn.click(
421
  lambda: gr.update(value="Segment the major affected lung"), None, txt
@@ -427,21 +433,21 @@ def create_demo(agent, tools_dict):
427
  outputs=[chatbot, image_display, txt],
428
  ).then(lambda: gr.Textbox(interactive=True), None, [txt])
429
 
430
- upload_button.upload(handle_file_upload, inputs=upload_button, outputs=[image_display, analyze_btn, segment_btn])
431
 
432
- dicom_upload.upload(handle_file_upload, inputs=dicom_upload, outputs=[image_display, analyze_btn, segment_btn])
433
 
434
  clear_btn.click(clear_chat, outputs=[chatbot, image_display])
435
- new_thread_btn.click(new_thread, outputs=[chatbot, image_display])
436
  # generate_report_btn.click(generate_report, outputs=[diseases_df, conclusion_tb, approve_btn, reject_btn])
437
- generate_report_btn.click(generate_report, outputs=[conclusion_tb, approve_btn, reject_btn])
438
  approve_btn.click(
439
  build_pdf_and_preview,
440
  # inputs=[diseases_df, conclusion_tb],
441
  inputs=[conclusion_tb],
442
  outputs=[download_pdf_btn, pdf_preview],
443
  )
444
- reject_btn.click(show_reject_ui, outputs=[rejection_text, submit_reject_btn, cancel_reject_btn])
445
- cancel_reject_btn.click(hide_reject_ui, outputs=[rejection_text, submit_reject_btn, cancel_reject_btn])
446
 
447
  return demo
 
255
  with gr.Tabs():
256
  with gr.Tab(label="Image section"):
257
  image_display = gr.Image(
258
+ label="Image", type="filepath", height=685, container=True
259
  )
260
+ # with gr.Row():
261
+ # upload_button = gr.UploadButton(
262
+ # "πŸ“Ž Upload X-Ray",
263
+ # file_types=["image"],
264
+ # )
265
+ # dicom_upload = gr.UploadButton(
266
+ # "πŸ“„ Upload DICOM",
267
+ # file_types=["file"],
268
+ # )
269
  with gr.Row():
270
+ analyze_btn = gr.Button("Analyze 1")
271
+ analyze2_btn = gr.Button("Analyze 2")
272
+ segment_btn = gr.Button("Segment")
 
 
 
 
 
 
 
 
 
273
  with gr.Row():
274
  clear_btn = gr.Button("Clear Chat")
275
+ new_thread_btn = gr.Button("New Patient")
276
 
277
  with gr.Tab(label="Report section"):
278
  generate_report_btn = gr.Button("Generate Report")
 
280
  # headers=["Disease", "Info"],
281
  # datatype=["str", "str"],
282
  # interactive=False, visible=False, max_height=220)
283
+ conclusion_tb = gr.Textbox(label="Conclusion", interactive=False)
284
  with gr.Row():
285
  approve_btn = gr.Button("Approve", visible=False)
286
+ # reject_btn = gr.Button("Reject", visible=False)
287
  download_pdf_btn = gr.DownloadButton(label="πŸ“₯ Download PDF", visible=False)
288
  # pdf_preview = gr.HTML(visible=False)
289
  # pdf_preview = gr.File(visible=False)
290
  pdf_preview = PDF(visible=False)
291
+ # rejection_text = gr.Textbox(
292
+ # show_label=False,
293
+ # visible=False,
294
+ # placeholder="Tell us what is wrong with the report",
295
+ # container=False,
296
+ # interactive=True
297
+ # )
298
+ # with gr.Row():
299
+ # submit_reject_btn = gr.Button("Submit", visible=False)
300
+ # cancel_reject_btn = gr.Button("Cancel", visible=False)
301
 
302
  # Event handlers
303
  def authenticate(username, password):
 
318
 
319
  def new_thread():
320
  interface.current_thread_id = str(time.time())
321
+ return (
322
+ [],
323
+ interface.display_file_path,
324
+ gr.update(value=None, interactive=False),
325
+ gr.update(visible=False),
326
+ # gr.update(visible=False),
327
+ gr.update(value=None, visible=False),
328
+ gr.update(value=None, visible=False)
329
+ )
330
 
331
  def handle_file_upload(file):
332
  return interface.handle_upload(file.name)
333
 
334
  def generate_report():
335
  result = interface.agent.summarize_message(interface.current_thread_id)
 
336
  return (
337
+ gr.update(value=result["Conclusion"], lines=4, interactive=True),
 
 
338
  gr.update(visible=True),
339
+ # gr.update(visible=True),
340
  )
341
 
342
  # def records_to_pdf(table, conclusion) -> Path:
 
413
  outputs=[chatbot, image_display, txt],
414
  ).then(lambda: gr.Textbox(interactive=True), None, [txt])
415
 
416
+ analyze2_btn.click(
417
+ lambda: gr.update(value="Analyze this xray and give me a detailed response. Use the chest_xray_expert tool"), None, txt
418
+ ).then(
419
+ interface.add_message, inputs=[txt, image_display, chatbot], outputs=[chatbot, txt]
420
+ ).then(
421
+ interface.process_message,
422
+ inputs=[txt, image_display, chatbot],
423
+ outputs=[chatbot, image_display, txt],
424
+ ).then(lambda: gr.Textbox(interactive=True), None, [txt])
425
 
426
  segment_btn.click(
427
  lambda: gr.update(value="Segment the major affected lung"), None, txt
 
433
  outputs=[chatbot, image_display, txt],
434
  ).then(lambda: gr.Textbox(interactive=True), None, [txt])
435
 
436
+ # upload_button.upload(handle_file_upload, inputs=upload_button, outputs=[image_display])
437
 
438
+ # dicom_upload.upload(handle_file_upload, inputs=dicom_upload, outputs=[image_display])
439
 
440
  clear_btn.click(clear_chat, outputs=[chatbot, image_display])
441
+ new_thread_btn.click(new_thread, outputs=[chatbot, image_display, conclusion_tb, approve_btn, download_pdf_btn, pdf_preview])
442
  # generate_report_btn.click(generate_report, outputs=[diseases_df, conclusion_tb, approve_btn, reject_btn])
443
+ generate_report_btn.click(generate_report, outputs=[conclusion_tb, approve_btn])
444
  approve_btn.click(
445
  build_pdf_and_preview,
446
  # inputs=[diseases_df, conclusion_tb],
447
  inputs=[conclusion_tb],
448
  outputs=[download_pdf_btn, pdf_preview],
449
  )
450
+ # reject_btn.click(show_reject_ui, outputs=[rejection_text, submit_reject_btn, cancel_reject_btn])
451
+ # cancel_reject_btn.click(hide_reject_ui, outputs=[rejection_text, submit_reject_btn, cancel_reject_btn])
452
 
453
  return demo