blackshadow1 commited on
Commit
44d2cac
·
verified ·
1 Parent(s): d423df8

updated UI code ✅✅

Browse files
Files changed (1) hide show
  1. mediSync/app.py +34 -80
mediSync/app.py CHANGED
@@ -533,14 +533,24 @@ def create_interface():
533
  """,
534
  elem_id="medisync-header"
535
  )
536
-
537
  with gr.Row():
538
- # --- Appointment ID auto-population logic: always leave value blank, use JS to set value after render ---
 
 
 
 
 
 
 
 
 
 
539
  appointment_id_input = gr.Textbox(
540
  label="Appointment ID",
541
  placeholder="Enter your appointment ID here...",
542
  info="This will be automatically populated if you came from the doctors page",
543
- value="", # Always blank, let JS set value after render
544
  elem_id="appointment_id_input"
545
  )
546
 
@@ -729,89 +739,33 @@ def create_interface():
729
  outputs=[end_consultation_status]
730
  )
731
 
732
- # --- Improved JavaScript for appointment ID auto-population ---
733
- # This script will robustly set the value of the Gradio textbox, even in Gradio 4.x shadow DOM.
734
  gr.HTML("""
735
  <script>
736
- (function() {
737
- function getUrlParameter(name) {
738
- name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
739
- var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
740
- var results = regex.exec(window.location.search);
741
- return results === null ? '' : decodeURIComponent(results[1].replace(/\\+/g, ' '));
742
- }
743
-
744
- function setAppointmentIdValue(val) {
745
- // Try by element id (Gradio 3.x and some 4.x)
746
  var input = document.getElementById('appointment_id_input');
747
  if (input) {
748
- input.value = val;
749
- input.dispatchEvent(new Event('input', { bubbles: true }));
750
- input.dispatchEvent(new Event('change', { bubbles: true }));
751
- return true;
752
- }
753
- // Try Gradio 4.x shadow DOM
754
- var gradioApp = document.querySelector('gradio-app');
755
- if (gradioApp && gradioApp.shadowRoot) {
756
- // Try to find textbox by label text
757
- var labels = gradioApp.shadowRoot.querySelectorAll('label');
758
- for (var i = 0; i < labels.length; i++) {
759
- if (labels[i].textContent.trim().toLowerCase().includes('appointment id')) {
760
- // Find the input in the same parent
761
- var parent = labels[i].parentElement;
762
- var textbox = parent.querySelector('input[type="text"], textarea');
763
- if (textbox) {
764
- textbox.value = val;
765
- textbox.dispatchEvent(new Event('input', { bubbles: true }));
766
- textbox.dispatchEvent(new Event('change', { bubbles: true }));
767
- return true;
768
- }
769
- }
770
- }
771
- // Fallback: try all textboxes in shadowRoot
772
- var allInputs = gradioApp.shadowRoot.querySelectorAll('input[type="text"], textarea');
773
- for (var i = 0; i < allInputs.length; i++) {
774
- if (allInputs[i].placeholder && allInputs[i].placeholder.toLowerCase().includes('appointment id')) {
775
- allInputs[i].value = val;
776
- allInputs[i].dispatchEvent(new Event('input', { bubbles: true }));
777
- allInputs[i].dispatchEvent(new Event('change', { bubbles: true }));
778
- return true;
779
- }
780
- }
781
- }
782
- // Try all textboxes for fallback (outside shadow DOM)
783
- var allInputs = document.querySelectorAll('input[type="text"], textarea');
784
- for (var i = 0; i < allInputs.length; i++) {
785
- if (allInputs[i].placeholder && allInputs[i].placeholder.toLowerCase().includes('appointment id')) {
786
- allInputs[i].value = val;
787
- allInputs[i].dispatchEvent(new Event('input', { bubbles: true }));
788
- allInputs[i].dispatchEvent(new Event('change', { bubbles: true }));
789
- return true;
790
- }
791
  }
792
- return false;
793
  }
794
-
795
- function tryPopulateAppointmentId() {
796
- var appointmentId = getUrlParameter('appointment_id');
797
- if (appointmentId) {
798
- setAppointmentIdValue(appointmentId);
799
- }
800
- }
801
-
802
- // Try multiple times and on different events for robustness
803
- document.addEventListener('DOMContentLoaded', function() {
804
- setTimeout(tryPopulateAppointmentId, 200);
805
- setTimeout(tryPopulateAppointmentId, 800);
806
- });
807
- window.addEventListener('load', function() {
808
- setTimeout(tryPopulateAppointmentId, 1200);
809
- });
810
- // Also try periodically for 3 seconds
811
- for (let t = 0; t <= 3000; t += 400) {
812
- setTimeout(tryPopulateAppointmentId, t);
813
- }
814
- })();
815
  </script>
816
  """)
817
 
 
533
  """,
534
  elem_id="medisync-header"
535
  )
536
+
537
  with gr.Row():
538
+ import urllib.parse
539
+ try:
540
+ url_params = {}
541
+ if hasattr(gr, 'get_current_url'):
542
+ current_url = gr.get_current_url()
543
+ if current_url:
544
+ parsed = urllib.parse.urlparse(current_url)
545
+ url_params = urllib.parse.parse_qs(parsed.query)
546
+ default_appointment_id = url_params.get('appointment_id', [''])[0]
547
+ except:
548
+ default_appointment_id = ""
549
  appointment_id_input = gr.Textbox(
550
  label="Appointment ID",
551
  placeholder="Enter your appointment ID here...",
552
  info="This will be automatically populated if you came from the doctors page",
553
+ value=default_appointment_id,
554
  elem_id="appointment_id_input"
555
  )
556
 
 
739
  outputs=[end_consultation_status]
740
  )
741
 
742
+ # --- Appointment ID auto-population logic (copied from template in working_hugging_face_code.py) ---
743
+ # # JavaScript for appointment ID auto-population
744
  gr.HTML("""
745
  <script>
746
+ function getUrlParameter(name) {
747
+ name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
748
+ var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
749
+ var results = regex.exec(location.search);
750
+ return results === null ? '' : decodeURIComponent(results[1].replace(/\\+/g, ' '));
751
+ }
752
+ function populateAppointmentId() {
753
+ var appointmentId = getUrlParameter('appointment_id');
754
+ if (appointmentId) {
 
755
  var input = document.getElementById('appointment_id_input');
756
  if (input) {
757
+ input.value = appointmentId;
758
+ var event = new Event('input', { bubbles: true });
759
+ input.dispatchEvent(event);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
760
  }
 
761
  }
762
+ }
763
+ document.addEventListener('DOMContentLoaded', function() {
764
+ setTimeout(populateAppointmentId, 800);
765
+ });
766
+ window.addEventListener('load', function() {
767
+ setTimeout(populateAppointmentId, 1200);
768
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
769
  </script>
770
  """)
771