blackshadow1 commited on
Commit
e96d834
·
verified ·
1 Parent(s): ade4e03

updated the UI code ✅✅

Browse files
Files changed (1) hide show
  1. mediSync/app.py +35 -66
mediSync/app.py CHANGED
@@ -7,47 +7,6 @@ import requests
7
  import gradio as gr
8
  import matplotlib.pyplot as plt
9
  from PIL import Image
10
- import logging
11
- import os
12
- import sys
13
- import tempfile
14
- from pathlib import Path
15
-
16
- import gradio as gr
17
- import matplotlib.pyplot as plt
18
- from PIL import Image
19
-
20
- # Add parent directory to path
21
- parent_dir = os.path.dirname(os.path.abspath(__file__))
22
- sys.path.append(parent_dir)
23
-
24
- # Import our modules
25
- from models.multimodal_fusion import MultimodalFusion
26
- from utils.preprocessing import enhance_xray_image, normalize_report_text
27
- from utils.visualization import (
28
- plot_image_prediction,
29
- plot_multimodal_results,
30
- plot_report_entities,
31
- )
32
- # Set up logging
33
- logging.basicConfig(
34
- level=logging.INFO,
35
- format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
36
- handlers=[logging.StreamHandler(), logging.FileHandler("mediSync.log")],
37
- )
38
- logger = logging.getLogger(__name__)
39
-
40
- # Create temporary directory for sample data if it doesn't exist
41
- os.makedirs(os.path.join(parent_dir, "data", "sample"), exist_ok=True)
42
- import logging
43
- import os
44
- import sys
45
- import tempfile
46
- from pathlib import Path
47
- import requests
48
- import gradio as gr
49
- import matplotlib.pyplot as plt
50
- from PIL import Image
51
 
52
  # Import configuration for end consultation logic
53
  try:
@@ -527,6 +486,26 @@ def create_interface():
527
  #end_consultation_status button:active, #end_consultation_status button:focus {
528
  outline: 2px solid #00bfae !important;
529
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
530
  """
531
  ) as interface:
532
  gr.Markdown(
@@ -555,7 +534,6 @@ def create_interface():
555
  )
556
 
557
  with gr.Row():
558
- # The value will be set by JS, so leave it empty here
559
  appointment_id_input = gr.Textbox(
560
  label="Appointment ID",
561
  placeholder="Enter your appointment ID here...",
@@ -697,12 +675,12 @@ def create_interface():
697
  <h3 style="color: #28a745;">✅ Consultation Completed Successfully!</h3>
698
  <p style="color: #28a745;">✔️ {result['message']}</p>
699
  <p>Your appointment has been marked as completed.</p>
700
- <button onclick="window.open('{doctors_urls['local']}', '_blank')"
701
- style="background-color: #00bfae; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; margin-top: 10px;">
702
  Return to Doctors Page (Local)
703
  </button>
704
- <button onclick="window.open('{doctors_urls['production']}', '_blank')"
705
- style="background-color: #6c63ff; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; margin-top: 10px; margin-left: 10px;">
706
  Return to Doctors Page (Production)
707
  </button>
708
  </div>
@@ -721,16 +699,13 @@ def create_interface():
721
  <li>Manually complete the appointment using the appointment ID</li>
722
  </ol>
723
  <div style="margin-top: 15px;">
724
- <button onclick="window.open('http://127.0.0.1:600/complete_appointment_manual?appointment_id={appointment_id.strip()}', '_blank')"
725
- style="background-color: #00bfae; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; margin-right: 10px;">
726
  Complete Appointment
727
  </button>
728
- <button onclick="window.open('http://127.0.0.1:600/doctors', '_blank')"
729
- style="background-color: #6c63ff; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; margin-right: 10px;">
730
  Return to Doctors Page
731
  </button>
732
- <button onclick="navigator.clipboard.writeText('{appointment_id.strip()}')"
733
- style="background-color: #23272f; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer;">
734
  Copy Appointment ID
735
  </button>
736
  </div>
@@ -752,10 +727,15 @@ def create_interface():
752
  outputs=[end_consultation_status]
753
  )
754
 
755
- # JavaScript for appointment ID auto-population (improved for Gradio 4.x and all browsers)
756
  gr.HTML("""
757
  <script>
758
- // Try to robustly set the appointment ID textbox value, supporting Gradio 3.x/4.x and shadow DOM
 
 
 
 
 
759
  function setAppointmentIdValue(val) {
760
  // Try by ID (Gradio 3.x and some 4.x)
761
  var input = document.getElementById('appointment_id_input');
@@ -793,29 +773,18 @@ def create_interface():
793
  }
794
  return false;
795
  }
796
-
797
- function getUrlParameter(name) {
798
- name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
799
- var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
800
- var results = regex.exec(window.location.search);
801
- return results === null ? '' : decodeURIComponent(results[1].replace(/\\+/g, ' '));
802
- }
803
-
804
  function tryPopulateAppointmentId() {
805
  var appointmentId = getUrlParameter('appointment_id');
806
  if (appointmentId) {
807
  setAppointmentIdValue(appointmentId);
808
  }
809
  }
810
-
811
- // Try on DOMContentLoaded, on load, and after a delay to ensure Gradio is ready
812
  document.addEventListener('DOMContentLoaded', function() {
813
  setTimeout(tryPopulateAppointmentId, 400);
814
  });
815
  window.addEventListener('load', function() {
816
  setTimeout(tryPopulateAppointmentId, 1000);
817
  });
818
- // Also try again after 2 seconds in case Gradio loads slowly
819
  setTimeout(tryPopulateAppointmentId, 2000);
820
  </script>
821
  """)
@@ -823,4 +792,4 @@ def create_interface():
823
  interface.launch()
824
 
825
  if __name__ == "__main__":
826
- create_interface()
 
7
  import gradio as gr
8
  import matplotlib.pyplot as plt
9
  from PIL import Image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  # Import configuration for end consultation logic
12
  try:
 
486
  #end_consultation_status button:active, #end_consultation_status button:focus {
487
  outline: 2px solid #00bfae !important;
488
  }
489
+ #end_consultation_status .btn-green {
490
+ background-color: #00bfae !important;
491
+ color: #fff !important;
492
+ }
493
+ #end_consultation_status .btn-purple {
494
+ background-color: #6c63ff !important;
495
+ color: #fff !important;
496
+ }
497
+ #end_consultation_status .btn-dark {
498
+ background-color: #23272f !important;
499
+ color: #fff !important;
500
+ }
501
+ #end_consultation_status .btn-orange {
502
+ background-color: #ff9800 !important;
503
+ color: #fff !important;
504
+ }
505
+ #end_consultation_status .btn-red {
506
+ background-color: #dc3545 !important;
507
+ color: #fff !important;
508
+ }
509
  """
510
  ) as interface:
511
  gr.Markdown(
 
534
  )
535
 
536
  with gr.Row():
 
537
  appointment_id_input = gr.Textbox(
538
  label="Appointment ID",
539
  placeholder="Enter your appointment ID here...",
 
675
  <h3 style="color: #28a745;">✅ Consultation Completed Successfully!</h3>
676
  <p style="color: #28a745;">✔️ {result['message']}</p>
677
  <p>Your appointment has been marked as completed.</p>
678
+ <button class="btn-green" onclick="window.open('{doctors_urls['local']}', '_blank')"
679
+ style="margin-top: 10px;">
680
  Return to Doctors Page (Local)
681
  </button>
682
+ <button class="btn-purple" onclick="window.open('{doctors_urls['production']}', '_blank')"
683
+ style="margin-top: 10px; margin-left: 10px;">
684
  Return to Doctors Page (Production)
685
  </button>
686
  </div>
 
699
  <li>Manually complete the appointment using the appointment ID</li>
700
  </ol>
701
  <div style="margin-top: 15px;">
702
+ <button class="btn-green" onclick="window.open('http://127.0.0.1:600/complete_appointment_manual?appointment_id={appointment_id.strip()}', '_blank')" style="margin-right: 10px;">
 
703
  Complete Appointment
704
  </button>
705
+ <button class="btn-purple" onclick="window.open('http://127.0.0.1:600/doctors', '_blank')" style="margin-right: 10px;">
 
706
  Return to Doctors Page
707
  </button>
708
+ <button class="btn-dark" onclick="navigator.clipboard.writeText('{appointment_id.strip()}')">
 
709
  Copy Appointment ID
710
  </button>
711
  </div>
 
727
  outputs=[end_consultation_status]
728
  )
729
 
730
+ # JavaScript for appointment ID auto-population (as in working_hugging_face_code.py)
731
  gr.HTML("""
732
  <script>
733
+ function getUrlParameter(name) {
734
+ name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
735
+ var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
736
+ var results = regex.exec(window.location.search);
737
+ return results === null ? '' : decodeURIComponent(results[1].replace(/\\+/g, ' '));
738
+ }
739
  function setAppointmentIdValue(val) {
740
  // Try by ID (Gradio 3.x and some 4.x)
741
  var input = document.getElementById('appointment_id_input');
 
773
  }
774
  return false;
775
  }
 
 
 
 
 
 
 
 
776
  function tryPopulateAppointmentId() {
777
  var appointmentId = getUrlParameter('appointment_id');
778
  if (appointmentId) {
779
  setAppointmentIdValue(appointmentId);
780
  }
781
  }
 
 
782
  document.addEventListener('DOMContentLoaded', function() {
783
  setTimeout(tryPopulateAppointmentId, 400);
784
  });
785
  window.addEventListener('load', function() {
786
  setTimeout(tryPopulateAppointmentId, 1000);
787
  });
 
788
  setTimeout(tryPopulateAppointmentId, 2000);
789
  </script>
790
  """)
 
792
  interface.launch()
793
 
794
  if __name__ == "__main__":
795
+ create_interface()