Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -45,10 +45,9 @@ def main():
|
|
| 45 |
st.session_state.result = ""
|
| 46 |
|
| 47 |
# Text area for email input
|
| 48 |
-
email_body = st.text_area("Email Body", value=st.session_state.email_body, height=200, key="email_input"
|
| 49 |
-
on_change=lambda: st.session_state.update({"result": analyze_email(st.session_state.email_input)}))
|
| 50 |
|
| 51 |
-
# Sample emails (
|
| 52 |
sample_spam = """
|
| 53 |
Subject: Urgent: Verify Your Account Now!
|
| 54 |
Dear Customer,
|
|
@@ -58,6 +57,7 @@ Failure to verify within 24 hours will result in your account being locked. This
|
|
| 58 |
Best regards,
|
| 59 |
The Security Team
|
| 60 |
"""
|
|
|
|
| 61 |
|
| 62 |
sample_not_spam_positive = """
|
| 63 |
Subject: Great News About Your Project!
|
|
@@ -66,6 +66,7 @@ I just wanted to let you know that the project is progressing wonderfully! Every
|
|
| 66 |
Best,
|
| 67 |
Alex
|
| 68 |
"""
|
|
|
|
| 69 |
|
| 70 |
sample_not_spam_negative = """
|
| 71 |
Subject: Issue with Recent Delivery
|
|
@@ -74,25 +75,52 @@ I received my package today, but it was damaged, and two items were missing. Thi
|
|
| 74 |
Thanks,
|
| 75 |
Sarah
|
| 76 |
"""
|
|
|
|
| 77 |
|
| 78 |
-
# Buttons with
|
| 79 |
col1, col2, col3 = st.columns(3)
|
| 80 |
with col1:
|
| 81 |
-
if st.button(
|
| 82 |
st.session_state.email_body = sample_spam
|
| 83 |
-
st.session_state.result =
|
| 84 |
st.rerun()
|
| 85 |
with col2:
|
| 86 |
-
if st.button(
|
| 87 |
st.session_state.email_body = sample_not_spam_positive
|
| 88 |
-
st.session_state.result =
|
| 89 |
st.rerun()
|
| 90 |
with col3:
|
| 91 |
-
if st.button(
|
| 92 |
st.session_state.email_body = sample_not_spam_negative
|
| 93 |
-
st.session_state.result =
|
| 94 |
st.rerun()
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
# Display result
|
| 97 |
if st.session_state.result:
|
| 98 |
st.write(st.session_state.result)
|
|
|
|
| 45 |
st.session_state.result = ""
|
| 46 |
|
| 47 |
# Text area for email input
|
| 48 |
+
email_body = st.text_area("Email Body", value=st.session_state.email_body, height=200, key="email_input")
|
|
|
|
| 49 |
|
| 50 |
+
# Sample emails (shortened snippets for button labels)
|
| 51 |
sample_spam = """
|
| 52 |
Subject: Urgent: Verify Your Account Now!
|
| 53 |
Dear Customer,
|
|
|
|
| 57 |
Best regards,
|
| 58 |
The Security Team
|
| 59 |
"""
|
| 60 |
+
spam_snippet = "Subject: Urgent: Verify Your Account Now! Dear Customer, We have detected unusual activity..."
|
| 61 |
|
| 62 |
sample_not_spam_positive = """
|
| 63 |
Subject: Great News About Your Project!
|
|
|
|
| 66 |
Best,
|
| 67 |
Alex
|
| 68 |
"""
|
| 69 |
+
positive_snippet = "Subject: Great News About Your Project! Hi Team, I just wanted to let you know..."
|
| 70 |
|
| 71 |
sample_not_spam_negative = """
|
| 72 |
Subject: Issue with Recent Delivery
|
|
|
|
| 75 |
Thanks,
|
| 76 |
Sarah
|
| 77 |
"""
|
| 78 |
+
negative_snippet = "Subject: Issue with Recent Delivery Dear Support, I received my package today, but..."
|
| 79 |
|
| 80 |
+
# Buttons with sample content (in columns)
|
| 81 |
col1, col2, col3 = st.columns(3)
|
| 82 |
with col1:
|
| 83 |
+
if st.button(spam_snippet, key="spam_sample"):
|
| 84 |
st.session_state.email_body = sample_spam
|
| 85 |
+
st.session_state.result = "" # Clear result until Analyze is clicked
|
| 86 |
st.rerun()
|
| 87 |
with col2:
|
| 88 |
+
if st.button(positive_snippet, key="positive_sample"):
|
| 89 |
st.session_state.email_body = sample_not_spam_positive
|
| 90 |
+
st.session_state.result = ""
|
| 91 |
st.rerun()
|
| 92 |
with col3:
|
| 93 |
+
if st.button(negative_snippet, key="negative_sample"):
|
| 94 |
st.session_state.email_body = sample_not_spam_negative
|
| 95 |
+
st.session_state.result = ""
|
| 96 |
st.rerun()
|
| 97 |
|
| 98 |
+
# Custom styled Analyze button
|
| 99 |
+
st.markdown("""
|
| 100 |
+
<style>
|
| 101 |
+
.analyze-button {
|
| 102 |
+
background-color: #4CAF50; /* Green */
|
| 103 |
+
color: white;
|
| 104 |
+
padding: 10px 20px;
|
| 105 |
+
border: none;
|
| 106 |
+
border-radius: 5px;
|
| 107 |
+
cursor: pointer;
|
| 108 |
+
font-size: 16px;
|
| 109 |
+
display: block;
|
| 110 |
+
margin-top: 10px;
|
| 111 |
+
}
|
| 112 |
+
.analyze-button:hover {
|
| 113 |
+
background-color: #45a049;
|
| 114 |
+
}
|
| 115 |
+
</style>
|
| 116 |
+
""", unsafe_allow_html=True)
|
| 117 |
+
|
| 118 |
+
if st.button("Analyze Email", key="analyze", help="Click to analyze the email"):
|
| 119 |
+
if email_body:
|
| 120 |
+
st.session_state.result = analyze_email(email_body)
|
| 121 |
+
else:
|
| 122 |
+
st.session_state.result = "Please enter an email body or select a sample to analyze."
|
| 123 |
+
|
| 124 |
# Display result
|
| 125 |
if st.session_state.result:
|
| 126 |
st.write(st.session_state.result)
|