Spaces:
Paused
Paused
File size: 11,840 Bytes
f3ebc82 | 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 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | """Sample room data for testing the FDAM AI Pipeline.
Provides 4 pre-configured sample scenarios with complete project data,
room information, images, and qualitative observations.
"""
import uuid
import io
from pathlib import Path
from dataclasses import dataclass, field
from PIL import Image
from ui.state import (
SessionState,
ProjectFormData,
RoomFormData,
ImageFormData,
ObservationsFormData,
)
from ui.components import image_store
# Path to sample images directory
SAMPLE_IMAGES_DIR = Path(__file__).parent.parent / "sample_images"
@dataclass
class SampleScenario:
"""Definition of a sample fire damage scenario."""
id: str
name: str
description: str
project_data: dict
room_data: dict
observations_data: dict
image_files: list[str] = field(default_factory=list)
# --- Sample Scenario Definitions ---
SAMPLE_SCENARIOS = [
# 1. Bar & Dining Area
SampleScenario(
id="bar_dining",
name="Bar & Dining Area",
description="3 images",
project_data={
"project_name": "Sample: Bar & Dining Fire Assessment",
"address": "1234 Main Street",
"city": "Springfield",
"state": "IL",
"zip_code": "62701",
"client_name": "Sample Test Client",
"fire_date": "2024-11-15",
"assessment_date": "2024-12-01",
"facility_classification": "non-operational",
"construction_era": "pre-1980",
"assessor_name": "Test Assessor",
"assessor_credentials": ["CIH"],
},
room_data={
"name": "Bar & Dining Area",
"floor": "Ground Floor",
"length_ft": 40.0,
"width_ft": 30.0,
"ceiling_height_ft": 12.0,
},
observations_data={
"smoke_fire_odor": True,
"odor_intensity": "strong",
"visible_soot_deposits": True,
"soot_pattern_description": "Heavy soot deposits on corrugated metal ceiling, moderate wall discoloration",
"large_char_particles": True,
"char_density_estimate": "moderate",
"ash_like_residue": True,
"ash_color_texture": "Ash deposits on horizontal surfaces and upholstered furniture",
"surface_discoloration": True,
"discoloration_description": "Tan/brown soot staining on walls, yellowing on decorative elements",
"dust_loading_interference": False,
"dust_notes": "",
"wildfire_indicators": False,
"wildfire_notes": "",
"additional_notes": "",
},
image_files=[
"Bar and dining area1.jpg",
"Bar and dining area2.jpg",
"Bar and dining area3.jpg",
],
),
# 2. Bar Area
SampleScenario(
id="bar_area",
name="Bar Area",
description="3 images",
project_data={
"project_name": "Sample: Bar Area Fire Assessment",
"address": "1234 Main Street",
"city": "Springfield",
"state": "IL",
"zip_code": "62701",
"client_name": "Sample Test Client",
"fire_date": "2024-11-15",
"assessment_date": "2024-12-01",
"facility_classification": "non-operational",
"construction_era": "pre-1980",
"assessor_name": "Test Assessor",
"assessor_credentials": ["CIH"],
},
room_data={
"name": "Bar Area",
"floor": "Ground Floor",
"length_ft": 25.0,
"width_ft": 20.0,
"ceiling_height_ft": 14.0,
},
observations_data={
"smoke_fire_odor": True,
"odor_intensity": "strong",
"visible_soot_deposits": True,
"soot_pattern_description": "Dense black coating on ceiling/ductwork, severe overhead damage",
"large_char_particles": True,
"char_density_estimate": "dense",
"ash_like_residue": True,
"ash_color_texture": "Heavy ash on shelving and bottled goods",
"surface_discoloration": True,
"discoloration_description": "Metal oxidation, melted plastic signage, deformed ductwork",
"dust_loading_interference": False,
"dust_notes": "",
"wildfire_indicators": False,
"wildfire_notes": "",
"additional_notes": "",
},
image_files=[
"Bar area1.jpg",
"Bar area2.jpg",
"Bar area3.jpg",
],
),
# 3. Kitchen
SampleScenario(
id="kitchen",
name="Kitchen",
description="6 images",
project_data={
"project_name": "Sample: Kitchen Fire Assessment",
"address": "5678 Industrial Blvd",
"city": "Chicago",
"state": "IL",
"zip_code": "60601",
"client_name": "Sample Test Client",
"fire_date": "2024-10-20",
"assessment_date": "2024-11-05",
"facility_classification": "non-operational",
"construction_era": "1980-2000",
"assessor_name": "Test Assessor",
"assessor_credentials": ["CIH", "CSP"],
},
room_data={
"name": "Commercial Kitchen",
"floor": "Ground Floor",
"length_ft": 30.0,
"width_ft": 25.0,
"ceiling_height_ft": 10.0,
},
observations_data={
"smoke_fire_odor": True,
"odor_intensity": "strong",
"visible_soot_deposits": True,
"soot_pattern_description": "Heavy soot on all surfaces, ceiling collapse debris",
"large_char_particles": True,
"char_density_estimate": "dense",
"ash_like_residue": True,
"ash_color_texture": "Thick ash deposits on work surfaces, equipment heavily coated",
"surface_discoloration": True,
"discoloration_description": "Charred drywall, oxidized metal equipment, concrete staining",
"dust_loading_interference": False,
"dust_notes": "",
"wildfire_indicators": False,
"wildfire_notes": "",
"additional_notes": "",
},
image_files=[
"Kitchen 1.jpg",
"Kitchen 2.jpg",
"Kitchen 3.jpg",
"Kitchen 4.jpg",
"Kitchen 5.jpg",
"Kitchen 6.jpg",
],
),
# 4. Factory Area
SampleScenario(
id="factory",
name="Factory Area",
description="1 image",
project_data={
"project_name": "Sample: Factory Fire Assessment",
"address": "9999 Factory Way",
"city": "Detroit",
"state": "MI",
"zip_code": "48201",
"client_name": "Industrial Test Corp",
"fire_date": "2024-09-01",
"assessment_date": "2024-09-15",
"facility_classification": "operational",
"construction_era": "pre-1980",
"assessor_name": "Test Assessor",
"assessor_credentials": ["CIH", "PE"],
},
room_data={
"name": "Factory Production Area",
"floor": "Ground Floor",
"length_ft": 80.0,
"width_ft": 60.0,
"ceiling_height_ft": 25.0,
},
observations_data={
"smoke_fire_odor": True,
"odor_intensity": "strong",
"visible_soot_deposits": True,
"soot_pattern_description": "Complete structural compromise, deep char on all surfaces",
"large_char_particles": True,
"char_density_estimate": "dense",
"ash_like_residue": True,
"ash_color_texture": "Heavy ash coating throughout, debris accumulation",
"surface_discoloration": True,
"discoloration_description": "Extreme oxidation on metal framing, thermal spalling on concrete",
"dust_loading_interference": False,
"dust_notes": "",
"wildfire_indicators": False,
"wildfire_notes": "",
"additional_notes": "",
},
image_files=[
"factory_area.jpg",
],
),
]
# Create lookup dict for fast access
SAMPLE_SCENARIOS_BY_ID = {s.id: s for s in SAMPLE_SCENARIOS}
def get_sample_choices() -> list[tuple[str, str]]:
"""Get dropdown choices for sample selector.
Returns:
List of (label, value) tuples for Gradio dropdown.
"""
choices = [("Select a sample scenario...", "")]
for scenario in SAMPLE_SCENARIOS:
label = f"{scenario.name} ({scenario.description})"
choices.append((label, scenario.id))
return choices
def load_sample_images(scenario: SampleScenario, room_id: str) -> list[ImageFormData]:
"""Load sample images from disk into image_store.
Args:
scenario: The sample scenario to load images for.
room_id: The room ID to associate images with.
Returns:
List of ImageFormData objects for the loaded images.
"""
image_metas = []
for filename in scenario.image_files:
filepath = SAMPLE_IMAGES_DIR / filename
if filepath.exists():
try:
# Read and convert image to PNG bytes
img = Image.open(filepath)
img_bytes = io.BytesIO()
img.save(img_bytes, format="PNG")
# Generate unique image ID
image_id = f"sample-{uuid.uuid4().hex[:8]}"
# Store in image_store
image_store.store(image_id, img_bytes.getvalue())
# Create metadata
image_metas.append(
ImageFormData(
id=image_id,
filename=filename,
room_id=room_id,
description=f"Sample image: {filename}",
)
)
except Exception:
# Skip files that can't be opened as images
continue
return image_metas
def load_sample(scenario_id: str) -> SessionState | None:
"""Load a sample scenario into a new SessionState.
Args:
scenario_id: The ID of the scenario to load.
Returns:
A new SessionState populated with the scenario data, or None if not found.
"""
scenario = SAMPLE_SCENARIOS_BY_ID.get(scenario_id)
if not scenario:
return None
# Create room with unique ID
room_id = f"room-{uuid.uuid4().hex[:8]}"
room = RoomFormData(
id=room_id,
name=scenario.room_data["name"],
floor=scenario.room_data.get("floor", ""),
length_ft=scenario.room_data["length_ft"],
width_ft=scenario.room_data["width_ft"],
ceiling_height_ft=scenario.room_data["ceiling_height_ft"],
)
# Load images
images = load_sample_images(scenario, room_id)
# Create session
session = SessionState(
project=ProjectFormData(**scenario.project_data),
rooms=[room],
images=images,
observations=ObservationsFormData(**scenario.observations_data),
name=scenario.project_data["project_name"],
)
# Mark tabs as complete since we have all data
session.tab1_complete = True
session.tab2_complete = True
session.tab3_complete = len(images) > 0
session.tab4_complete = True
return session
def get_scenario_by_id(scenario_id: str) -> SampleScenario | None:
"""Get a sample scenario by its ID.
Args:
scenario_id: The scenario ID.
Returns:
The SampleScenario object or None if not found.
"""
return SAMPLE_SCENARIOS_BY_ID.get(scenario_id)
|