updated code ✅✅
Browse files- mediSync/app.py +25 -40
mediSync/app.py
CHANGED
|
@@ -420,32 +420,23 @@ def create_interface():
|
|
| 420 |
RECOMMENDATIONS: Follow-up chest CT to further characterize the nodular opacity in the right lower lobe.
|
| 421 |
"""
|
| 422 |
|
| 423 |
-
# Sample image handling with
|
| 424 |
sample_image_path = None
|
| 425 |
-
fallback_urls = [
|
| 426 |
-
"https://raw.githubusercontent.com/ieee8023/covid-chestxray-dataset/master/images/1-s2.0-S0929664620300449-gr2_lrg-a.jpg",
|
| 427 |
-
"https://raw.githubusercontent.com/ieee8023/covid-chestxray-dataset/master/images/1-s2.0-S0929664620300449-gr1_lrg-a.jpg",
|
| 428 |
-
"https://github.com/ieee8023/covid-chestxray-dataset/raw/master/images/1-s2.0-S0929664620300449-gr3_lrg-a.jpg"
|
| 429 |
-
]
|
| 430 |
-
|
| 431 |
try:
|
| 432 |
sample_images_dir = Path(__file__).parent.parent / "data" / "sample"
|
| 433 |
os.makedirs(sample_images_dir, exist_ok=True)
|
|
|
|
|
|
|
| 434 |
sample_images = list(sample_images_dir.glob("*.png")) + list(sample_images_dir.glob("*.jpg"))
|
| 435 |
|
| 436 |
if not sample_images:
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
sample_image_path = str(sample_path)
|
| 445 |
-
logger.info(f"Successfully downloaded fallback sample image from {url}")
|
| 446 |
-
break
|
| 447 |
-
except Exception as e:
|
| 448 |
-
logger.warning(f"Could not download sample image from {url}: {str(e)}")
|
| 449 |
else:
|
| 450 |
sample_image_path = str(sample_images[0])
|
| 451 |
except Exception as e:
|
|
@@ -476,24 +467,22 @@ def create_interface():
|
|
| 476 |
css=custom_css
|
| 477 |
) as interface:
|
| 478 |
|
| 479 |
-
# Appointment ID handling
|
| 480 |
-
appointment_id = gr.Textbox(visible=False
|
| 481 |
-
|
| 482 |
-
#
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
|
|
|
| 490 |
|
| 491 |
-
# Initialize appointment ID from URL
|
| 492 |
interface.load(
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
None,
|
| 496 |
-
_js=js_code
|
| 497 |
)
|
| 498 |
|
| 499 |
gr.Markdown("""
|
|
@@ -597,15 +586,11 @@ def create_interface():
|
|
| 597 |
)
|
| 598 |
|
| 599 |
def complete_consultation(appointment_id):
|
| 600 |
-
"""Handle consultation completion with improved error handling."""
|
| 601 |
if not appointment_id:
|
| 602 |
error_html = """
|
| 603 |
<div class="alert-box alert-error">
|
| 604 |
<strong>No Appointment ID Found</strong>
|
| 605 |
<p>Your session may not be properly recorded.</p>
|
| 606 |
-
<script>
|
| 607 |
-
setTimeout(() => window.location.href = "http://127.0.0.1:600/doctors", 3000);
|
| 608 |
-
</script>
|
| 609 |
</div>
|
| 610 |
"""
|
| 611 |
logger.error("Completion attempted without appointment ID")
|
|
@@ -624,7 +609,7 @@ def create_interface():
|
|
| 624 |
<strong>Consultation Completed</strong>
|
| 625 |
<p>You will be redirected shortly.</p>
|
| 626 |
<script>
|
| 627 |
-
setTimeout(() => window.location.href = "http://127.0.0.1:600/
|
| 628 |
</script>
|
| 629 |
</div>
|
| 630 |
"""
|
|
|
|
| 420 |
RECOMMENDATIONS: Follow-up chest CT to further characterize the nodular opacity in the right lower lobe.
|
| 421 |
"""
|
| 422 |
|
| 423 |
+
# Sample image handling with local fallback
|
| 424 |
sample_image_path = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
try:
|
| 426 |
sample_images_dir = Path(__file__).parent.parent / "data" / "sample"
|
| 427 |
os.makedirs(sample_images_dir, exist_ok=True)
|
| 428 |
+
|
| 429 |
+
# First check for existing local images
|
| 430 |
sample_images = list(sample_images_dir.glob("*.png")) + list(sample_images_dir.glob("*.jpg"))
|
| 431 |
|
| 432 |
if not sample_images:
|
| 433 |
+
# Use local fallback if no images exist
|
| 434 |
+
local_fallback = Path(__file__).parent.parent / "static" / "fallback_xray.jpg"
|
| 435 |
+
if local_fallback.exists():
|
| 436 |
+
sample_image_path = str(local_fallback)
|
| 437 |
+
logger.info("Using local fallback sample image")
|
| 438 |
+
else:
|
| 439 |
+
logger.warning("No local fallback image found")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 440 |
else:
|
| 441 |
sample_image_path = str(sample_images[0])
|
| 442 |
except Exception as e:
|
|
|
|
| 467 |
css=custom_css
|
| 468 |
) as interface:
|
| 469 |
|
| 470 |
+
# Appointment ID handling - simplified approach
|
| 471 |
+
appointment_id = gr.Textbox(visible=False)
|
| 472 |
+
|
| 473 |
+
# Initialize appointment ID from URL using Gradio's built-in method
|
| 474 |
+
def get_appointment_id():
|
| 475 |
+
try:
|
| 476 |
+
from gradio.context import Context
|
| 477 |
+
if hasattr(Context, 'request') and hasattr(Context.request, 'query_params'):
|
| 478 |
+
return Context.request.query_params.get("appointment_id", "")
|
| 479 |
+
except Exception as e:
|
| 480 |
+
logger.warning(f"Could not get URL parameters: {str(e)}")
|
| 481 |
+
return ""
|
| 482 |
|
|
|
|
| 483 |
interface.load(
|
| 484 |
+
fn=get_appointment_id,
|
| 485 |
+
outputs=[appointment_id]
|
|
|
|
|
|
|
| 486 |
)
|
| 487 |
|
| 488 |
gr.Markdown("""
|
|
|
|
| 586 |
)
|
| 587 |
|
| 588 |
def complete_consultation(appointment_id):
|
|
|
|
| 589 |
if not appointment_id:
|
| 590 |
error_html = """
|
| 591 |
<div class="alert-box alert-error">
|
| 592 |
<strong>No Appointment ID Found</strong>
|
| 593 |
<p>Your session may not be properly recorded.</p>
|
|
|
|
|
|
|
|
|
|
| 594 |
</div>
|
| 595 |
"""
|
| 596 |
logger.error("Completion attempted without appointment ID")
|
|
|
|
| 609 |
<strong>Consultation Completed</strong>
|
| 610 |
<p>You will be redirected shortly.</p>
|
| 611 |
<script>
|
| 612 |
+
setTimeout(() => window.location.href = "http://127.0.0.1:600/doctors", 2000);
|
| 613 |
</script>
|
| 614 |
</div>
|
| 615 |
"""
|