aaronmrls commited on
Commit
2525fee
Β·
verified Β·
1 Parent(s): f733c1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -8
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
- text_lower = input_text.lower()
32
- critical_keywords = [
33
- "umuusok", "sunog", "amoy sunog", "spark", "kuryente",
34
- "leak", "baha", "gas", "short circuit", "smoke"
35
- ]
36
- if any(word in text_lower for word in critical_keywords):
37
- results.append({"priority_score": 5})
38
- continue
 
 
 
 
 
 
 
 
 
 
 
 
 
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