varshakolanu commited on
Commit
74d6484
·
verified ·
1 Parent(s): 4a64264

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -20,10 +20,10 @@ def calculate_scores(work_completion, delay_reports, incident_logs):
20
  This is a simplified, rule-based demo version.
21
  """
22
 
23
- quality_score = 100 # Start with a base score
24
- timeliness_score = 100
25
- safety_score = 100
26
- communication_score = 100
27
 
28
  # --- Quality Score ---
29
  quality_keywords_positive = ["good", "excellent", "high quality", "efficient", "precise"]
@@ -32,16 +32,16 @@ def calculate_scores(work_completion, delay_reports, incident_logs):
32
  quality_score += work_completion.lower().count(keyword) * 5
33
  for keyword in quality_keywords_negative:
34
  quality_score -= work_completion.lower().count(keyword) * 10
35
- quality_score = max(0, min(quality_score, 100))
36
 
37
  # --- Timeliness Score ---
38
  timeliness_keywords_positive = ["on time", "punctual", "early", "ahead of schedule"]
39
  timeliness_keywords_negative = ["late", "delayed", "behind schedule"]
40
  for keyword in timeliness_keywords_positive:
41
  timeliness_score += work_completion.lower().count(keyword) * 5 + delay_reports.lower().count(keyword) * 5
42
- for keyword in timeliness_negative:
43
  timeliness_score -= delay_reports.lower().count(keyword) * 10
44
- timeliness_score = max(0, min(timeliness_score, 100))
45
 
46
  # --- Safety Score ---
47
  safety_keywords_positive = ["safe", "safety protocol", "no accidents", "precaution"]
@@ -50,7 +50,7 @@ def calculate_scores(work_completion, delay_reports, incident_logs):
50
  safety_score += work_completion.lower().count(keyword) * 5 + incident_logs.lower().count(keyword) * 5
51
  for keyword in safety_keywords_negative:
52
  safety_score -= incident_logs.lower().count(keyword) * 15
53
- safety_score = max(0, min(safety_score, 100))
54
 
55
  # --- Communication Score ---
56
  communication_keywords_positive = ["clear communication", "responsive", "proactive", "helpful"]
@@ -65,11 +65,11 @@ def calculate_scores(work_completion, delay_reports, incident_logs):
65
  vs = analyzer.polarity_scores(work_completion + " " + delay_reports + " " + incident_logs)
66
  sentiment_score = vs['compound']
67
  communication_score += sentiment_score * 10 # Adjust weight as needed
68
- communication_score = max(0, min(communication_score, 100))
69
 
70
  # Calculate Final Score (as per Salesforce formula)
71
  final_score = (0.4 * quality_score + 0.3 * timeliness_score + 0.15 * safety_score + 0.15 * communication_score)
72
- final_score = max(0, min(final_score, 100))
73
 
74
  return {
75
  "Quality Score": round(quality_score, 2),
@@ -91,4 +91,4 @@ if __name__ == "__main__":
91
  title="Vendor Performance Scoring",
92
  description="Enter vendor logs to calculate performance scores."
93
  )
94
- iface.launch()
 
20
  This is a simplified, rule-based demo version.
21
  """
22
 
23
+ quality_score = 100.0 # Initialize as float
24
+ timeliness_score = 100.0
25
+ safety_score = 100.0
26
+ communication_score = 100.0
27
 
28
  # --- Quality Score ---
29
  quality_keywords_positive = ["good", "excellent", "high quality", "efficient", "precise"]
 
32
  quality_score += work_completion.lower().count(keyword) * 5
33
  for keyword in quality_keywords_negative:
34
  quality_score -= work_completion.lower().count(keyword) * 10
35
+ quality_score = max(0.0, min(quality_score, 100.0))
36
 
37
  # --- Timeliness Score ---
38
  timeliness_keywords_positive = ["on time", "punctual", "early", "ahead of schedule"]
39
  timeliness_keywords_negative = ["late", "delayed", "behind schedule"]
40
  for keyword in timeliness_keywords_positive:
41
  timeliness_score += work_completion.lower().count(keyword) * 5 + delay_reports.lower().count(keyword) * 5
42
+ for keyword in timeliness_keywords_negative:
43
  timeliness_score -= delay_reports.lower().count(keyword) * 10
44
+ timeliness_score = max(0.0, min(timeliness_score, 100.0))
45
 
46
  # --- Safety Score ---
47
  safety_keywords_positive = ["safe", "safety protocol", "no accidents", "precaution"]
 
50
  safety_score += work_completion.lower().count(keyword) * 5 + incident_logs.lower().count(keyword) * 5
51
  for keyword in safety_keywords_negative:
52
  safety_score -= incident_logs.lower().count(keyword) * 15
53
+ safety_score = max(0.0, min(safety_score, 100.0))
54
 
55
  # --- Communication Score ---
56
  communication_keywords_positive = ["clear communication", "responsive", "proactive", "helpful"]
 
65
  vs = analyzer.polarity_scores(work_completion + " " + delay_reports + " " + incident_logs)
66
  sentiment_score = vs['compound']
67
  communication_score += sentiment_score * 10 # Adjust weight as needed
68
+ communication_score = max(0.0, min(communication_score, 100.0))
69
 
70
  # Calculate Final Score (as per Salesforce formula)
71
  final_score = (0.4 * quality_score + 0.3 * timeliness_score + 0.15 * safety_score + 0.15 * communication_score)
72
+ final_score = max(0.0, min(final_score, 100.0))
73
 
74
  return {
75
  "Quality Score": round(quality_score, 2),
 
91
  title="Vendor Performance Scoring",
92
  description="Enter vendor logs to calculate performance scores."
93
  )
94
+ iface.launch()