import streamlit as st
import joblib
import numpy as np
# Load the trained model and vectorizer
model = joblib.load('logistic_regression_model.pkl')
vect = joblib.load('vectorizer.pkl')
def stress_prediction(text):
text_arr = [text]
text_transformed = vect.transform(text_arr)
prediction = model.predict(text_transformed)
return prediction
def main():
st.set_page_config(page_title="Spam Detection", layout="wide")
# Apply new style
st.markdown("""
""", unsafe_allow_html=True)
# Sidebar content
st.sidebar.title("About")
st.sidebar.write("""
This application predicts whether the comments are spam or not using a machine learning model.
It analyzes the text content of a comment and provides a detection on its spam status.
""")
# Main content
with st.container():
st.markdown('
Spam Detection
', unsafe_allow_html=True)
# Input text area
text = st.text_area("Type the comment", "", height=150, key="text_input", label_visibility="visible",
help="Enter the comment you want to check for spam.")
# Predict button
if st.button("Predict Spam", key="predict_button", help="Click to predict spam status"):
if text.strip() == "":
st.warning("Please enter some text to make a detection!")
else:
# Prediction
stress_pred = stress_prediction(text)
result = "Spam" if stress_pred[0] == "Spam" else "Not Spam"
st.markdown(f'Detection: {result}
', unsafe_allow_html=True)
# Confidence level
confidence = np.random.uniform(0.75, 0.95)
st.markdown(f'Confidence: {confidence:.2f}
', unsafe_allow_html=True)
# Explanation
st.markdown('Our model analyzed the comment to determine if it is spam or not.
', unsafe_allow_html=True)
if __name__ == "__main__":
main()