Spaces:
Runtime error
Runtime error
Rename utils/image_utils.py to utils/parser.py
Browse files- utils/image_utils.py +0 -4
- utils/parser.py +52 -0
utils/image_utils.py
DELETED
|
@@ -1,4 +0,0 @@
|
|
| 1 |
-
from PIL import Image
|
| 2 |
-
|
| 3 |
-
def load_image(image_path):
|
| 4 |
-
return Image.open(image_path).convert("RGB")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils/parser.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def parse_damage_description(text: str):
|
| 2 |
+
"""
|
| 3 |
+
Converts vision-language description into structured damage info.
|
| 4 |
+
Defensive by design (never crashes on unexpected text).
|
| 5 |
+
"""
|
| 6 |
+
t = text.lower()
|
| 7 |
+
|
| 8 |
+
# Default values
|
| 9 |
+
part = "Vehicle Body"
|
| 10 |
+
damage = "Visible Damage"
|
| 11 |
+
severity = "Medium"
|
| 12 |
+
confidence = 70
|
| 13 |
+
|
| 14 |
+
# Part detection
|
| 15 |
+
if "rear bumper" in t or "back bumper" in t:
|
| 16 |
+
part = "Rear Bumper"
|
| 17 |
+
elif "front bumper" in t:
|
| 18 |
+
part = "Front Bumper"
|
| 19 |
+
elif "door" in t:
|
| 20 |
+
part = "Door Panel"
|
| 21 |
+
elif "fender" in t:
|
| 22 |
+
part = "Fender"
|
| 23 |
+
elif "hood" in t or "bonnet" in t:
|
| 24 |
+
part = "Hood"
|
| 25 |
+
elif "trunk" in t or "boot" in t:
|
| 26 |
+
part = "Trunk"
|
| 27 |
+
|
| 28 |
+
# Damage type
|
| 29 |
+
if "dent" in t:
|
| 30 |
+
damage = "Panel Dent"
|
| 31 |
+
severity = "Medium"
|
| 32 |
+
confidence = 88
|
| 33 |
+
elif "scratch" in t:
|
| 34 |
+
damage = "Paint Scratch"
|
| 35 |
+
severity = "Low"
|
| 36 |
+
confidence = 75
|
| 37 |
+
elif "crack" in t or "broken" in t:
|
| 38 |
+
damage = "Structural Crack"
|
| 39 |
+
severity = "High"
|
| 40 |
+
confidence = 92
|
| 41 |
+
|
| 42 |
+
# Severity refinement
|
| 43 |
+
if "severe" in t or "major" in t:
|
| 44 |
+
severity = "High"
|
| 45 |
+
confidence = min(confidence + 5, 95)
|
| 46 |
+
|
| 47 |
+
return {
|
| 48 |
+
"part": part,
|
| 49 |
+
"report": damage,
|
| 50 |
+
"severity": severity,
|
| 51 |
+
"confidence": confidence
|
| 52 |
+
}
|