Spaces:
Paused
Paused
File size: 9,080 Bytes
88bdcff f3ebc82 88bdcff |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
"""Tab 4: Observations.
Qualitative observation checklist per FDAM §2.3.
"""
import gradio as gr
from typing import Any
from ui.state import SessionState, ObservationsFormData
# Map UI values to schema values
ODOR_MAP = {
"None": "none",
"Faint": "faint",
"Moderate": "moderate",
"Strong": "strong",
}
ODOR_MAP_REVERSE = {v: k for k, v in ODOR_MAP.items()}
CHAR_DENSITY_MAP = {
"None": None,
"Sparse": "sparse",
"Moderate": "moderate",
"Dense": "dense",
}
CHAR_DENSITY_MAP_REVERSE = {v: k for k, v in CHAR_DENSITY_MAP.items()}
def create_tab() -> dict[str, Any]:
"""Create Tab 4 UI components.
Returns:
Dictionary of component references for event wiring.
"""
gr.Markdown("### Qualitative Observations")
gr.Markdown("*Document field observations per FDAM §2.3. All fields are optional but recommended.*")
with gr.Row():
with gr.Column():
gr.Markdown("#### Odor Assessment")
smoke_odor = gr.Checkbox(
label="Smoke/fire odor present?",
elem_id="smoke_odor",
)
odor_intensity = gr.Radio(
choices=["None", "Faint", "Moderate", "Strong"],
label="Odor Intensity",
value="None",
elem_id="odor_intensity",
)
gr.Markdown("#### Visible Contamination")
visible_soot = gr.Checkbox(
label="Visible soot deposits?",
elem_id="visible_soot",
)
soot_description = gr.Textbox(
label="Soot Pattern Description (optional)",
placeholder="e.g., Heavy deposits on ceiling, lighter on walls",
elem_id="soot_description",
)
large_char = gr.Checkbox(
label="Large char particles observed?",
elem_id="large_char",
)
char_density = gr.Radio(
choices=["None", "Sparse", "Moderate", "Dense"],
label="Char Density",
value="None",
elem_id="char_density",
)
ash_residue = gr.Checkbox(
label="Ash-like residue present?",
elem_id="ash_residue",
)
ash_description = gr.Textbox(
label="Ash Color/Texture (optional)",
placeholder="e.g., Gray powdery residue",
elem_id="ash_description",
)
with gr.Column():
gr.Markdown("#### Surface Conditions")
surface_discoloration = gr.Checkbox(
label="Surface discoloration?",
elem_id="surface_discoloration",
)
discoloration_description = gr.Textbox(
label="Discoloration Description (optional)",
placeholder="e.g., Yellowing on painted surfaces",
elem_id="discoloration_description",
)
gr.Markdown("#### Environmental Factors")
dust_interference = gr.Checkbox(
label="Dust loading or interference?",
info="Pre-existing dust may affect sample interpretation",
elem_id="dust_interference",
)
dust_notes = gr.Textbox(
label="Dust Notes (optional)",
placeholder="e.g., Heavy ambient dust from warehouse operations",
elem_id="dust_notes",
)
wildfire_indicators = gr.Checkbox(
label="Wildfire indicators (burned vegetation/pollen)?",
info="May indicate wildfire vs structural fire",
elem_id="wildfire_indicators",
)
wildfire_notes = gr.Textbox(
label="Wildfire Notes (optional)",
placeholder="e.g., Burned pine pollen visible on surfaces",
elem_id="wildfire_notes",
)
gr.Markdown("#### Additional Notes")
additional_notes = gr.Textbox(
label="Additional Observations",
lines=3,
placeholder="Any other relevant observations...",
elem_id="additional_notes",
)
# Validation status
with gr.Row():
validation_status = gr.HTML(
value="",
elem_id="tab4_validation",
)
with gr.Row():
back_btn = gr.Button("← Back to Images")
validate_btn = gr.Button(
"Save & Continue to Generate Results →",
variant="primary",
)
return {
"smoke_odor": smoke_odor,
"odor_intensity": odor_intensity,
"visible_soot": visible_soot,
"soot_description": soot_description,
"large_char": large_char,
"char_density": char_density,
"ash_residue": ash_residue,
"ash_description": ash_description,
"surface_discoloration": surface_discoloration,
"discoloration_description": discoloration_description,
"dust_interference": dust_interference,
"dust_notes": dust_notes,
"wildfire_indicators": wildfire_indicators,
"wildfire_notes": wildfire_notes,
"additional_notes": additional_notes,
"validation_status": validation_status,
"back_btn": back_btn,
"validate_btn": validate_btn,
}
def update_session_from_form(
session: SessionState,
smoke_odor: bool,
odor_intensity: str,
visible_soot: bool,
soot_description: str,
large_char: bool,
char_density: str,
ash_residue: bool,
ash_description: str,
surface_discoloration: bool,
discoloration_description: str,
dust_interference: bool,
dust_notes: str,
wildfire_indicators: bool,
wildfire_notes: str,
additional_notes: str,
) -> SessionState:
"""Update session state from form values."""
session.observations = ObservationsFormData(
smoke_fire_odor=smoke_odor or False,
odor_intensity=ODOR_MAP.get(odor_intensity, "none"),
visible_soot_deposits=visible_soot or False,
soot_pattern_description=soot_description or "",
large_char_particles=large_char or False,
char_density_estimate=CHAR_DENSITY_MAP.get(char_density),
ash_like_residue=ash_residue or False,
ash_color_texture=ash_description or "",
surface_discoloration=surface_discoloration or False,
discoloration_description=discoloration_description or "",
dust_loading_interference=dust_interference or False,
dust_notes=dust_notes or "",
wildfire_indicators=wildfire_indicators or False,
wildfire_notes=wildfire_notes or "",
additional_notes=additional_notes or "",
)
session.update_timestamp()
return session
def validate_and_continue(
session: SessionState,
smoke_odor: bool,
odor_intensity: str,
visible_soot: bool,
soot_description: str,
large_char: bool,
char_density: str,
ash_residue: bool,
ash_description: str,
surface_discoloration: bool,
discoloration_description: str,
dust_interference: bool,
dust_notes: str,
wildfire_indicators: bool,
wildfire_notes: str,
additional_notes: str,
) -> tuple[SessionState, str, int]:
"""Save observations and proceed to Tab 5.
Returns:
Tuple of (session, validation_html, next_tab_index).
"""
# Update session
session = update_session_from_form(
session,
smoke_odor,
odor_intensity,
visible_soot,
soot_description,
large_char,
char_density,
ash_residue,
ash_description,
surface_discoloration,
discoloration_description,
dust_interference,
dust_notes,
wildfire_indicators,
wildfire_notes,
additional_notes,
)
# Tab 4 has no required fields
session.tab4_complete = True
html = """
<div style="background: #e8f5e9; border: 1px solid #66bb6a; border-radius: 4px; padding: 10px;">
<span style="color: #2e7d32;">✓ Observations saved. Proceeding to Generate Results...</span>
</div>
"""
return session, html, gr.update(selected=4) # Go to tab index 4 (Results)
def load_form_from_session(session: SessionState) -> tuple:
"""Load form values from session state.
Returns:
Tuple of form values in component order.
"""
obs = session.observations
return (
obs.smoke_fire_odor,
ODOR_MAP_REVERSE.get(obs.odor_intensity, "None"),
obs.visible_soot_deposits,
obs.soot_pattern_description,
obs.large_char_particles,
CHAR_DENSITY_MAP_REVERSE.get(obs.char_density_estimate, "None"),
obs.ash_like_residue,
obs.ash_color_texture,
obs.surface_discoloration,
obs.discoloration_description,
obs.dust_loading_interference,
obs.dust_notes,
obs.wildfire_indicators,
obs.wildfire_notes,
obs.additional_notes,
)
|