updated code UI ✅✅
Browse files- mediSync/app.py +36 -14
mediSync/app.py
CHANGED
@@ -544,6 +544,18 @@ def create_interface():
|
|
544 |
elem_id="appointment_id_input"
|
545 |
)
|
546 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
547 |
with gr.Tab("🧬 Multimodal Analysis"):
|
548 |
with gr.Row():
|
549 |
with gr.Column():
|
@@ -729,7 +741,7 @@ def create_interface():
|
|
729 |
outputs=[end_consultation_status]
|
730 |
)
|
731 |
|
732 |
-
# ---
|
733 |
gr.HTML("""
|
734 |
<script>
|
735 |
function getUrlParameter(name) {
|
@@ -738,26 +750,36 @@ def create_interface():
|
|
738 |
var results = regex.exec(window.location.search);
|
739 |
return results === null ? '' : decodeURIComponent(results[1].replace(/\\+/g, ' '));
|
740 |
}
|
741 |
-
function
|
742 |
var appointmentId = getUrlParameter('appointment_id');
|
743 |
-
var
|
744 |
-
if (
|
|
|
|
|
|
|
|
|
|
|
745 |
input.value = appointmentId;
|
746 |
-
|
747 |
-
|
748 |
-
input.dispatchEvent(event);
|
749 |
-
var event2 = new Event('change', { bubbles: true });
|
750 |
-
input.dispatchEvent(event2);
|
751 |
}
|
752 |
}
|
753 |
-
//
|
754 |
-
setInterval(
|
755 |
-
|
756 |
-
window.addEventListener('
|
757 |
-
|
|
|
758 |
</script>
|
759 |
""")
|
760 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
761 |
interface.launch()
|
762 |
|
763 |
if __name__ == "__main__":
|
|
|
544 |
elem_id="appointment_id_input"
|
545 |
)
|
546 |
|
547 |
+
# Populate appointment id from URL on initial load using server-side request (robust, no JS dependency)
|
548 |
+
def _populate_appointment_id_on_load(request: gr.Request):
|
549 |
+
try:
|
550 |
+
params = getattr(request, "query_params", {}) or {}
|
551 |
+
appointment_id = params.get("appointment_id", "")
|
552 |
+
if appointment_id:
|
553 |
+
return gr.update(value=appointment_id)
|
554 |
+
return gr.update()
|
555 |
+
except Exception as e:
|
556 |
+
logger.warning(f"Could not populate appointment_id from URL: {e}")
|
557 |
+
return gr.update()
|
558 |
+
|
559 |
with gr.Tab("🧬 Multimodal Analysis"):
|
560 |
with gr.Row():
|
561 |
with gr.Column():
|
|
|
741 |
outputs=[end_consultation_status]
|
742 |
)
|
743 |
|
744 |
+
# --- Client-side fallback: update the underlying input/textarea inside the Gradio container ---
|
745 |
gr.HTML("""
|
746 |
<script>
|
747 |
function getUrlParameter(name) {
|
|
|
750 |
var results = regex.exec(window.location.search);
|
751 |
return results === null ? '' : decodeURIComponent(results[1].replace(/\\+/g, ' '));
|
752 |
}
|
753 |
+
function setAppointmentIdFallback() {
|
754 |
var appointmentId = getUrlParameter('appointment_id');
|
755 |
+
var container = document.getElementById('appointment_id_input');
|
756 |
+
if (!container || !appointmentId) return;
|
757 |
+
var input = container.querySelector('input, textarea');
|
758 |
+
if (!input && container.shadowRoot) {
|
759 |
+
input = container.shadowRoot.querySelector('input, textarea');
|
760 |
+
}
|
761 |
+
if (input && input.value !== appointmentId) {
|
762 |
input.value = appointmentId;
|
763 |
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
764 |
+
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
|
|
|
|
|
765 |
}
|
766 |
}
|
767 |
+
// Try to apply once on load and occasionally afterward in case Gradio re-renders
|
768 |
+
const fallbackInterval = setInterval(setAppointmentIdFallback, 1000);
|
769 |
+
window.addEventListener('DOMContentLoaded', setAppointmentIdFallback);
|
770 |
+
window.addEventListener('load', setAppointmentIdFallback);
|
771 |
+
// Stop after some time to avoid running forever (10s)
|
772 |
+
setTimeout(() => clearInterval(fallbackInterval), 10000);
|
773 |
</script>
|
774 |
""")
|
775 |
|
776 |
+
# Server-side load event to populate appointment id reliably
|
777 |
+
interface.load(
|
778 |
+
_populate_appointment_id_on_load,
|
779 |
+
inputs=None,
|
780 |
+
outputs=appointment_id_input
|
781 |
+
)
|
782 |
+
|
783 |
interface.launch()
|
784 |
|
785 |
if __name__ == "__main__":
|