blackshadow1 commited on
Commit
4b107df
·
verified ·
1 Parent(s): 82dc143

updated code ✅✅

Browse files
Files changed (1) hide show
  1. mediSync/app.py +17 -39
mediSync/app.py CHANGED
@@ -402,7 +402,7 @@ def create_interface():
402
  """Create and launch the Gradio interface with all fixes implemented."""
403
  app = MediSyncApp()
404
 
405
- # Example medical report for demo
406
  example_report = """
407
  CHEST X-RAY EXAMINATION
408
 
@@ -421,32 +421,15 @@ def create_interface():
421
  RECOMMENDATIONS: Follow-up chest CT to further characterize the nodular opacity in the right lower lobe.
422
  """
423
 
424
- # Get sample image path with robust error handling
425
  sample_image_path = None
426
  try:
427
  sample_images_dir = Path(__file__).parent.parent / "data" / "sample"
428
  os.makedirs(sample_images_dir, exist_ok=True)
429
-
430
- # Check for existing images first
431
  sample_images = list(sample_images_dir.glob("*.png")) + list(sample_images_dir.glob("*.jpg"))
432
-
433
- if not sample_images:
434
- # Use reliable fallback image URL
435
- fallback_url = "https://raw.githubusercontent.com/ieee8023/covid-chestxray-dataset/master/images/1-s2.0-S0929664620300449-gr2_lrg-a.jpg"
436
- sample_path = sample_images_dir / "sample_xray.jpg"
437
- try:
438
- response = requests.get(fallback_url, timeout=10)
439
- if response.status_code == 200:
440
- with open(sample_path, 'wb') as f:
441
- f.write(response.content)
442
- sample_image_path = str(sample_path)
443
- logging.info("Successfully downloaded fallback sample image")
444
- else:
445
- logging.warning("Failed to download sample image")
446
- except Exception as e:
447
- logging.warning(f"Could not download sample image: {str(e)}")
448
- else:
449
  sample_image_path = str(sample_images[0])
 
450
  except Exception as e:
451
  logging.error(f"Error setting up sample images: {str(e)}")
452
 
@@ -454,21 +437,19 @@ def create_interface():
454
  title="MediSync: Multi-Modal Medical Analysis System",
455
  theme=gr.themes.Soft()
456
  ) as interface:
457
- # Appointment ID handling with JavaScript workaround
458
  appointment_id = gr.Textbox(visible=False, value="")
459
 
460
- # Load appointment ID from URL when interface loads
461
- interface.load(
462
- fn=lambda: "",
463
- outputs=appointment_id,
464
- _js="""
465
- function() {
466
- const params = new URLSearchParams(window.location.search);
467
- return params.get('appointment_id') || '';
468
- }
469
- """
470
- )
471
 
 
472
  gr.Markdown("""
473
  # MediSync: Multi-Modal Medical Analysis System
474
 
@@ -482,23 +463,19 @@ def create_interface():
482
  4. Click "End Consultation" when finished to complete your appointment
483
  """)
484
 
 
485
  with gr.Tab("Multimodal Analysis"):
486
  with gr.Row():
487
  with gr.Column():
488
  multi_img_input = gr.Image(label="Upload X-ray Image", type="pil")
489
  multi_img_enhance = gr.Button("Enhance Image")
490
-
491
  multi_text_input = gr.Textbox(
492
  label="Enter Medical Report Text",
493
  placeholder="Enter the radiologist's report text here...",
494
  lines=10,
495
  value=example_report if not sample_image_path else None,
496
  )
497
-
498
- multi_analyze_btn = gr.Button(
499
- "Analyze Image & Text", variant="primary"
500
- )
501
-
502
  with gr.Column():
503
  multi_results = gr.HTML(label="Analysis Results")
504
  multi_plot = gr.HTML(label="Visualization")
@@ -510,6 +487,7 @@ def create_interface():
510
  label="Example X-ray and Report",
511
  )
512
 
 
513
  with gr.Tab("Image Analysis"):
514
  with gr.Row():
515
  with gr.Column():
 
402
  """Create and launch the Gradio interface with all fixes implemented."""
403
  app = MediSyncApp()
404
 
405
+ # Example medical report for demo (unchanged)
406
  example_report = """
407
  CHEST X-RAY EXAMINATION
408
 
 
421
  RECOMMENDATIONS: Follow-up chest CT to further characterize the nodular opacity in the right lower lobe.
422
  """
423
 
424
+ # Updated image handling - only use local files
425
  sample_image_path = None
426
  try:
427
  sample_images_dir = Path(__file__).parent.parent / "data" / "sample"
428
  os.makedirs(sample_images_dir, exist_ok=True)
 
 
429
  sample_images = list(sample_images_dir.glob("*.png")) + list(sample_images_dir.glob("*.jpg"))
430
+ if sample_images:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
431
  sample_image_path = str(sample_images[0])
432
+ logging.info(f"Using local sample image: {sample_image_path}")
433
  except Exception as e:
434
  logging.error(f"Error setting up sample images: {str(e)}")
435
 
 
437
  title="MediSync: Multi-Modal Medical Analysis System",
438
  theme=gr.themes.Soft()
439
  ) as interface:
440
+ # Updated appointment ID handling
441
  appointment_id = gr.Textbox(visible=False, value="")
442
 
443
+ # New initialization function for appointment ID
444
+ @interface.load(inputs=[], outputs=[appointment_id])
445
+ def load_id():
446
+ try:
447
+ from flask import request
448
+ return request.args.get('appointment_id', '')
449
+ except:
450
+ return ""
 
 
 
451
 
452
+ # Unchanged interface sections
453
  gr.Markdown("""
454
  # MediSync: Multi-Modal Medical Analysis System
455
 
 
463
  4. Click "End Consultation" when finished to complete your appointment
464
  """)
465
 
466
+ # Unchanged tab definitions
467
  with gr.Tab("Multimodal Analysis"):
468
  with gr.Row():
469
  with gr.Column():
470
  multi_img_input = gr.Image(label="Upload X-ray Image", type="pil")
471
  multi_img_enhance = gr.Button("Enhance Image")
 
472
  multi_text_input = gr.Textbox(
473
  label="Enter Medical Report Text",
474
  placeholder="Enter the radiologist's report text here...",
475
  lines=10,
476
  value=example_report if not sample_image_path else None,
477
  )
478
+ multi_analyze_btn = gr.Button("Analyze Image & Text", variant="primary")
 
 
 
 
479
  with gr.Column():
480
  multi_results = gr.HTML(label="Analysis Results")
481
  multi_plot = gr.HTML(label="Visualization")
 
487
  label="Example X-ray and Report",
488
  )
489
 
490
+
491
  with gr.Tab("Image Analysis"):
492
  with gr.Row():
493
  with gr.Column():