Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,88 +1,94 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
| 7 |
nltk.download('vader_lexicon')
|
|
|
|
|
|
|
|
|
|
| 8 |
nltk.download('punkt')
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 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 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
"Final Score": round(final_score, 2)
|
| 74 |
-
}
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
)
|
| 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 |
+
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()
|