Spaces:
Paused
Paused
File size: 9,842 Bytes
f3ebc82 3b08f11 f3ebc82 3b08f11 f3ebc82 3b08f11 f3ebc82 3b08f11 f3ebc82 3b08f11 f3ebc82 3b08f11 f3ebc82 3b08f11 f3ebc82 3b08f11 f3ebc82 3b08f11 f3ebc82 3b08f11 f3ebc82 6fc2368 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 |
"""Sample room data for testing the FDAM AI Pipeline.
Provides 4 pre-configured sample scenarios with complete room data,
images, and qualitative observations.
MVP Simplification: Single room, no project-level data.
"""
import uuid
import io
from pathlib import Path
from dataclasses import dataclass, field
from PIL import Image
from ui.state import (
SessionState,
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
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",
room_data={
"name": "Bar & Dining Area",
"length_ft": 40.0,
"width_ft": 30.0,
"ceiling_height_ft": 12.0,
"facility_classification": "non-operational",
"construction_era": "pre-1980",
},
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",
room_data={
"name": "Bar Area",
"length_ft": 25.0,
"width_ft": 20.0,
"ceiling_height_ft": 14.0,
"facility_classification": "non-operational",
"construction_era": "pre-1980",
},
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",
room_data={
"name": "Commercial Kitchen",
"length_ft": 30.0,
"width_ft": 25.0,
"ceiling_height_ft": 10.0,
"facility_classification": "non-operational",
"construction_era": "1980-2000",
},
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",
room_data={
"name": "Factory Production Area",
"length_ft": 80.0,
"width_ft": 60.0,
"ceiling_height_ft": 25.0,
"facility_classification": "operational",
"construction_era": "pre-1980",
},
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 and all fields from room_data
room_id = f"room-{uuid.uuid4().hex[:8]}"
room = RoomFormData(
id=room_id,
name=scenario.room_data["name"],
length_ft=scenario.room_data["length_ft"],
width_ft=scenario.room_data["width_ft"],
ceiling_height_ft=scenario.room_data["ceiling_height_ft"],
facility_classification=scenario.room_data.get("facility_classification", "non-operational"),
construction_era=scenario.room_data.get("construction_era", "post-2000"),
)
# Load images
images = load_sample_images(scenario, room_id)
# Create session with single room
session = SessionState(
room=room,
images=images,
observations=ObservationsFormData(**scenario.observations_data),
name=scenario.room_data["name"],
)
# Mark input as complete since sample has all required data
session.input_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)
|