reupdated code ✅✅
Browse files- mediSync/app.py +1 -68
mediSync/app.py
CHANGED
|
@@ -421,15 +421,8 @@ def create_interface():
|
|
| 421 |
|
| 422 |
# Define interface
|
| 423 |
with gr.Blocks(
|
| 424 |
-
title="MediSync: Multi-Modal Medical Analysis System",
|
| 425 |
-
theme=gr.themes.Soft()
|
| 426 |
) as interface:
|
| 427 |
-
# Get appointment ID from URL parameters if present
|
| 428 |
-
appointment_id = gr.Textbox(
|
| 429 |
-
visible=False,
|
| 430 |
-
value=gr.Request.query_params.get("appointment_id", "")
|
| 431 |
-
)
|
| 432 |
-
|
| 433 |
gr.Markdown("""
|
| 434 |
# MediSync: Multi-Modal Medical Analysis System
|
| 435 |
|
|
@@ -440,7 +433,6 @@ def create_interface():
|
|
| 440 |
1. Upload a chest X-ray image
|
| 441 |
2. Enter the corresponding medical report text
|
| 442 |
3. Choose the analysis type: image-only, text-only, or multimodal (combined)
|
| 443 |
-
4. Click "End Consultation" when finished to complete your appointment
|
| 444 |
""")
|
| 445 |
|
| 446 |
with gr.Tab("Multimodal Analysis"):
|
|
@@ -537,16 +529,6 @@ def create_interface():
|
|
| 537 |
This tool is for educational and research purposes only. It is not intended to provide medical advice or replace professional healthcare. Always consult with qualified healthcare providers for medical decisions.
|
| 538 |
""")
|
| 539 |
|
| 540 |
-
# Consultation completion section
|
| 541 |
-
with gr.Row():
|
| 542 |
-
with gr.Column():
|
| 543 |
-
end_consultation_btn = gr.Button(
|
| 544 |
-
"End Consultation",
|
| 545 |
-
variant="stop",
|
| 546 |
-
size="lg"
|
| 547 |
-
)
|
| 548 |
-
completion_status = gr.HTML()
|
| 549 |
-
|
| 550 |
# Set up event handlers
|
| 551 |
multi_img_enhance.click(
|
| 552 |
app.enhance_image, inputs=multi_img_input, outputs=multi_img_input
|
|
@@ -570,58 +552,9 @@ def create_interface():
|
|
| 570 |
outputs=[text_output, text_results, text_plot],
|
| 571 |
)
|
| 572 |
|
| 573 |
-
# Handle consultation completion
|
| 574 |
-
end_consultation_btn.click(
|
| 575 |
-
fn=complete_consultation,
|
| 576 |
-
inputs=[appointment_id],
|
| 577 |
-
outputs=completion_status
|
| 578 |
-
)
|
| 579 |
-
|
| 580 |
# Run the interface
|
| 581 |
interface.launch()
|
| 582 |
|
| 583 |
-
def complete_consultation(appointment_id):
|
| 584 |
-
"""Handle consultation completion by notifying the Flask app."""
|
| 585 |
-
if not appointment_id:
|
| 586 |
-
return "<div class='alert alert-error'>No appointment ID found. Please contact support.</div>"
|
| 587 |
-
|
| 588 |
-
try:
|
| 589 |
-
# Call your Flask app's completion endpoint
|
| 590 |
-
# Replace with your actual Flask app URL
|
| 591 |
-
flask_app_url = "http://127.0.0.1:600/complete_consultation"
|
| 592 |
-
|
| 593 |
-
response = requests.post(
|
| 594 |
-
flask_app_url,
|
| 595 |
-
json={"appointment_id": appointment_id},
|
| 596 |
-
timeout=10
|
| 597 |
-
)
|
| 598 |
-
|
| 599 |
-
if response.status_code == 200:
|
| 600 |
-
# Return JavaScript to redirect back to the doctors page
|
| 601 |
-
return """
|
| 602 |
-
<div class='alert alert-success'>
|
| 603 |
-
Consultation completed successfully. Redirecting...
|
| 604 |
-
<script>
|
| 605 |
-
setTimeout(function() {
|
| 606 |
-
window.location.href = "http://127.0.0.1:600/doctors";
|
| 607 |
-
}, 2000);
|
| 608 |
-
</script>
|
| 609 |
-
</div>
|
| 610 |
-
"""
|
| 611 |
-
else:
|
| 612 |
-
return f"""
|
| 613 |
-
<div class='alert alert-error'>
|
| 614 |
-
Error completing appointment (Status: {response.status_code}).
|
| 615 |
-
Please contact support.
|
| 616 |
-
</div>
|
| 617 |
-
"""
|
| 618 |
-
|
| 619 |
-
except Exception as e:
|
| 620 |
-
return f"""
|
| 621 |
-
<div class='alert alert-error'>
|
| 622 |
-
Error: {str(e)}
|
| 623 |
-
</div>
|
| 624 |
-
"""
|
| 625 |
|
| 626 |
if __name__ == "__main__":
|
| 627 |
create_interface()
|
|
|
|
| 421 |
|
| 422 |
# Define interface
|
| 423 |
with gr.Blocks(
|
| 424 |
+
title="MediSync: Multi-Modal Medical Analysis System", theme=gr.themes.Soft()
|
|
|
|
| 425 |
) as interface:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
gr.Markdown("""
|
| 427 |
# MediSync: Multi-Modal Medical Analysis System
|
| 428 |
|
|
|
|
| 433 |
1. Upload a chest X-ray image
|
| 434 |
2. Enter the corresponding medical report text
|
| 435 |
3. Choose the analysis type: image-only, text-only, or multimodal (combined)
|
|
|
|
| 436 |
""")
|
| 437 |
|
| 438 |
with gr.Tab("Multimodal Analysis"):
|
|
|
|
| 529 |
This tool is for educational and research purposes only. It is not intended to provide medical advice or replace professional healthcare. Always consult with qualified healthcare providers for medical decisions.
|
| 530 |
""")
|
| 531 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 532 |
# Set up event handlers
|
| 533 |
multi_img_enhance.click(
|
| 534 |
app.enhance_image, inputs=multi_img_input, outputs=multi_img_input
|
|
|
|
| 552 |
outputs=[text_output, text_results, text_plot],
|
| 553 |
)
|
| 554 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 555 |
# Run the interface
|
| 556 |
interface.launch()
|
| 557 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 558 |
|
| 559 |
if __name__ == "__main__":
|
| 560 |
create_interface()
|