Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,7 +15,7 @@ class CarDamageWebInterface:
|
|
| 15 |
def __init__(self, damage_system):
|
| 16 |
"""Initialize web interface"""
|
| 17 |
self.damage_system = damage_system
|
| 18 |
-
print("
|
| 19 |
|
| 20 |
def process_uploaded_image(self, image):
|
| 21 |
"""Process uploaded image and return results"""
|
|
@@ -128,11 +128,11 @@ class CarDamageWebInterface:
|
|
| 128 |
|
| 129 |
def _create_detailed_report(self, classified_damages, cost_analysis):
|
| 130 |
"""Create detailed text report"""
|
| 131 |
-
report = "
|
| 132 |
report += "=" * 50 + "\n\n"
|
| 133 |
|
| 134 |
# Summary
|
| 135 |
-
report += f"
|
| 136 |
report += f"β’ Total damages detected: {len(classified_damages)}\n"
|
| 137 |
|
| 138 |
# Count damage types
|
|
@@ -150,7 +150,7 @@ class CarDamageWebInterface:
|
|
| 150 |
report += f"β’ Severity distribution: {dict(severity_counts)}\n\n"
|
| 151 |
|
| 152 |
# Detailed damage list
|
| 153 |
-
report += "
|
| 154 |
report += "-" * 30 + "\n"
|
| 155 |
|
| 156 |
for i, damage in enumerate(classified_damages, 1):
|
|
@@ -164,7 +164,7 @@ class CarDamageWebInterface:
|
|
| 164 |
|
| 165 |
# Cost analysis
|
| 166 |
if cost_analysis:
|
| 167 |
-
report += "
|
| 168 |
report += "-" * 20 + "\n"
|
| 169 |
report += f"Labor Cost: ${cost_analysis.get('labor_cost', 0):.2f}\n"
|
| 170 |
report += f"Parts Cost: ${cost_analysis.get('parts_cost', 0):.2f}\n"
|
|
@@ -177,16 +177,16 @@ class CarDamageWebInterface:
|
|
| 177 |
|
| 178 |
high_severity = [d for d in classified_damages if d.get('severity') == 'high']
|
| 179 |
if high_severity:
|
| 180 |
-
report += "
|
| 181 |
|
| 182 |
if any(d.get('type') == 'rust' for d in classified_damages):
|
| 183 |
-
report += "
|
| 184 |
|
| 185 |
if any(d.get('type') == 'crack' for d in classified_damages):
|
| 186 |
-
report += "
|
| 187 |
|
| 188 |
if len(classified_damages) > 5:
|
| 189 |
-
report += "
|
| 190 |
|
| 191 |
return report
|
| 192 |
|
|
@@ -202,25 +202,12 @@ class CarDamageWebInterface:
|
|
| 202 |
.main-header {
|
| 203 |
text-align: center;
|
| 204 |
color: #2c3e50;
|
| 205 |
-
margin-bottom:
|
| 206 |
-
}
|
| 207 |
-
.main-header h1 {
|
| 208 |
-
font-size: 2.2rem;
|
| 209 |
-
margin-bottom: 10px;
|
| 210 |
-
}
|
| 211 |
-
.main-header p {
|
| 212 |
-
font-size: 1.1rem;
|
| 213 |
-
color: #34495e;
|
| 214 |
}
|
| 215 |
.upload-area {
|
| 216 |
border: 2px dashed #3498db;
|
| 217 |
-
border-radius:
|
| 218 |
-
padding:
|
| 219 |
-
background-color: #f4faff;
|
| 220 |
-
transition: background-color 0.3s;
|
| 221 |
-
}
|
| 222 |
-
.upload-area:hover {
|
| 223 |
-
background-color: #e8f4fd;
|
| 224 |
}
|
| 225 |
.result-area {
|
| 226 |
border: 1px solid #bdc3c7;
|
|
@@ -228,21 +215,14 @@ class CarDamageWebInterface:
|
|
| 228 |
padding: 15px;
|
| 229 |
margin: 10px 0;
|
| 230 |
}
|
| 231 |
-
.gr-button {
|
| 232 |
-
font-size: 1rem;
|
| 233 |
-
padding: 10px 16px;
|
| 234 |
-
}
|
| 235 |
-
ul {
|
| 236 |
-
padding-left: 20px;
|
| 237 |
-
}
|
| 238 |
"""
|
| 239 |
|
| 240 |
-
with gr.Blocks(css=css, title="Car Damage Detection
|
| 241 |
|
| 242 |
# Header
|
| 243 |
gr.HTML("""
|
| 244 |
<div class="main-header">
|
| 245 |
-
<h1>
|
| 246 |
<p>Upload a photo of your car to get instant damage analysis and repair cost estimates</p>
|
| 247 |
</div>
|
| 248 |
""")
|
|
@@ -282,7 +262,7 @@ class CarDamageWebInterface:
|
|
| 282 |
|
| 283 |
# Results tabs
|
| 284 |
with gr.Tabs():
|
| 285 |
-
with gr.TabItem("
|
| 286 |
report_output = gr.Textbox(
|
| 287 |
label="Analysis Report",
|
| 288 |
lines=20,
|
|
@@ -290,7 +270,7 @@ class CarDamageWebInterface:
|
|
| 290 |
elem_classes="result-area"
|
| 291 |
)
|
| 292 |
|
| 293 |
-
with gr.TabItem("
|
| 294 |
image_output = gr.Image(
|
| 295 |
label="Damage Detection Results",
|
| 296 |
height=400,
|
|
@@ -304,7 +284,6 @@ class CarDamageWebInterface:
|
|
| 304 |
elem_classes="result-area"
|
| 305 |
)
|
| 306 |
|
| 307 |
-
|
| 308 |
|
| 309 |
# Connect the analyze button to processing function
|
| 310 |
analyze_btn.click(
|
|
@@ -326,7 +305,7 @@ class CarDamageWebInterface:
|
|
| 326 |
def launch_car_damage_app():
|
| 327 |
"""Launch the car damage detection web app"""
|
| 328 |
|
| 329 |
-
print("
|
| 330 |
|
| 331 |
# Create damage detection system (assuming it's already created from previous phases)
|
| 332 |
try:
|
|
@@ -349,12 +328,12 @@ def launch_car_damage_app():
|
|
| 349 |
)
|
| 350 |
|
| 351 |
except NameError:
|
| 352 |
-
print("
|
| 353 |
print("Please run Phases 1-5 first to create the damage detection system.")
|
| 354 |
return None
|
| 355 |
|
| 356 |
except Exception as e:
|
| 357 |
-
print(f"
|
| 358 |
return None
|
| 359 |
|
| 360 |
# Alternative: Create a demo interface if damage system is not available
|
|
@@ -424,4 +403,7 @@ print("β’ π± Mobile-friendly interface")
|
|
| 424 |
print("β’ π Public sharing capability")
|
| 425 |
print()
|
| 426 |
print("π― Ready to launch your Car Damage Detection Web App!")
|
| 427 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
def __init__(self, damage_system):
|
| 16 |
"""Initialize web interface"""
|
| 17 |
self.damage_system = damage_system
|
| 18 |
+
print("Initializing Web Interface...")
|
| 19 |
|
| 20 |
def process_uploaded_image(self, image):
|
| 21 |
"""Process uploaded image and return results"""
|
|
|
|
| 128 |
|
| 129 |
def _create_detailed_report(self, classified_damages, cost_analysis):
|
| 130 |
"""Create detailed text report"""
|
| 131 |
+
report = "CAR DAMAGE ANALYSIS REPORT\n"
|
| 132 |
report += "=" * 50 + "\n\n"
|
| 133 |
|
| 134 |
# Summary
|
| 135 |
+
report += f"SUMMARY:\n"
|
| 136 |
report += f"β’ Total damages detected: {len(classified_damages)}\n"
|
| 137 |
|
| 138 |
# Count damage types
|
|
|
|
| 150 |
report += f"β’ Severity distribution: {dict(severity_counts)}\n\n"
|
| 151 |
|
| 152 |
# Detailed damage list
|
| 153 |
+
report += "DETAILED DAMAGE LIST:\n"
|
| 154 |
report += "-" * 30 + "\n"
|
| 155 |
|
| 156 |
for i, damage in enumerate(classified_damages, 1):
|
|
|
|
| 164 |
|
| 165 |
# Cost analysis
|
| 166 |
if cost_analysis:
|
| 167 |
+
report += "COST ANALYSIS:\n"
|
| 168 |
report += "-" * 20 + "\n"
|
| 169 |
report += f"Labor Cost: ${cost_analysis.get('labor_cost', 0):.2f}\n"
|
| 170 |
report += f"Parts Cost: ${cost_analysis.get('parts_cost', 0):.2f}\n"
|
|
|
|
| 177 |
|
| 178 |
high_severity = [d for d in classified_damages if d.get('severity') == 'high']
|
| 179 |
if high_severity:
|
| 180 |
+
report += " High severity damages detected - immediate repair recommended\n"
|
| 181 |
|
| 182 |
if any(d.get('type') == 'rust' for d in classified_damages):
|
| 183 |
+
report += "Rust detected - treat immediately to prevent spreading\n"
|
| 184 |
|
| 185 |
if any(d.get('type') == 'crack' for d in classified_damages):
|
| 186 |
+
report += "Cracks found - structural integrity may be compromised\n"
|
| 187 |
|
| 188 |
if len(classified_damages) > 5:
|
| 189 |
+
report += "Multiple damages - consider comprehensive repair package\n"
|
| 190 |
|
| 191 |
return report
|
| 192 |
|
|
|
|
| 202 |
.main-header {
|
| 203 |
text-align: center;
|
| 204 |
color: #2c3e50;
|
| 205 |
+
margin-bottom: 30px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
}
|
| 207 |
.upload-area {
|
| 208 |
border: 2px dashed #3498db;
|
| 209 |
+
border-radius: 10px;
|
| 210 |
+
padding: 20px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
}
|
| 212 |
.result-area {
|
| 213 |
border: 1px solid #bdc3c7;
|
|
|
|
| 215 |
padding: 15px;
|
| 216 |
margin: 10px 0;
|
| 217 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
"""
|
| 219 |
|
| 220 |
+
with gr.Blocks(css=css, title="Car Damage Detection AI") as interface:
|
| 221 |
|
| 222 |
# Header
|
| 223 |
gr.HTML("""
|
| 224 |
<div class="main-header">
|
| 225 |
+
<h1>Car Damage Detection & Cost Estimation</h1>
|
| 226 |
<p>Upload a photo of your car to get instant damage analysis and repair cost estimates</p>
|
| 227 |
</div>
|
| 228 |
""")
|
|
|
|
| 262 |
|
| 263 |
# Results tabs
|
| 264 |
with gr.Tabs():
|
| 265 |
+
with gr.TabItem("Detailed Report"):
|
| 266 |
report_output = gr.Textbox(
|
| 267 |
label="Analysis Report",
|
| 268 |
lines=20,
|
|
|
|
| 270 |
elem_classes="result-area"
|
| 271 |
)
|
| 272 |
|
| 273 |
+
with gr.TabItem("Annotated Image"):
|
| 274 |
image_output = gr.Image(
|
| 275 |
label="Damage Detection Results",
|
| 276 |
height=400,
|
|
|
|
| 284 |
elem_classes="result-area"
|
| 285 |
)
|
| 286 |
|
|
|
|
| 287 |
|
| 288 |
# Connect the analyze button to processing function
|
| 289 |
analyze_btn.click(
|
|
|
|
| 305 |
def launch_car_damage_app():
|
| 306 |
"""Launch the car damage detection web app"""
|
| 307 |
|
| 308 |
+
print("Launching Car Damage Detection Web App...")
|
| 309 |
|
| 310 |
# Create damage detection system (assuming it's already created from previous phases)
|
| 311 |
try:
|
|
|
|
| 328 |
)
|
| 329 |
|
| 330 |
except NameError:
|
| 331 |
+
print("Error: Complete damage system not found!")
|
| 332 |
print("Please run Phases 1-5 first to create the damage detection system.")
|
| 333 |
return None
|
| 334 |
|
| 335 |
except Exception as e:
|
| 336 |
+
print(f"Error launching app: {e}")
|
| 337 |
return None
|
| 338 |
|
| 339 |
# Alternative: Create a demo interface if damage system is not available
|
|
|
|
| 403 |
print("β’ π Public sharing capability")
|
| 404 |
print()
|
| 405 |
print("π― Ready to launch your Car Damage Detection Web App!")
|
| 406 |
+
|
| 407 |
+
# Uncomment one of these lines to launch:
|
| 408 |
+
# launch_car_damage_app() # Use this if you completed all previous phases
|
| 409 |
+
# create_demo_interface() # Use this for demo/testing
|