ISOM5240GP4 commited on
Commit
c70917b
·
verified ·
1 Parent(s): 86fdd24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -10
app.py CHANGED
@@ -2,19 +2,43 @@ import streamlit as st
2
  from transformers import pipeline
3
 
4
  def main():
5
- sentiment_pipeline = pipeline(model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
 
 
6
 
7
- st.title("Sentiment Analysis with HuggingFace Spaces")
8
- st.write("Enter a sentence to analyze its sentiment:")
 
9
 
10
- user_input = st.text_input("")
11
- if user_input:
12
- result = sentiment_pipeline(user_input)
13
- sentiment = result[0]["label"]
14
- confidence = result[0]["score"]
15
 
16
- st.write(f"Sentiment: {sentiment}")
17
- st.write(f"Confidence: {confidence:.2f}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  if __name__ == "__main__":
20
  main()
 
2
  from transformers import pipeline
3
 
4
  def main():
5
+ # Load the models
6
+ spam_pipeline = pipeline("text-classification", model="cybersectony/phishing-email-detection-distilbert_v2.4.1")
7
+ sentiment_pipeline = pipeline("text-classification", model="ISOM5240GP4/email_sentiment")
8
 
9
+ # Title and description
10
+ st.title("Email Analysis Tool")
11
+ st.write("Enter an email body below to check if it's spam and analyze its sentiment.")
12
 
13
+ # Text area for email input
14
+ email_body = st.text_area("Email Body", height=200)
 
 
 
15
 
16
+ # Button to trigger analysis
17
+ if st.button("Analyze Email"):
18
+ if email_body:
19
+ # Step 1: Check if the email is spam
20
+ spam_result = spam_pipeline(email_body)
21
+ spam_label = spam_result[0]["label"]
22
+ spam_confidence = spam_result[0]["score"]
23
+
24
+ # If it's spam, display result and stop
25
+ if spam_label == "POSITIVE": # Assuming "POSITIVE" means spam/phishing (check model docs)
26
+ st.write(f"This is a spam email (Confidence: {spam_confidence:.2f}). No follow-up needed.")
27
+ else:
28
+ # Step 2: If not spam, analyze sentiment
29
+ sentiment_result = sentiment_pipeline(email_body)
30
+ sentiment_label = sentiment_result[0]["label"]
31
+ sentiment_confidence = sentiment_result[0]["score"]
32
+
33
+ if sentiment_label == "POSITIVE":
34
+ st.write(f"This email is not spam (Confidence: {spam_confidence:.2f}).")
35
+ st.write(f"Sentiment: Positive (Confidence: {sentiment_confidence:.2f}). No follow-up needed.")
36
+ else: # Assuming "NEGATIVE" for negative sentiment
37
+ st.write(f"This email is not spam (Confidence: {spam_confidence:.2f}).")
38
+ st.write(f"Sentiment: Negative (Confidence: {sentiment_confidence:.2f}).")
39
+ st.write("**This email needs follow-up as it is not spam and has negative sentiment.**")
40
+ else:
41
+ st.write("Please enter an email body to analyze.")
42
 
43
  if __name__ == "__main__":
44
  main()