updated UI code ✅✅
Browse files- mediSync/app.py +51 -19
mediSync/app.py
CHANGED
@@ -555,19 +555,12 @@ def create_interface():
|
|
555 |
)
|
556 |
|
557 |
with gr.Row():
|
558 |
-
|
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(
|
567 |
label="Appointment ID",
|
568 |
placeholder="Enter your appointment ID here...",
|
569 |
info="This will be automatically populated if you came from the doctors page",
|
570 |
-
value=
|
571 |
elem_id="appointment_id_input"
|
572 |
)
|
573 |
|
@@ -759,32 +752,71 @@ def create_interface():
|
|
759 |
outputs=[end_consultation_status]
|
760 |
)
|
761 |
|
762 |
-
# JavaScript for appointment ID auto-population (
|
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 |
-
|
|
|
772 |
var appointmentId = getUrlParameter('appointment_id');
|
773 |
if (appointmentId) {
|
774 |
-
|
775 |
-
if (input) {
|
776 |
-
input.value = appointmentId;
|
777 |
-
var event = new Event('input', { bubbles: true });
|
778 |
-
input.dispatchEvent(event);
|
779 |
-
}
|
780 |
}
|
781 |
}
|
|
|
|
|
782 |
document.addEventListener('DOMContentLoaded', function() {
|
783 |
-
setTimeout(
|
784 |
});
|
785 |
window.addEventListener('load', function() {
|
786 |
-
setTimeout(
|
787 |
});
|
|
|
|
|
788 |
</script>
|
789 |
""")
|
790 |
|
|
|
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...",
|
562 |
info="This will be automatically populated if you came from the doctors page",
|
563 |
+
value="",
|
564 |
elem_id="appointment_id_input"
|
565 |
)
|
566 |
|
|
|
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');
|
762 |
+
if (input) {
|
763 |
+
input.value = val;
|
764 |
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
765 |
+
return true;
|
766 |
+
}
|
767 |
+
// Try Gradio 4.x shadow DOM
|
768 |
+
var gradioApp = document.querySelector('gradio-app') || document.querySelector('body');
|
769 |
+
if (gradioApp) {
|
770 |
+
// Find textbox by label
|
771 |
+
var labels = gradioApp.querySelectorAll('label');
|
772 |
+
for (var i = 0; i < labels.length; i++) {
|
773 |
+
if (labels[i].textContent.trim().toLowerCase().includes('appointment id')) {
|
774 |
+
// Find the input in the same parent
|
775 |
+
var parent = labels[i].parentElement;
|
776 |
+
var textbox = parent.querySelector('input[type="text"], textarea');
|
777 |
+
if (textbox) {
|
778 |
+
textbox.value = val;
|
779 |
+
textbox.dispatchEvent(new Event('input', { bubbles: true }));
|
780 |
+
return true;
|
781 |
+
}
|
782 |
+
}
|
783 |
+
}
|
784 |
+
}
|
785 |
+
// Try all textboxes for fallback
|
786 |
+
var allInputs = document.querySelectorAll('input[type="text"], textarea');
|
787 |
+
for (var i = 0; i < allInputs.length; i++) {
|
788 |
+
if (allInputs[i].placeholder && allInputs[i].placeholder.toLowerCase().includes('appointment id')) {
|
789 |
+
allInputs[i].value = val;
|
790 |
+
allInputs[i].dispatchEvent(new Event('input', { bubbles: true }));
|
791 |
+
return true;
|
792 |
+
}
|
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 |
""")
|
822 |
|