Spaces:
Runtime error
Runtime error
updated code ✅✅
Browse files398 unmodified lines39940040140240240340440514 unmodified lines4204214224234244254264274284294304314324334344354364304314324334344354364374384394404374384394404414424434444454464474484494504514 unmodified lines45645745845946046146213 unmodified lines47647747847947047148048148248348448548648748848949049149249349449547647747847948048148249649749849977 unmodified lines57757857958058158258313 unmodified lines5975985996006015866026035886046056066076086096106116126136146156166176186195975986206216226236006246256266026276286296306316326336346356366376386086396406416426436446456466146476486496506513 unmodified lines655656657658624659660661662663664627665398 unmodified lines
def create_interface(): """Create and launch the Gradio interface.""" """Create and launch the Gradio interface with all fixes.""" app = MediSyncApp()
example_report = """14 unmodified lines RECOMMENDATIONS: Follow-up chest CT to further characterize the nodular opacity in the right lower lobe. """
# Sample image handling with multiple fallback options sample_image_path = None fallback_urls = [ "https://raw.githubusercontent.com/ieee8023/covid-chestxray-dataset/master/images/1-s2.0-S0929664620300449-gr2_lrg-a.jpg", "https://raw.githubusercontent.com/ieee8023/covid-chestxray-dataset/master/images/1-s2.0-S0929664620300449-gr1_lrg-a.jpg", "https://github.com/ieee8023/covid-chestxray-dataset/raw/master/images/1-s2.0-S0929664620300449-gr3_lrg-a.jpg" ] try: sample_images_dir = Path(__file__).parent.parent / "data" / "sample" os.makedirs(sample_images_dir, exist_ok=True) sample_images = list(sample_images_dir.glob("*.png")) + list(sample_images_dir.glob("*.jpg")) if not sample_images: fallback_url = "https://raw.githubusercontent.com/ieee8023/covid-chestxray-dataset/master/images/1-s2.0-S0929664620300449-gr2_lrg-a.jpg" sample_path = sample_images_dir / "sample_xray.jpg" try: response = requests.get(fallback_url, timeout=10) if response.status_code == 200: with open(sample_path, 'wb') as f: f.write(response.content) sample_image_path = str(sample_path) logger.info("Downloaded fallback sample image") except Exception as e: logger.warning(f"Could not download sample image: {str(e)}") for i, url in enumerate(fallback_urls): try: sample_path = sample_images_dir / f"sample_xray_{i}.jpg" response = requests.get(url, timeout=10) if response.status_code == 200: with open(sample_path, 'wb') as f: f.write(response.content) sample_image_path = str(sample_path) logger.info(f"Successfully downloaded fallback sample image from {url}") break except Exception as e: logger.warning(f"Could not download sample image from {url}: {str(e)}") else: sample_image_path = str(sample_images[0]) except Exception as e:4 unmodified lines padding: 15px; margin: 10px 0; border-radius: 5px; font-family: sans-serif; } .alert-error { background-color: #ffebee;13 unmodified lines css=custom_css ) as interface: # Appointment ID handling with both Python and JavaScript fallback appointment_id = gr.Textbox(visible=False)
appointment_id = gr.Textbox(visible=False, elem_id="appointment-id")
# JavaScript to extract appointment ID from URL js_code = """ function getAppointmentId() { const urlParams = new URLSearchParams(window.location.search); return urlParams.get('appointment_id') || ''; } document.getElementById('appointment-id').value = getAppointmentId(); """ # Initialize appointment ID from URL interface.load( None, None, None, _js=""" function getAppointmentId() { const urlParams = new URLSearchParams(window.location.search); return urlParams.get('appointment_id') || ''; } document.getElementById('appointment-id').value = getAppointmentId(); """ _js=js_code )
gr.Markdown("""77 unmodified lines end_consultation_btn = gr.Button("End Consultation", variant="stop", size="lg") completion_status = gr.HTML()
# Event handlers multi_img_enhance.click(app.enhance_image, inputs=multi_img_input, outputs=multi_img_input) multi_analyze_btn.click( app.analyze_multimodal,13 unmodified lines )
def complete_consultation(appointment_id): """Handle consultation completion with improved error handling.""" if not appointment_id: return """ error_html = """ <div class="alert-box alert-error"> No appointment ID found. Please contact support. <strong>No Appointment ID Found</strong> <p>Your session may not be properly recorded.</p> <script> setTimeout(() => window.location.href = "http://127.0.0.1:600/doctors", 3000); </script> </div> """ logger.error("Completion attempted without appointment ID") return error_html try: response = requests.post( "http://127.0.0.1:600/complete_consultation", json={"appointment_id": appointment_id}, timeout=10 ) if response.status_code == 200: return """
if response.ok: success_html = """ <div class="alert-box alert-success"> Consultation completed successfully. Redirecting... <strong>Consultation Completed</strong> <p>You will be redirected shortly.</p> <script> setTimeout(() => window.location.href = "http://127.0.0.1:600/doctors", 2000); setTimeout(() => window.location.href = "http://127.0.0.1:600/complete_appointment", 2000); </script> </div> """ logger.info(f"Successfully completed appointment {appointment_id}") return success_html error_msg = f"Server error: {response.status_code}" if response.text: error_msg += f" - {response.text[:200]}" logger.error(error_msg) return f""" <div class="alert-box alert-error"> Error completing appointment (Status: {response.status_code}). <strong>Error Completing Appointment</strong> <p>{error_msg}</p> </div> """ except Exception as e: logger.error(f"Completion error: {str(e)}") return f""" <div class="alert-box alert-error"> Error: {str(e)} <strong>Connection Error</strong> <p>{str(e)}</p> </div> """
3 unmodified lines outputs=[completion_status] )
try: interface.launch() interface.launch() except Exception as e: logger.error(f"Failed to launch interface: {str(e)}") raise
if __name__ == "__main__": create_interface() create_interface()mediSync/app.py+69-31