blackshadow1 commited on
Commit
4c93748
·
verified ·
1 Parent(s): b88f42c

updated UI code ✅✅

Browse files
Files changed (1) hide show
  1. mediSync/app.py +24 -28
mediSync/app.py CHANGED
@@ -29,16 +29,6 @@ from utils.visualization import (
29
  plot_multimodal_results,
30
  plot_report_entities,
31
  )
32
- import logging
33
- import os
34
- import sys
35
- import tempfile
36
- from pathlib import Path
37
- import requests
38
- import gradio as gr
39
- import matplotlib.pyplot as plt
40
- from PIL import Image
41
-
42
  # Set up logging
43
  logging.basicConfig(
44
  level=logging.INFO,
@@ -49,6 +39,15 @@ logger = logging.getLogger(__name__)
49
 
50
  # Create temporary directory for sample data if it doesn't exist
51
  os.makedirs(os.path.join(parent_dir, "data", "sample"), exist_ok=True)
 
 
 
 
 
 
 
 
 
52
 
53
  # Import configuration for end consultation logic
54
  try:
@@ -559,12 +558,9 @@ def create_interface():
559
  import urllib.parse
560
  try:
561
  url_params = {}
562
- if hasattr(gr, 'get_current_url'):
563
- current_url = gr.get_current_url()
564
- if current_url:
565
- parsed = urllib.parse.urlparse(current_url)
566
- url_params = urllib.parse.parse_qs(parsed.query)
567
- default_appointment_id = url_params.get('appointment_id', [''])[0]
568
  except:
569
  default_appointment_id = ""
570
  appointment_id_input = gr.Textbox(
@@ -697,7 +693,7 @@ def create_interface():
697
  )
698
 
699
  def handle_end_consultation(appointment_id):
700
- # Output status: keep text black, simple, no color or theme
701
  if not appointment_id or appointment_id.strip() == "":
702
  return "<div style='color: #000; background: #fff; padding: 10px; border-radius: 5px;'>Please enter your appointment ID first.</div>"
703
  result = complete_appointment(appointment_id.strip())
@@ -705,15 +701,15 @@ def create_interface():
705
  doctors_urls = get_doctors_page_urls()
706
  html_response = f"""
707
  <div style='color: #000; background: #fff; padding: 15px; border-radius: 5px; margin: 10px 0;'>
708
- <h3 style="color: #000;">✅ Consultation Completed Successfully!</h3>
709
- <p>✔️ {result['message']}</p>
710
  <p>Your appointment has been marked as completed.</p>
711
  <button onclick="window.open('{doctors_urls['local']}', '_blank')"
712
- style="background-color: #00bfae; color: white; padding: 8px 18px; border: none; border-radius: 6px; cursor: pointer; margin-top: 10px;">
713
  Return to Doctors Page (Local)
714
  </button>
715
  <button onclick="window.open('{doctors_urls['production']}', '_blank')"
716
- style="background-color: #6c63ff; color: white; padding: 8px 18px; border: none; border-radius: 6px; cursor: pointer; margin-top: 10px; margin-left: 10px;">
717
  Return to Doctors Page (Production)
718
  </button>
719
  </div>
@@ -722,7 +718,7 @@ def create_interface():
722
  if "Cannot connect to Flask app" in result['message']:
723
  html_response = f"""
724
  <div style='color: #000; background: #fff; padding: 15px; border-radius: 5px; margin: 10px 0;'>
725
- <h3 style="color: #000;">⚠️ Consultation Ready to Complete</h3>
726
  <p>Your consultation analysis is complete! However, we cannot automatically mark your appointment as completed because the Flask app is not accessible from this environment.</p>
727
  <p><strong>Appointment ID:</strong> {appointment_id.strip()}</p>
728
  <p><strong>Next Steps:</strong></p>
@@ -733,15 +729,15 @@ def create_interface():
733
  </ol>
734
  <div style="margin-top: 15px;">
735
  <button onclick="window.open('http://127.0.0.1:600/complete_appointment_manual?appointment_id={appointment_id.strip()}', '_blank')"
736
- style="background-color: #00bfae; color: white; padding: 8px 18px; border: none; border-radius: 6px; cursor: pointer; margin-right: 10px;">
737
  Complete Appointment
738
  </button>
739
  <button onclick="window.open('http://127.0.0.1:600/doctors', '_blank')"
740
- style="background-color: #6c63ff; color: white; padding: 8px 18px; border: none; border-radius: 6px; cursor: pointer; margin-right: 10px;">
741
  Return to Doctors Page
742
  </button>
743
  <button onclick="navigator.clipboard.writeText('{appointment_id.strip()}')"
744
- style="background-color: #23272f; color: white; padding: 8px 18px; border: none; border-radius: 6px; cursor: pointer;">
745
  Copy Appointment ID
746
  </button>
747
  </div>
@@ -750,7 +746,7 @@ def create_interface():
750
  else:
751
  html_response = f"""
752
  <div style='color: #000; background: #fff; padding: 15px; border-radius: 5px; margin: 10px 0;'>
753
- <h3 style="color: #000;">❌ Error Completing Consultation</h3>
754
  <p>{result['message']}</p>
755
  <p>Please try again or contact support if the problem persists.</p>
756
  </div>
@@ -763,13 +759,13 @@ def create_interface():
763
  outputs=[end_consultation_status]
764
  )
765
 
766
- # JavaScript for appointment ID auto-population
767
  gr.HTML("""
768
  <script>
769
  function getUrlParameter(name) {
770
  name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
771
  var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
772
- var results = regex.exec(location.search);
773
  return results === null ? '' : decodeURIComponent(results[1].replace(/\\+/g, ' '));
774
  }
775
  function populateAppointmentId() {
 
29
  plot_multimodal_results,
30
  plot_report_entities,
31
  )
 
 
 
 
 
 
 
 
 
 
32
  # Set up logging
33
  logging.basicConfig(
34
  level=logging.INFO,
 
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:
 
558
  import urllib.parse
559
  try:
560
  url_params = {}
561
+ # Use window.location.search if available, fallback to gradio's get_current_url
562
+ # This logic is for server-side, so we will use a placeholder and rely on JS for actual population
563
+ default_appointment_id = ""
 
 
 
564
  except:
565
  default_appointment_id = ""
566
  appointment_id_input = gr.Textbox(
 
693
  )
694
 
695
  def handle_end_consultation(appointment_id):
696
+ # Output status: styled with color for buttons and clear status box, as per template
697
  if not appointment_id or appointment_id.strip() == "":
698
  return "<div style='color: #000; background: #fff; padding: 10px; border-radius: 5px;'>Please enter your appointment ID first.</div>"
699
  result = complete_appointment(appointment_id.strip())
 
701
  doctors_urls = get_doctors_page_urls()
702
  html_response = f"""
703
  <div style='color: #000; background: #fff; padding: 15px; border-radius: 5px; margin: 10px 0;'>
704
+ <h3 style="color: #28a745;">✅ Consultation Completed Successfully!</h3>
705
+ <p style="color: #28a745;">✔️ {result['message']}</p>
706
  <p>Your appointment has been marked as completed.</p>
707
  <button onclick="window.open('{doctors_urls['local']}', '_blank')"
708
+ style="background-color: #00bfae; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; margin-top: 10px;">
709
  Return to Doctors Page (Local)
710
  </button>
711
  <button onclick="window.open('{doctors_urls['production']}', '_blank')"
712
+ style="background-color: #6c63ff; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; margin-top: 10px; margin-left: 10px;">
713
  Return to Doctors Page (Production)
714
  </button>
715
  </div>
 
718
  if "Cannot connect to Flask app" in result['message']:
719
  html_response = f"""
720
  <div style='color: #000; background: #fff; padding: 15px; border-radius: 5px; margin: 10px 0;'>
721
+ <h3 style="color: #ff9800;">⚠️ Consultation Ready to Complete</h3>
722
  <p>Your consultation analysis is complete! However, we cannot automatically mark your appointment as completed because the Flask app is not accessible from this environment.</p>
723
  <p><strong>Appointment ID:</strong> {appointment_id.strip()}</p>
724
  <p><strong>Next Steps:</strong></p>
 
729
  </ol>
730
  <div style="margin-top: 15px;">
731
  <button onclick="window.open('http://127.0.0.1:600/complete_appointment_manual?appointment_id={appointment_id.strip()}', '_blank')"
732
+ style="background-color: #00bfae; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; margin-right: 10px;">
733
  Complete Appointment
734
  </button>
735
  <button onclick="window.open('http://127.0.0.1:600/doctors', '_blank')"
736
+ style="background-color: #6c63ff; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; margin-right: 10px;">
737
  Return to Doctors Page
738
  </button>
739
  <button onclick="navigator.clipboard.writeText('{appointment_id.strip()}')"
740
+ style="background-color: #23272f; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer;">
741
  Copy Appointment ID
742
  </button>
743
  </div>
 
746
  else:
747
  html_response = f"""
748
  <div style='color: #000; background: #fff; padding: 15px; border-radius: 5px; margin: 10px 0;'>
749
+ <h3 style="color: #dc3545;">❌ Error Completing Consultation</h3>
750
  <p>{result['message']}</p>
751
  <p>Please try again or contact support if the problem persists.</p>
752
  </div>
 
759
  outputs=[end_consultation_status]
760
  )
761
 
762
+ # JavaScript for appointment ID auto-population (reference template logic)
763
  gr.HTML("""
764
  <script>
765
  function getUrlParameter(name) {
766
  name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
767
  var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
768
+ var results = regex.exec(window.location.search);
769
  return results === null ? '' : decodeURIComponent(results[1].replace(/\\+/g, ' '));
770
  }
771
  function populateAppointmentId() {