SmartHeal commited on
Commit
ade675f
·
verified ·
1 Parent(s): afbe010

Update src/ui_components_original.py

Browse files
Files changed (1) hide show
  1. src/ui_components_original.py +38 -4
src/ui_components_original.py CHANGED
@@ -61,7 +61,8 @@ def standalone_run_analysis(
61
  mode, existing_label,
62
  np_name, np_age, np_gender,
63
  w_loc, w_dur, pain, moist, infect, diabetic,
64
- prev_tx, med_hist, meds, alls, notes, img_path
 
65
  ):
66
  """Runs in the ZeroGPU worker; returns HTML for the UI."""
67
  def _label_to_id(label: str):
@@ -183,6 +184,9 @@ def standalone_run_analysis(
183
  'additional_notes': notes
184
  }
185
 
 
 
 
186
  # Run AI
187
  analysis_result = wound_analyzer.analyze_wound(img_path, q_for_ai)
188
  if not analysis_result or not analysis_result.get("success"):
@@ -669,6 +673,9 @@ button.gr-button:hover, button.gr-button-primary:hover {
669
  with gr.Column(scale=1):
670
  gr.HTML("<h3>📸 Wound Image</h3>")
671
  wound_image = gr.Image(label="Upload Wound Image", type="filepath")
 
 
 
672
  gr.HTML("<h3>📝 Medical History</h3>")
673
  previous_treatment = gr.Textbox(label="Previous Treatment", lines=3)
674
  medical_history = gr.Textbox(label="Medical History", lines=3)
@@ -864,18 +871,34 @@ button.gr-button:hover, button.gr-button-primary:hover {
864
  outputs=[new_patient_group, existing_patient_dd]
865
  )
866
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
867
  # --- IMPORTANT: call standalone GPU function via lambda to pass instance/ctx ---
868
  analyze_btn.click(
869
- fn=lambda mode, ex_lbl, np_n, np_a, np_g, wl, wd, p, m, i, d, pt, mh, med, al, nt, img: \
870
  standalone_run_analysis(
871
  self, self.current_user, self.database_manager, self.wound_analyzer,
872
- mode, ex_lbl, np_n, np_a, np_g, wl, wd, p, m, i, d, pt, mh, med, al, nt, img
873
  ),
874
  inputs=[
875
  patient_mode, existing_patient_dd,
876
  new_patient_name, new_patient_age, new_patient_gender,
877
  wound_location, wound_duration, pain_level, moisture_level, infection_signs, diabetic_status,
878
- previous_treatment, medical_history, medications, allergies, additional_notes, wound_image
879
  ],
880
  outputs=[analysis_output]
881
  )
@@ -900,6 +923,9 @@ button.gr-button:hover, button.gr-button-primary:hover {
900
  saved_image_path = analysis_result.get('saved_image_path', '')
901
 
902
  wound_type = visual_analysis.get('wound_type', 'Unknown')
 
 
 
903
  length_cm = visual_analysis.get('length_cm', 0)
904
  breadth_cm = visual_analysis.get('breadth_cm', 0)
905
  area_cm2 = visual_analysis.get('surface_area_cm2', 0)
@@ -1007,6 +1033,14 @@ button.gr-button:hover, button.gr-button-primary:hover {
1007
  <h3 style="color: #3182ce; margin: 0 0 10px 0;">Location</h3>
1008
  <p style="font-weight: 600; font-size: 18px; color: #2d3748; margin: 0;">{html.escape(str(questionnaire_data.get('wound_location', 'Not specified')))}</p>
1009
  </div>
 
 
 
 
 
 
 
 
1010
  </div>
1011
  </div>
1012
 
 
61
  mode, existing_label,
62
  np_name, np_age, np_gender,
63
  w_loc, w_dur, pain, moist, infect, diabetic,
64
+ prev_tx, med_hist, meds, alls, notes, img_path,
65
+ manual_annotation=None
66
  ):
67
  """Runs in the ZeroGPU worker; returns HTML for the UI."""
68
  def _label_to_id(label: str):
 
184
  'additional_notes': notes
185
  }
186
 
187
+ # Include manual annotation (mask) in questionnaire for AI
188
+ if manual_annotation is not None:
189
+ q_for_ai['manual_mask'] = manual_annotation
190
  # Run AI
191
  analysis_result = wound_analyzer.analyze_wound(img_path, q_for_ai)
192
  if not analysis_result or not analysis_result.get("success"):
 
673
  with gr.Column(scale=1):
674
  gr.HTML("<h3>📸 Wound Image</h3>")
675
  wound_image = gr.Image(label="Upload Wound Image", type="filepath")
676
+ # Manual annotation field: user can draw wound boundary if model fails
677
+ gr.HTML("<h3>✏️ Manual Annotation (optional)</h3>")
678
+ manual_annotation = gr.Image(label="Draw wound boundary", tool="sketch", type="pil", interactive=True)
679
  gr.HTML("<h3>📝 Medical History</h3>")
680
  previous_treatment = gr.Textbox(label="Previous Treatment", lines=3)
681
  medical_history = gr.Textbox(label="Medical History", lines=3)
 
871
  outputs=[new_patient_group, existing_patient_dd]
872
  )
873
 
874
+ # Keep manual annotation preview in sync with uploaded image
875
+ def _update_annotation_preview(path):
876
+ try:
877
+ if not path:
878
+ return None
879
+ from PIL import Image
880
+ return Image.open(path).convert("RGB")
881
+ except Exception:
882
+ return None
883
+
884
+ wound_image.change(
885
+ _update_annotation_preview,
886
+ inputs=[wound_image],
887
+ outputs=[manual_annotation]
888
+ )
889
+
890
  # --- IMPORTANT: call standalone GPU function via lambda to pass instance/ctx ---
891
  analyze_btn.click(
892
+ fn=lambda mode, ex_lbl, np_n, np_a, np_g, wl, wd, p, m, i, d, pt, mh, med, al, nt, img, annot: \
893
  standalone_run_analysis(
894
  self, self.current_user, self.database_manager, self.wound_analyzer,
895
+ mode, ex_lbl, np_n, np_a, np_g, wl, wd, p, m, i, d, pt, mh, med, al, nt, img, annot
896
  ),
897
  inputs=[
898
  patient_mode, existing_patient_dd,
899
  new_patient_name, new_patient_age, new_patient_gender,
900
  wound_location, wound_duration, pain_level, moisture_level, infection_signs, diabetic_status,
901
+ previous_treatment, medical_history, medications, allergies, additional_notes, wound_image, manual_annotation
902
  ],
903
  outputs=[analysis_output]
904
  )
 
923
  saved_image_path = analysis_result.get('saved_image_path', '')
924
 
925
  wound_type = visual_analysis.get('wound_type', 'Unknown')
926
+ skin_tone_label = visual_analysis.get('skin_tone_label', 'Unknown')
927
+ ita_degrees = visual_analysis.get('ita_degrees', 0)
928
+ tissue_type = visual_analysis.get('tissue_type', 'Unknown')
929
  length_cm = visual_analysis.get('length_cm', 0)
930
  breadth_cm = visual_analysis.get('breadth_cm', 0)
931
  area_cm2 = visual_analysis.get('surface_area_cm2', 0)
 
1033
  <h3 style="color: #3182ce; margin: 0 0 10px 0;">Location</h3>
1034
  <p style="font-weight: 600; font-size: 18px; color: #2d3748; margin: 0;">{html.escape(str(questionnaire_data.get('wound_location', 'Not specified')))}</p>
1035
  </div>
1036
+ <div style="background: white; padding: 20px; border-radius: 8px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
1037
+ <h3 style="color: #3182ce; margin: 0 0 10px 0;">Skin Tone</h3>
1038
+ <p style="font-weight: 600; font-size: 18px; color: #2d3748; margin: 0;">{html.escape(str(skin_tone_label))} ({ita_degrees:.1f}°)</p>
1039
+ </div>
1040
+ <div style="background: white; padding: 20px; border-radius: 8px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
1041
+ <h3 style="color: #3182ce; margin: 0 0 10px 0;">Tissue Type</h3>
1042
+ <p style="font-weight: 600; font-size: 18px; color: #2d3748; margin: 0;">{html.escape(str(tissue_type))}</p>
1043
+ </div>
1044
  </div>
1045
  </div>
1046