Spaces:
Runtime error
Runtime error
updated the UI code ✅✅
Browse files6 unmodified lines7891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253473 unmodified lines52752852953053153222 unmodified lines555556557558559560561135 unmodified lines69769869970070170270370470570670770812 unmodified lines72172272372472572672772872973073173273373473573615 unmodified lines75275375475575675775875976076131 unmodified lines7937947957967977987998008018028038048058068078088098108118128138148158168178188198208211 unmodified line8238248258266 unmodified linesimport gradio as grimport matplotlib.pyplot as pltfrom PIL import Imageimport loggingimport osimport sysimport tempfilefrom pathlib import Pathimport gradio as grimport matplotlib.pyplot as pltfrom PIL import Image# Add parent directory to pathparent_dir = os.path.dirname(os.path.abspath(__file__))sys.path.append(parent_dir)# Import our modulesfrom models.multimodal_fusion import MultimodalFusionfrom utils.preprocessing import enhance_xray_image, normalize_report_textfrom utils.visualization import (plot_image_prediction,plot_multimodal_results,plot_report_entities,)# Set up logginglogging.basicConfig(level=logging.INFO,format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",handlers=[logging.StreamHandler(), logging.FileHandler("mediSync.log")],)logger = logging.getLogger(__name__)# Create temporary directory for sample data if it doesn't existos.makedirs(os.path.join(parent_dir, "data", "sample"), exist_ok=True)import loggingimport osimport sysimport tempfilefrom pathlib import Pathimport requestsimport gradio as grimport matplotlib.pyplot as pltfrom PIL import Image# Import configuration for end consultation logictry:473 unmodified lines#end_consultation_status button:active, #end_consultation_status button:focus {outline: 2px solid #00bfae !important;}""") as interface:gr.Markdown(22 unmodified lines)with gr.Row():# The value will be set by JS, so leave it empty hereappointment_id_input = gr.Textbox(label="Appointment ID",placeholder="Enter your appointment ID here...",135 unmodified lines<h3 style="color: #28a745;">✅ Consultation Completed Successfully!</h3><p style="color: #28a745;">✔️ {result['message']}</p><p>Your appointment has been marked as completed.</p><button onclick="window.open('{doctors_urls['local']}', '_blank')"style="background-color: #00bfae; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; margin-top: 10px;">Return to Doctors Page (Local)</button><button onclick="window.open('{doctors_urls['production']}', '_blank')"style="background-color: #6c63ff; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; margin-top: 10px; margin-left: 10px;">Return to Doctors Page (Production)</button></div>12 unmodified lines<li>Manually complete the appointment using the appointment ID</li></ol><div style="margin-top: 15px;"><button onclick="window.open('http://127.0.0.1:600/complete_appointment_manual?appointment_id={appointment_id.strip()}', '_blank')"style="background-color: #00bfae; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; margin-right: 10px;">Complete Appointment</button><button onclick="window.open('http://127.0.0.1:600/doctors', '_blank')"style="background-color: #6c63ff; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; margin-right: 10px;">Return to Doctors Page</button><button onclick="navigator.clipboard.writeText('{appointment_id.strip()}')"style="background-color: #23272f; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer;">Copy Appointment ID</button></div>15 unmodified linesoutputs=[end_consultation_status])# JavaScript for appointment ID auto-population (improved for Gradio 4.x and all browsers)gr.HTML("""<script>// Try to robustly set the appointment ID textbox value, supporting Gradio 3.x/4.x and shadow DOMfunction setAppointmentIdValue(val) {// Try by ID (Gradio 3.x and some 4.x)var input = document.getElementById('appointment_id_input');31 unmodified lines}return false;}function getUrlParameter(name) {name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');var results = regex.exec(window.location.search);return results === null ? '' : decodeURIComponent(results[1].replace(/\\+/g, ' '));}function tryPopulateAppointmentId() {var appointmentId = getUrlParameter('appointment_id');if (appointmentId) {setAppointmentIdValue(appointmentId);}}// Try on DOMContentLoaded, on load, and after a delay to ensure Gradio is readydocument.addEventListener('DOMContentLoaded', function() {setTimeout(tryPopulateAppointmentId, 400);});window.addEventListener('load', function() {setTimeout(tryPopulateAppointmentId, 1000);});// Also try again after 2 seconds in case Gradio loads slowlysetTimeout(tryPopulateAppointmentId, 2000);</script>""")1 unmodified lineinterface.launch()if __name__ == "__main__":create_interface()6 unmodified lines789101112473 unmodified lines48648748848949049149249349449549649749849950050150250350450550650750850951051122 unmodified lines534535536537538539135 unmodified lines67567667767867968068168268368468568612 unmodified lines69970070170270370470570670770870971071115 unmodified lines72772872973073173273373473573673773873974074131 unmodified lines7737747757767777787797807817827837847857867877887897901 unmodified line7927937947956 unmodified linesimport gradio as grimport matplotlib.pyplot as pltfrom PIL import Image# Import configuration for end consultation logictry:473 unmodified lines#end_consultation_status button:active, #end_consultation_status button:focus {outline: 2px solid #00bfae !important;}#end_consultation_status .btn-green {background-color: #00bfae !important;color: #fff !important;}#end_consultation_status .btn-purple {background-color: #6c63ff !important;color: #fff !important;}#end_consultation_status .btn-dark {background-color: #23272f !important;color: #fff !important;}#end_consultation_status .btn-orange {background-color: #ff9800 !important;color: #fff !important;}#end_consultation_status .btn-red {background-color: #dc3545 !important;color: #fff !important;}""") as interface:gr.Markdown(22 unmodified lines)with gr.Row():appointment_id_input = gr.Textbox(label="Appointment ID",placeholder="Enter your appointment ID here...",135 unmodified lines<h3 style="color: #28a745;">✅ Consultation Completed Successfully!</h3><p style="color: #28a745;">✔️ {result['message']}</p><p>Your appointment has been marked as completed.</p><button class="btn-green" onclick="window.open('{doctors_urls['local']}', '_blank')"style="margin-top: 10px;">Return to Doctors Page (Local)</button><button class="btn-purple" onclick="window.open('{doctors_urls['production']}', '_blank')"style="margin-top: 10px; margin-left: 10px;">Return to Doctors Page (Production)</button></div>12 unmodified lines<li>Manually complete the appointment using the appointment ID</li></ol><div style="margin-top: 15px;"><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;">Complete Appointment</button><button class="btn-purple" onclick="window.open('http://127.0.0.1:600/doctors', '_blank')" style="margin-right: 10px;">Return to Doctors Page</button><button class="btn-dark" onclick="navigator.clipboard.writeText('{appointment_id.strip()}')">Copy Appointment ID</button></div>15 unmodified linesoutputs=[end_consultation_status])# JavaScript for appointment ID auto-population (as in working_hugging_face_code.py)gr.HTML("""<script>function getUrlParameter(name) {name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');var results = regex.exec(window.location.search);return results === null ? '' : decodeURIComponent(results[1].replace(/\\+/g, ' '));}function setAppointmentIdValue(val) {// Try by ID (Gradio 3.x and some 4.x)var input = document.getElementById('appointment_id_input');31 unmodified lines}return false;}function tryPopulateAppointmentId() {var appointmentId = getUrlParameter('appointment_id');if (appointmentId) {setAppointmentIdValue(appointmentId);}}document.addEventListener('DOMContentLoaded', function() {setTimeout(tryPopulateAppointmentId, 400);});window.addEventListener('load', function() {setTimeout(tryPopulateAppointmentId, 1000);});setTimeout(tryPopulateAppointmentId, 2000);</script>""")1 unmodified lineinterface.launch()if __name__ == "__main__":create_interface()
mediSync/app.py+35-66