File size: 4,247 Bytes
95384d0
f2d1de5
 
 
95384d0
f2d1de5
 
2b053f0
 
 
 
f2d1de5
2b053f0
 
 
95384d0
f2d1de5
 
 
 
 
95384d0
74d6484
 
 
 
95384d0
f2d1de5
 
 
 
 
 
 
74d6484
95384d0
f2d1de5
 
 
 
 
74d6484
f2d1de5
74d6484
95384d0
f2d1de5
 
 
 
 
 
 
74d6484
95384d0
f2d1de5
 
 
 
 
 
 
a5d1b4f
95384d0
f2d1de5
b6fc742
 
 
 
74d6484
f2d1de5
 
 
74d6484
f2d1de5
 
 
 
 
 
 
 
 
 
 
 
 
f2adc87
 
 
f2d1de5
f2adc87
f2d1de5
 
 
74d6484
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import gradio as gr
import nltk
from nltk.sentiment.vader import SentimentIntensityAnalyzer
import re

# Download required NLTK resources
try:
    nltk.data.find('sentiment/vader_lexicon.zip')
except LookupError:
    nltk.download('vader_lexicon')

try:
    nltk.data.find('tokenizers/punkt/english.pickle')
except LookupError:
    nltk.download('punkt')

def calculate_scores(work_completion, delay_reports, incident_logs):
    """
    Calculates vendor performance scores based on log entries.
    This is a simplified, rule-based demo version.
    """

    quality_score = 100.0  # Initialize as float
    timeliness_score = 100.0
    safety_score = 100.0
    communication_score = 100.0

    # --- Quality Score ---
    quality_keywords_positive = ["good", "excellent", "high quality", "efficient", "precise"]
    quality_keywords_negative = ["poor", "bad", "low quality", "defect", "error"]
    for keyword in quality_keywords_positive:
        quality_score += work_completion.lower().count(keyword) * 5
    for keyword in quality_keywords_negative:
        quality_score -= work_completion.lower().count(keyword) * 10
    quality_score = max(0.0, min(quality_score, 100.0))

    # --- Timeliness Score ---
    timeliness_keywords_positive = ["on time", "punctual", "early", "ahead of schedule"]
    timeliness_keywords_negative = ["late", "delayed", "behind schedule"]
    for keyword in timeliness_keywords_positive:
        timeliness_score += work_completion.lower().count(keyword) * 5 + delay_reports.lower().count(keyword) * 5
    for keyword in timeliness_keywords_negative:
        timeliness_score -= delay_reports.lower().count(keyword) * 10
    timeliness_score = max(0.0, min(timeliness_score, 100.0))

    # --- Safety Score ---
    safety_keywords_positive = ["safe", "safety protocol", "no accidents", "precaution"]
    safety_keywords_negative = ["unsafe", "accident", "injury", "hazard"]
    for keyword in safety_keywords_positive:
        safety_score += work_completion.lower().count(keyword) * 5 + incident_logs.lower().count(keyword) * 5
    for keyword in safety_keywords_negative:
        safety_score -= incident_logs.lower().count(keyword) * 15
    safety_score = max(0.0, min(safety_score, 100.0))

    # --- Communication Score ---
    communication_keywords_positive = ["clear communication", "responsive", "proactive", "helpful"]
    communication_keywords_negative = ["unresponsive", "late reply", "miscommunication", "unclear"]
    for keyword in communication_keywords_positive:
        communication_score += work_completion.lower().count(keyword) * 5 + delay_reports.lower().count(keyword) * 5 + incident_logs.lower().count(keyword) * 5
    for keyword in communication_keywords_negative:
        communication_score -= delay_reports.lower().count(keyword) * 10
    communication_score = max(0.0, min(communication_score, 100.0))

    # Basic Sentiment Analysis (Optional - Requires NLTK Download)
    analyzer = SentimentIntensityAnalyzer()
    vs = analyzer.polarity_scores(work_completion + " " + delay_reports + " " + incident_logs)
    sentiment_score = vs['compound']
    communication_score += sentiment_score * 10  # Adjust weight as needed
    communication_score = max(0.0, min(communication_score, 100.0))

    # Calculate Final Score (as per Salesforce formula)
    final_score = (0.4 * quality_score + 0.3 * timeliness_score + 0.15 * safety_score + 0.15 * communication_score)
    final_score = max(0.0, min(final_score, 100.0))

    return {
        "Quality Score": round(quality_score, 2),
        "Timeliness Score": round(timeliness_score, 2),
        "Safety Score": round(safety_score, 2),
        "Communication Score": round(communication_score, 2),
        "Final Score": round(final_score, 2)
    }

if __name__ == "__main__":
    iface = gr.Interface(
        fn=calculate_scores,
        inputs=[
            gr.Textbox(lines=5, label="Work Completion Details"),
            gr.Textbox(lines=5, label="Delay Reports"),
            gr.Textbox(lines=5, label="Incident Logs")
        ],
        outputs=gr.Label(label="Performance Scores"),
        title="Vendor Performance Scoring",
        description="Enter vendor logs to calculate performance scores."
    )
    iface.launch()