Spaces:
Sleeping
Sleeping
Update src/ui_components_original.py
Browse files- src/ui_components_original.py +90 -29
src/ui_components_original.py
CHANGED
|
@@ -58,11 +58,25 @@ def standalone_run_analysis(
|
|
| 58 |
database_manager,
|
| 59 |
wound_analyzer,
|
| 60 |
# UI inputs
|
| 61 |
-
mode,
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
):
|
| 67 |
"""Runs in the ZeroGPU worker; returns HTML for the UI."""
|
| 68 |
def _label_to_id(label: str):
|
|
@@ -183,10 +197,10 @@ def standalone_run_analysis(
|
|
| 183 |
'medications': meds,
|
| 184 |
'additional_notes': notes
|
| 185 |
}
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
|
| 191 |
# Run AI
|
| 192 |
analysis_result = wound_analyzer.analyze_wound(img_path, q_for_ai)
|
|
@@ -674,9 +688,6 @@ button.gr-button:hover, button.gr-button-primary:hover {
|
|
| 674 |
with gr.Column(scale=1):
|
| 675 |
gr.HTML("<h3>πΈ Wound Image</h3>")
|
| 676 |
wound_image = gr.Image(label="Upload Wound Image", type="filepath")
|
| 677 |
-
# Optional manual wound mask upload
|
| 678 |
-
gr.HTML("<h3>βοΈ Manual Annotation (optional)</h3>")
|
| 679 |
-
manual_annotation = gr.Image(label="Upload Manual Wound Mask", type="filepath")
|
| 680 |
gr.HTML("<h3>π Medical History</h3>")
|
| 681 |
previous_treatment = gr.Textbox(label="Previous Treatment", lines=3)
|
| 682 |
medical_history = gr.Textbox(label="Medical History", lines=3)
|
|
@@ -684,6 +695,20 @@ button.gr-button:hover, button.gr-button-primary:hover {
|
|
| 684 |
allergies = gr.Textbox(label="Known Allergies", lines=2)
|
| 685 |
additional_notes = gr.Textbox(label="Additional Notes", lines=3)
|
| 686 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 687 |
analyze_btn = gr.Button("π¬ Analyze Wound", variant="primary", elem_id="analyze-btn")
|
| 688 |
analysis_output = gr.HTML("")
|
| 689 |
|
|
@@ -874,18 +899,54 @@ button.gr-button:hover, button.gr-button-primary:hover {
|
|
| 874 |
|
| 875 |
# --- IMPORTANT: call standalone GPU function via lambda to pass instance/ctx ---
|
| 876 |
analyze_btn.click(
|
| 877 |
-
fn=lambda mode, ex_lbl, np_n, np_a, np_g, wl, wd, p, m, i, d, pt, mh, med, al, nt, img,
|
| 878 |
standalone_run_analysis(
|
| 879 |
-
self,
|
| 880 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 881 |
),
|
| 882 |
inputs=[
|
| 883 |
-
patient_mode,
|
| 884 |
-
|
| 885 |
-
|
| 886 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 887 |
],
|
| 888 |
-
outputs=[analysis_output]
|
| 889 |
)
|
| 890 |
|
| 891 |
history_btn.click(load_history, outputs=[patient_history_output])
|
|
@@ -908,13 +969,13 @@ button.gr-button:hover, button.gr-button-primary:hover {
|
|
| 908 |
saved_image_path = analysis_result.get('saved_image_path', '')
|
| 909 |
|
| 910 |
wound_type = visual_analysis.get('wound_type', 'Unknown')
|
| 911 |
-
skin_tone_label = visual_analysis.get('skin_tone_label', 'Unknown')
|
| 912 |
-
ita_degrees = visual_analysis.get('ita_degrees', 0)
|
| 913 |
-
tissue_type = visual_analysis.get('tissue_type', 'Unknown')
|
| 914 |
length_cm = visual_analysis.get('length_cm', 0)
|
| 915 |
breadth_cm = visual_analysis.get('breadth_cm', 0)
|
| 916 |
area_cm2 = visual_analysis.get('surface_area_cm2', 0)
|
| 917 |
-
|
|
|
|
|
|
|
|
|
|
| 918 |
|
| 919 |
detection_image_path = visual_analysis.get('detection_image_path', '')
|
| 920 |
segmentation_image_path = visual_analysis.get('segmentation_image_path', '')
|
|
@@ -966,7 +1027,7 @@ button.gr-button:hover, button.gr-button-primary:hover {
|
|
| 966 |
<div class="image-item">
|
| 967 |
<img src="{detection_image_base64}" alt="Wound Detection">
|
| 968 |
<h4>π― Wound Detection</h4>
|
| 969 |
-
<p>AI-detected wound boundaries
|
| 970 |
</div>
|
| 971 |
'''
|
| 972 |
if segmentation_image_base64:
|
|
@@ -1006,22 +1067,22 @@ button.gr-button:hover, button.gr-button-primary:hover {
|
|
| 1006 |
<div style="background: #f8f9fa; padding: 30px; border-radius: 12px; margin-bottom: 30px;">
|
| 1007 |
<h2 style="color: #2d3748; margin-top: 0;">π Wound Detection & Classification</h2>
|
| 1008 |
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin: 20px 0;">
|
|
|
|
| 1009 |
<div style="background: white; padding: 20px; border-radius: 8px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
|
| 1010 |
<h3 style="color: #3182ce; margin: 0 0 10px 0;">Wound Type</h3>
|
| 1011 |
<p style="font-weight: 600; font-size: 18px; color: #2d3748; margin: 0;">{html.escape(str(wound_type))}</p>
|
| 1012 |
</div>
|
| 1013 |
-
|
| 1014 |
-
<h3 style="color: #3182ce; margin: 0 0 10px 0;">Detection Confidence</h3>
|
| 1015 |
-
<p style="font-weight: 600; font-size: 18px; color: #2d3748; margin: 0;">{detection_confidence:.1%}</p>
|
| 1016 |
-
</div>
|
| 1017 |
<div style="background: white; padding: 20px; border-radius: 8px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
|
| 1018 |
<h3 style="color: #3182ce; margin: 0 0 10px 0;">Location</h3>
|
| 1019 |
<p style="font-weight: 600; font-size: 18px; color: #2d3748; margin: 0;">{html.escape(str(questionnaire_data.get('wound_location', 'Not specified')))}</p>
|
| 1020 |
</div>
|
|
|
|
| 1021 |
<div style="background: white; padding: 20px; border-radius: 8px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
|
| 1022 |
<h3 style="color: #3182ce; margin: 0 0 10px 0;">Skin Tone</h3>
|
| 1023 |
<p style="font-weight: 600; font-size: 18px; color: #2d3748; margin: 0;">{html.escape(str(skin_tone_label))} ({ita_degrees:.1f}Β°)</p>
|
| 1024 |
</div>
|
|
|
|
| 1025 |
<div style="background: white; padding: 20px; border-radius: 8px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
|
| 1026 |
<h3 style="color: #3182ce; margin: 0 0 10px 0;">Tissue Type</h3>
|
| 1027 |
<p style="font-weight: 600; font-size: 18px; color: #2d3748; margin: 0;">{html.escape(str(tissue_type))}</p>
|
|
|
|
| 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 |
'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)
|
|
|
|
| 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)
|
|
|
|
| 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("")
|
| 714 |
|
|
|
|
| 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])
|
|
|
|
| 969 |
saved_image_path = analysis_result.get('saved_image_path', '')
|
| 970 |
|
| 971 |
wound_type = visual_analysis.get('wound_type', 'Unknown')
|
|
|
|
|
|
|
|
|
|
| 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', '')
|
|
|
|
| 1027 |
<div class="image-item">
|
| 1028 |
<img src="{detection_image_base64}" alt="Wound Detection">
|
| 1029 |
<h4>π― Wound Detection</h4>
|
| 1030 |
+
<p>AI-detected wound boundaries</p>
|
| 1031 |
</div>
|
| 1032 |
'''
|
| 1033 |
if segmentation_image_base64:
|
|
|
|
| 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>
|