rajendradayma commited on
Commit
00d2792
Β·
verified Β·
1 Parent(s): e7a2add

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +41 -28
streamlit_app.py CHANGED
@@ -1,28 +1,41 @@
1
- # streamlit_app.py
2
- import streamlit as st
3
- import requests
4
-
5
- st.title("πŸ“§ Email Classification and PII Masking System")
6
-
7
- email_input = st.text_area("Enter your email text:")
8
-
9
- if st.button("Classify Email"):
10
- if email_input.strip() != "":
11
- # Send to FastAPI
12
- response = requests.post("http://127.0.0.1:8000/predict", json={"email_body": email_input})
13
-
14
- if response.status_code == 200:
15
- result = response.json()
16
-
17
- st.subheader("πŸ”Ž Masked Email:")
18
- st.write(result['masked_email'])
19
-
20
- st.subheader("πŸ” List of Masked Entities:")
21
- st.json(result['list_of_masked_entities'])
22
-
23
- st.subheader("πŸ“‚ Predicted Category:")
24
- st.success(result['category_of_the_email'])
25
- else:
26
- st.error("Error from API.")
27
- else:
28
- st.warning("Please enter email text!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # streamlit_app.py
2
+ import streamlit as st
3
+ from models import load_model
4
+ from utils import mask_pii
5
+
6
+ st.set_page_config(page_title="πŸ“§ Email Classification System", page_icon="πŸ“§")
7
+
8
+ st.title("πŸ“§ Email Classification and PII Masking System")
9
+
10
+ # Load model
11
+ model = load_model("model/classifier.pkl")
12
+
13
+ # Prediction function
14
+ def classify_email_direct(email_body):
15
+ masked_text, entities = mask_pii(email_body)
16
+ category = model.predict([masked_text])[0]
17
+ return {
18
+ "input_email_body": email_body,
19
+ "list_of_masked_entities": entities,
20
+ "masked_email": masked_text,
21
+ "category_of_the_email": category
22
+ }
23
+
24
+ # Streamlit UI
25
+ email_input = st.text_area("βœ‰οΈ Enter your email text:")
26
+
27
+ if st.button("πŸš€ Classify Email"):
28
+ if email_input.strip() != "":
29
+ result = classify_email_direct(email_input)
30
+
31
+ st.subheader("πŸ”Ž Masked Email")
32
+ st.write(result['masked_email'])
33
+
34
+ st.subheader("πŸ” List of Masked Entities")
35
+ st.json(result['list_of_masked_entities'])
36
+
37
+ st.subheader("πŸ“‚ Predicted Category")
38
+ st.success(result['category_of_the_email'])
39
+ else:
40
+ st.warning("⚠️ Please enter some text first.")
41
+