Update app.py
Browse files
app.py
CHANGED
|
@@ -28,14 +28,27 @@ def predict():
|
|
| 28 |
input_text = f"{item['category']} - {item['subcategory']} in {item['area']}. {item.get('comments', '')}"
|
| 29 |
|
| 30 |
# Smart keyword override for critical incidents
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# Tokenize & predict
|
| 41 |
inputs = tokenizer(input_text, return_tensors="pt", truncation=True, padding=True)
|
|
@@ -47,6 +60,12 @@ def predict():
|
|
| 47 |
# β
Convert back to 1β5 scale
|
| 48 |
priority_score = predicted_class + 1
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
# β
Here's where this line goes
|
| 51 |
results.append({"priority_score": priority_score})
|
| 52 |
|
|
|
|
| 28 |
input_text = f"{item['category']} - {item['subcategory']} in {item['area']}. {item.get('comments', '')}"
|
| 29 |
|
| 30 |
# Smart keyword override for critical incidents
|
| 31 |
+
text_lower = input_text.lower()
|
| 32 |
+
|
| 33 |
+
# Critical and low-urgency keyword lists
|
| 34 |
+
critical_keywords = [
|
| 35 |
+
"umuusok", "sunog", "amoy sunog", "spark", "kuryente",
|
| 36 |
+
"leak", "baha", "gas", "short circuit", "smoke"
|
| 37 |
+
]
|
| 38 |
+
|
| 39 |
+
low_keywords = [
|
| 40 |
+
"lightbulb", "bumbilya", "ilaw", "palitan", "replace bulb",
|
| 41 |
+
"painting", "door knob", "hinge", "minor", "cosmetic"
|
| 42 |
+
]
|
| 43 |
+
|
| 44 |
+
# β
Priority rules
|
| 45 |
+
if any(word in text_lower for word in critical_keywords):
|
| 46 |
+
results.append({"priority_score": 5})
|
| 47 |
+
continue
|
| 48 |
+
elif any(word in text_lower for word in low_keywords):
|
| 49 |
+
results.append({"priority_score": 2})
|
| 50 |
+
continue
|
| 51 |
+
|
| 52 |
|
| 53 |
# Tokenize & predict
|
| 54 |
inputs = tokenizer(input_text, return_tensors="pt", truncation=True, padding=True)
|
|
|
|
| 60 |
# β
Convert back to 1β5 scale
|
| 61 |
priority_score = predicted_class + 1
|
| 62 |
|
| 63 |
+
# Soft correction: cap too-high or too-low predictions
|
| 64 |
+
if priority_score >= 5 and not any(word in text_lower for word in critical_keywords):
|
| 65 |
+
priority_score = 4 # reduce overly high unless it's critical
|
| 66 |
+
elif priority_score <= 1:
|
| 67 |
+
priority_score = 2 # lift up if too low
|
| 68 |
+
|
| 69 |
# β
Here's where this line goes
|
| 70 |
results.append({"priority_score": priority_score})
|
| 71 |
|