Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,18 +7,15 @@ def main():
|
|
| 7 |
# Load the spam detection pipeline
|
| 8 |
spam_pipeline = pipeline("text-classification", model="cybersectony/phishing-email-detection-distilbert_v2.4.1")
|
| 9 |
|
| 10 |
-
# Load the sentiment model and tokenizer
|
| 11 |
sentiment_model = AutoModelForSequenceClassification.from_pretrained("ISOM5240GP4/email_sentiment", num_labels=2)
|
| 12 |
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
|
| 13 |
|
| 14 |
-
# Title and description
|
| 15 |
st.title("Email Analysis Tool")
|
| 16 |
st.write("Enter an email body below to check if it's spam and analyze its sentiment.")
|
| 17 |
|
| 18 |
-
# Text area for email input
|
| 19 |
email_body = st.text_area("Email Body", height=200)
|
| 20 |
|
| 21 |
-
# Button to trigger analysis
|
| 22 |
if st.button("Analyze Email"):
|
| 23 |
if email_body:
|
| 24 |
# Step 1: Check if the email is spam
|
|
@@ -26,8 +23,8 @@ def main():
|
|
| 26 |
spam_label = spam_result[0]["label"]
|
| 27 |
spam_confidence = spam_result[0]["score"]
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
if spam_label == "
|
| 31 |
st.write(f"This is a spam email (Confidence: {spam_confidence:.2f}). No follow-up needed.")
|
| 32 |
else:
|
| 33 |
# Step 2: Analyze sentiment for non-spam emails
|
|
@@ -38,13 +35,12 @@ def main():
|
|
| 38 |
sentiment_index = np.argmax(predictions)
|
| 39 |
sentiment_confidence = predictions[0][sentiment_index]
|
| 40 |
|
| 41 |
-
# Map index to sentiment (1 = positive, 0 = negative)
|
| 42 |
sentiment = "Positive" if sentiment_index == 1 else "Negative"
|
| 43 |
|
| 44 |
if sentiment == "Positive":
|
| 45 |
st.write(f"This email is not spam (Confidence: {spam_confidence:.2f}).")
|
| 46 |
st.write(f"Sentiment: {sentiment} (Confidence: {sentiment_confidence:.2f}). No follow-up needed.")
|
| 47 |
-
else:
|
| 48 |
st.write(f"This email is not spam (Confidence: {spam_confidence:.2f}).")
|
| 49 |
st.write(f"Sentiment: {sentiment} (Confidence: {sentiment_confidence:.2f}).")
|
| 50 |
st.write("**This email needs follow-up as it is not spam and has negative sentiment.**")
|
|
|
|
| 7 |
# Load the spam detection pipeline
|
| 8 |
spam_pipeline = pipeline("text-classification", model="cybersectony/phishing-email-detection-distilbert_v2.4.1")
|
| 9 |
|
| 10 |
+
# Load the sentiment model and tokenizer
|
| 11 |
sentiment_model = AutoModelForSequenceClassification.from_pretrained("ISOM5240GP4/email_sentiment", num_labels=2)
|
| 12 |
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
|
| 13 |
|
|
|
|
| 14 |
st.title("Email Analysis Tool")
|
| 15 |
st.write("Enter an email body below to check if it's spam and analyze its sentiment.")
|
| 16 |
|
|
|
|
| 17 |
email_body = st.text_area("Email Body", height=200)
|
| 18 |
|
|
|
|
| 19 |
if st.button("Analyze Email"):
|
| 20 |
if email_body:
|
| 21 |
# Step 1: Check if the email is spam
|
|
|
|
| 23 |
spam_label = spam_result[0]["label"]
|
| 24 |
spam_confidence = spam_result[0]["score"]
|
| 25 |
|
| 26 |
+
# Check if label is 'LABEL_1' for spam
|
| 27 |
+
if spam_label == "LABEL_1":
|
| 28 |
st.write(f"This is a spam email (Confidence: {spam_confidence:.2f}). No follow-up needed.")
|
| 29 |
else:
|
| 30 |
# Step 2: Analyze sentiment for non-spam emails
|
|
|
|
| 35 |
sentiment_index = np.argmax(predictions)
|
| 36 |
sentiment_confidence = predictions[0][sentiment_index]
|
| 37 |
|
|
|
|
| 38 |
sentiment = "Positive" if sentiment_index == 1 else "Negative"
|
| 39 |
|
| 40 |
if sentiment == "Positive":
|
| 41 |
st.write(f"This email is not spam (Confidence: {spam_confidence:.2f}).")
|
| 42 |
st.write(f"Sentiment: {sentiment} (Confidence: {sentiment_confidence:.2f}). No follow-up needed.")
|
| 43 |
+
else:
|
| 44 |
st.write(f"This email is not spam (Confidence: {spam_confidence:.2f}).")
|
| 45 |
st.write(f"Sentiment: {sentiment} (Confidence: {sentiment_confidence:.2f}).")
|
| 46 |
st.write("**This email needs follow-up as it is not spam and has negative sentiment.**")
|