varshakolanu commited on
Commit
95384d0
·
verified ·
1 Parent(s): 4c50bc0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -0
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import nltk
3
+ from nltk.sentiment.vader import SentimentIntensityAnalyzer
4
+ import re
5
+
6
+ # Download required NLTK resources
7
+ nltk.download('vader_lexicon')
8
+ nltk.download('punkt')
9
+
10
+ def calculate_scores(work_completion, delay_reports, incident_logs):
11
+ """
12
+ Calculates vendor performance scores based on log entries.
13
+ This is a simplified, rule-based demo version.
14
+ """
15
+
16
+ quality_score = 100 # Start with a base score
17
+ timeliness_score = 100
18
+ safety_score = 100
19
+ communication_score = 100
20
+
21
+ # --- Quality Score ---
22
+ quality_keywords_positive = ["good", "excellent", "high quality", "efficient", "precise"]
23
+ quality_keywords_negative = ["poor", "bad", "low quality", "defect", "error"]
24
+ for keyword in quality_keywords_positive:
25
+ quality_score += work_completion.lower().count(keyword) * 5
26
+ for keyword in quality_keywords_negative:
27
+ quality_score -= work_completion.lower().count(keyword) * 10
28
+
29
+ # --- Timeliness Score ---
30
+ timeliness_keywords_positive = ["on time", "punctual", "early", "ahead of schedule"]
31
+ timeliness_keywords_negative = ["late", "delayed", "behind schedule"]
32
+ for keyword in timeliness_keywords_positive:
33
+ timeliness_score += work_completion.lower().count(keyword) * 5 + delay_reports.lower().count(keyword) * 5
34
+ for keyword in timeliness_keywords_negative:
35
+ timeliness_score -= delay_reports.lower().count(keyword) * 10
36
+
37
+ # --- Safety Score ---
38
+ safety_keywords_positive = ["safe", "safety protocol", "no accidents", "precaution"]
39
+ safety_keywords_negative = ["unsafe", "accident", "injury", "hazard"]
40
+ for keyword in safety_keywords_positive:
41
+ safety_score += work_completion.lower().count(keyword) * 5 + incident_logs.lower().count(keyword) * 5
42
+ for keyword in safety_keywords_negative:
43
+ safety_score -= incident_logs.lower().count(keyword) * 15
44
+
45
+ # --- Communication Score ---
46
+ communication_keywords_positive = ["clear communication", "responsive", "proactive", "helpful"]
47
+ communication_keywords_negative = ["unresponsive", "late reply", "miscommunication", "unclear"]
48
+ for keyword in communication_keywords_positive:
49
+ communication_score += work_completion.lower().count(keyword) * 5 + delay_reports.lower().count(keyword) * 5 + incident_logs.lower().count(keyword) * 5
50
+ for keyword in communication_keywords_negative:
51
+ communication_score -= delay_reports.lower().count(keyword) * 10
52
+
53
+ # Basic Sentiment Analysis (Optional - Requires NLTK Download)
54
+ # analyzer = SentimentIntensityAnalyzer()
55
+ # vs = analyzer.polarity_scores(work_completion + " " + delay_reports + " " + incident_logs)
56
+ # sentiment_score = vs['compound']
57
+ # communication_score += sentiment_score * 10 # Adjust weight as needed
58
+
59
+ # Ensure scores are within 0-100 range
60
+ quality_score = max(0, min(quality_score, 100))
61
+ timeliness_score = max(0, min(timeliness_score, 100))
62
+ safety_score = max(0, min(safety_score, 100))
63
+ communication_score = max(0, min(communication_score, 100))
64
+
65
+ # Calculate Final Score (as per Salesforce formula)
66
+ final_score = (0.4 * quality_score + 0.3 * timeliness_score + 0.15 * safety_score + 0.15 * communication_score)
67
+
68
+ return {
69
+ "Quality Score": round(quality_score, 2),
70
+ "Timeliness Score": round(timeliness_score, 2),
71
+ "Safety Score": round(safety_score, 2),
72
+ "Communication Score": round(communication_score, 2),
73
+ "Final Score": round(final_score, 2)
74
+ }
75
+
76
+ if __name__ == "__main__":
77
+ iface = gr.Interface(
78
+ fn=calculate_scores,
79
+ inputs=[
80
+ gr.inputs.Textbox(lines=5, label="Work Completion Details"),
81
+ gr.inputs.Textbox(lines=5, label="Delay Reports"),
82
+ gr.inputs.Textbox(lines=5, label="Incident Logs")
83
+ ],
84
+ outputs=gr.outputs.Label(label="Performance Scores"),
85
+ title="Vendor Performance Scoring",
86
+ description="Enter vendor logs to calculate performance scores."
87
+ )
88
+ iface.launch()