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

Update app.py

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