SmartHeal commited on
Commit
62e1e3e
Β·
verified Β·
1 Parent(s): 08a022d

Update src/ui_components_original.py

Browse files
Files changed (1) hide show
  1. src/ui_components_original.py +43 -99
src/ui_components_original.py CHANGED
@@ -58,25 +58,11 @@ def standalone_run_analysis(
58
  database_manager,
59
  wound_analyzer,
60
  # UI inputs
61
- mode,
62
- existing_label,
63
- np_name,
64
- np_age,
65
- np_gender,
66
- w_loc,
67
- w_dur,
68
- pain,
69
- moist,
70
- infect,
71
- diabetic,
72
- prev_tx,
73
- med_hist,
74
- meds,
75
- alls,
76
- notes,
77
- img_path,
78
- manual_mask_path=None,
79
- mask_adjustment=0,
80
  ):
81
  """Runs in the ZeroGPU worker; returns HTML for the UI."""
82
  def _label_to_id(label: str):
@@ -197,13 +183,14 @@ def standalone_run_analysis(
197
  'medications': meds,
198
  'additional_notes': notes
199
  }
200
- # Include optional manual mask and adjustment in questionnaire data
201
- if manual_mask_path:
202
- q_for_ai['manual_mask_path'] = manual_mask_path
203
- q_for_ai['mask_adjustment'] = mask_adjustment
204
 
205
- # Run AI
206
- analysis_result = wound_analyzer.analyze_wound(img_path, q_for_ai)
 
 
 
 
 
207
  if not analysis_result or not analysis_result.get("success"):
208
  err = (analysis_result or {}).get("error", "Unknown analysis error")
209
  return f"<div class='status-error'>❌ AI Analysis failed: {html.escape(str(err))}</div>"
@@ -688,26 +675,31 @@ button.gr-button:hover, button.gr-button-primary:hover {
688
  with gr.Column(scale=1):
689
  gr.HTML("<h3>πŸ“Έ Wound Image</h3>")
690
  wound_image = gr.Image(label="Upload Wound Image", type="filepath")
691
- gr.HTML("<h3>πŸ“ Medical History</h3>")
692
- previous_treatment = gr.Textbox(label="Previous Treatment", lines=3)
693
- medical_history = gr.Textbox(label="Medical History", lines=3)
694
- medications = gr.Textbox(label="Current Medications", lines=2)
695
- allergies = gr.Textbox(label="Known Allergies", lines=2)
696
- additional_notes = gr.Textbox(label="Additional Notes", lines=3)
697
-
698
- # Optional manual segmentation mask and adjustment
699
- manual_mask = gr.Image(
700
  label="Manual Segmentation Mask (optional)",
701
  type="filepath",
702
- interactive=True
 
703
  )
704
- mask_adjustment = gr.Slider(
705
- -10,
706
- 10,
 
 
 
707
  value=0,
708
  step=1,
709
- label="Segmentation Adjustment (neg = shrink, pos = expand)"
 
710
  )
 
 
 
 
 
 
711
 
712
  analyze_btn = gr.Button("πŸ”¬ Analyze Wound", variant="primary", elem_id="analyze-btn")
713
  analysis_output = gr.HTML("")
@@ -899,54 +891,21 @@ button.gr-button:hover, button.gr-button-primary:hover {
899
 
900
  # --- IMPORTANT: call standalone GPU function via lambda to pass instance/ctx ---
901
  analyze_btn.click(
902
- fn=lambda mode, ex_lbl, np_n, np_a, np_g, wl, wd, p, m, i, d, pt, mh, med, al, nt, img, man_mask, mask_adj: \
 
903
  standalone_run_analysis(
904
- self,
905
- self.current_user,
906
- self.database_manager,
907
- self.wound_analyzer,
908
- mode,
909
- ex_lbl,
910
- np_n,
911
- np_a,
912
- np_g,
913
- wl,
914
- wd,
915
- p,
916
- m,
917
- i,
918
- d,
919
- pt,
920
- mh,
921
- med,
922
- al,
923
- nt,
924
- img,
925
- man_mask,
926
- mask_adj
927
  ),
928
  inputs=[
929
- patient_mode,
930
- existing_patient_dd,
931
- new_patient_name,
932
- new_patient_age,
933
- new_patient_gender,
934
- wound_location,
935
- wound_duration,
936
- pain_level,
937
- moisture_level,
938
- infection_signs,
939
- diabetic_status,
940
- previous_treatment,
941
- medical_history,
942
- medications,
943
- allergies,
944
- additional_notes,
945
- wound_image,
946
- manual_mask,
947
- mask_adjustment,
948
  ],
949
- outputs=[analysis_output],
950
  )
951
 
952
  history_btn.click(load_history, outputs=[patient_history_output])
@@ -972,10 +931,7 @@ button.gr-button:hover, button.gr-button-primary:hover {
972
  length_cm = visual_analysis.get('length_cm', 0)
973
  breadth_cm = visual_analysis.get('breadth_cm', 0)
974
  area_cm2 = visual_analysis.get('surface_area_cm2', 0)
975
- # Skin tone and tissue classification
976
- skin_tone_label = visual_analysis.get('skin_tone_label', 'Unknown')
977
- ita_degrees = visual_analysis.get('ita_degrees', 0.0)
978
- tissue_type = visual_analysis.get('tissue_type', 'Unknown')
979
 
980
  detection_image_path = visual_analysis.get('detection_image_path', '')
981
  segmentation_image_path = visual_analysis.get('segmentation_image_path', '')
@@ -1067,26 +1023,14 @@ button.gr-button:hover, button.gr-button-primary:hover {
1067
  <div style="background: #f8f9fa; padding: 30px; border-radius: 12px; margin-bottom: 30px;">
1068
  <h2 style="color: #2d3748; margin-top: 0;">πŸ” Wound Detection & Classification</h2>
1069
  <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin: 20px 0;">
1070
- <!-- Wound Type -->
1071
  <div style="background: white; padding: 20px; border-radius: 8px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
1072
  <h3 style="color: #3182ce; margin: 0 0 10px 0;">Wound Type</h3>
1073
  <p style="font-weight: 600; font-size: 18px; color: #2d3748; margin: 0;">{html.escape(str(wound_type))}</p>
1074
  </div>
1075
- <!-- Location -->
1076
  <div style="background: white; padding: 20px; border-radius: 8px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
1077
  <h3 style="color: #3182ce; margin: 0 0 10px 0;">Location</h3>
1078
  <p style="font-weight: 600; font-size: 18px; color: #2d3748; margin: 0;">{html.escape(str(questionnaire_data.get('wound_location', 'Not specified')))}</p>
1079
  </div>
1080
- <!-- Skin Tone -->
1081
- <div style="background: white; padding: 20px; border-radius: 8px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
1082
- <h3 style="color: #3182ce; margin: 0 0 10px 0;">Skin Tone</h3>
1083
- <p style="font-weight: 600; font-size: 18px; color: #2d3748; margin: 0;">{html.escape(str(skin_tone_label))} ({ita_degrees:.1f}Β°)</p>
1084
- </div>
1085
- <!-- Tissue Type -->
1086
- <div style="background: white; padding: 20px; border-radius: 8px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
1087
- <h3 style="color: #3182ce; margin: 0 0 10px 0;">Tissue Type</h3>
1088
- <p style="font-weight: 600; font-size: 18px; color: #2d3748; margin: 0;">{html.escape(str(tissue_type))}</p>
1089
- </div>
1090
  </div>
1091
  </div>
1092
 
 
58
  database_manager,
59
  wound_analyzer,
60
  # UI inputs
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
+ , seg_adjust=0.0, manual_mask=None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  ):
67
  """Runs in the ZeroGPU worker; returns HTML for the UI."""
68
  def _label_to_id(label: str):
 
183
  'medications': meds,
184
  'additional_notes': notes
185
  }
 
 
 
 
186
 
187
+ # Run AI with optional segmentation adjustment and manual mask
188
+ analysis_result = wound_analyzer.analyze_wound(
189
+ img_path,
190
+ q_for_ai,
191
+ seg_adjust=seg_adjust or 0.0,
192
+ manual_mask_path=manual_mask if manual_mask else None
193
+ )
194
  if not analysis_result or not analysis_result.get("success"):
195
  err = (analysis_result or {}).get("error", "Unknown analysis error")
196
  return f"<div class='status-error'>❌ AI Analysis failed: {html.escape(str(err))}</div>"
 
675
  with gr.Column(scale=1):
676
  gr.HTML("<h3>πŸ“Έ Wound Image</h3>")
677
  wound_image = gr.Image(label="Upload Wound Image", type="filepath")
678
+ # Optional manual segmentation mask provided by the clinician. This allows clinicians
679
+ # to manually mark the wound boundary after the automatic segmentation has run.
680
+ manual_mask_input = gr.Image(
 
 
 
 
 
 
681
  label="Manual Segmentation Mask (optional)",
682
  type="filepath",
683
+ optional=True,
684
+ interactive=True,
685
  )
686
+ # Slider to adjust the automatic segmentation mask. Positive values dilate
687
+ # (expand) the mask, negative values erode (shrink) it. The value represents
688
+ # roughly percentage change where each 5 units corresponds to one iteration.
689
+ seg_adjust_slider = gr.Slider(
690
+ minimum=-20,
691
+ maximum=20,
692
  value=0,
693
  step=1,
694
+ label="Segmentation Adjustment",
695
+ info="Adjust the automatic segmentation (negative shrinks, positive expands)"
696
  )
697
+ gr.HTML("<h3>πŸ“ Medical History</h3>")
698
+ previous_treatment = gr.Textbox(label="Previous Treatment", lines=3)
699
+ medical_history = gr.Textbox(label="Medical History", lines=3)
700
+ medications = gr.Textbox(label="Current Medications", lines=2)
701
+ allergies = gr.Textbox(label="Known Allergies", lines=2)
702
+ additional_notes = gr.Textbox(label="Additional Notes", lines=3)
703
 
704
  analyze_btn = gr.Button("πŸ”¬ Analyze Wound", variant="primary", elem_id="analyze-btn")
705
  analysis_output = gr.HTML("")
 
891
 
892
  # --- IMPORTANT: call standalone GPU function via lambda to pass instance/ctx ---
893
  analyze_btn.click(
894
+ fn=lambda mode, ex_lbl, np_n, np_a, np_g, wl, wd, p, m, i, d, pt, mh, med, al, nt,
895
+ img, manual_mask, seg_adj: \
896
  standalone_run_analysis(
897
+ self, self.current_user, self.database_manager, self.wound_analyzer,
898
+ mode, ex_lbl, np_n, np_a, np_g, wl, wd, p, m, i, d, pt, mh, med, al, nt,
899
+ img, seg_adj, manual_mask
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
900
  ),
901
  inputs=[
902
+ patient_mode, existing_patient_dd,
903
+ new_patient_name, new_patient_age, new_patient_gender,
904
+ wound_location, wound_duration, pain_level, moisture_level, infection_signs, diabetic_status,
905
+ previous_treatment, medical_history, medications, allergies, additional_notes,
906
+ wound_image, manual_mask_input, seg_adjust_slider
 
 
 
 
 
 
 
 
 
 
 
 
 
 
907
  ],
908
+ outputs=[analysis_output]
909
  )
910
 
911
  history_btn.click(load_history, outputs=[patient_history_output])
 
931
  length_cm = visual_analysis.get('length_cm', 0)
932
  breadth_cm = visual_analysis.get('breadth_cm', 0)
933
  area_cm2 = visual_analysis.get('surface_area_cm2', 0)
934
+ detection_confidence = visual_analysis.get('detection_confidence', 0)
 
 
 
935
 
936
  detection_image_path = visual_analysis.get('detection_image_path', '')
937
  segmentation_image_path = visual_analysis.get('segmentation_image_path', '')
 
1023
  <div style="background: #f8f9fa; padding: 30px; border-radius: 12px; margin-bottom: 30px;">
1024
  <h2 style="color: #2d3748; margin-top: 0;">πŸ” Wound Detection & Classification</h2>
1025
  <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin: 20px 0;">
 
1026
  <div style="background: white; padding: 20px; border-radius: 8px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
1027
  <h3 style="color: #3182ce; margin: 0 0 10px 0;">Wound Type</h3>
1028
  <p style="font-weight: 600; font-size: 18px; color: #2d3748; margin: 0;">{html.escape(str(wound_type))}</p>
1029
  </div>
 
1030
  <div style="background: white; padding: 20px; border-radius: 8px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
1031
  <h3 style="color: #3182ce; margin: 0 0 10px 0;">Location</h3>
1032
  <p style="font-weight: 600; font-size: 18px; color: #2d3748; margin: 0;">{html.escape(str(questionnaire_data.get('wound_location', 'Not specified')))}</p>
1033
  </div>
 
 
 
 
 
 
 
 
 
 
1034
  </div>
1035
  </div>
1036