-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
48 lines (38 loc) · 1.17 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# imports
import streamlit as st
import pickle , sys , nltk
sys.path.append("./src")
from src import textPreprocessor as tp
# import models
with open("./src/classifier.pkl","rb") as f:
classifier = pickle.load(f)
with open("./src/vectorizer.pkl","rb") as f:
vecotrizer = pickle.load(f)
nltk.download("punkt")
nltk.download("stopwords")
# app configuration
st.set_page_config(
page_title="SMS Spam Classifier",
page_icon="./src/icon.png"
)
# app body
st.title("SMS Spam Classifier")
message = st.text_area("Message",placeholder="Enter message here",key="input")
col1 , col2 = st.columns(2)
def clear_text():
st.session_state["input"] = ""
with col1:
if st.button("Predict",use_container_width=True):
if message == "":
pass
else:
message = tp.textPreprocessor(message)
message = vecotrizer.transform([message]).toarray()
result = classifier.predict(message)[0]
if result == 0:
st.header("Not spam")
else:
st.header("Spam")
with col2:
if st.button("Clear",use_container_width=True,type="primary",on_click=clear_text):
pass