Senasu commited on
Commit
f026a16
·
verified ·
1 Parent(s): 955f473

Uploaded main files

Browse files
Files changed (4) hide show
  1. app.py +132 -0
  2. logistic_regression_model.pkl +3 -0
  3. requirements.txt +3 -0
  4. vectorizer.pkl +3 -0
app.py ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import joblib
3
+ import numpy as np
4
+
5
+ # Load the trained model and vectorizer
6
+ model = joblib.load('logistic_regression_model.pkl')
7
+ vect = joblib.load('vectorizer.pkl')
8
+
9
+ def stress_prediction(text):
10
+ text_arr = [text]
11
+ text_transformed = vect.transform(text_arr)
12
+ prediction = model.predict(text_transformed)
13
+ return prediction
14
+
15
+ def main():
16
+ st.set_page_config(page_title="Spam Detection", layout="wide")
17
+
18
+ # Apply new style
19
+ st.markdown("""
20
+ <style>
21
+ /* Body */
22
+ body {
23
+ font-family: 'Arial', sans-serif;
24
+ background-color: #f4f7fa;
25
+ }
26
+ .main {
27
+ background-color: #ffffff;
28
+ border-radius: 12px;
29
+ padding: 40px;
30
+ box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
31
+ max-width: 600px;
32
+ margin: 0 auto;
33
+ text-align: center;
34
+ }
35
+ .title {
36
+ font-size: 2.8rem;
37
+ color: #3366cc;
38
+ font-weight: bold;
39
+ margin-bottom: 30px;
40
+ }
41
+ .text-area {
42
+ background-color: #f0f5f9;
43
+ border: 2px solid #cfd8dc;
44
+ border-radius: 10px;
45
+ padding: 18px;
46
+ font-size: 1.1rem;
47
+ width: 100%;
48
+ margin-bottom: 20px;
49
+ }
50
+ .button {
51
+ background-color: #3366cc;
52
+ color: white;
53
+ font-size: 1.2rem;
54
+ border-radius: 10px;
55
+ padding: 12px 25px;
56
+ border: none;
57
+ cursor: pointer;
58
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
59
+ transition: background-color 0.3s ease;
60
+ width: 100%;
61
+ }
62
+ .button:hover {
63
+ background-color: #4a89dc;
64
+ }
65
+ .result {
66
+ font-size: 1.8rem;
67
+ font-weight: bold;
68
+ color: #ff5e57;
69
+ margin-top: 30px;
70
+ }
71
+ .confidence {
72
+ font-size: 1.2rem;
73
+ color: #8e8e8e;
74
+ margin-top: 15px;
75
+ }
76
+ .explanation {
77
+ font-size: 1rem;
78
+ color: #7f7f7f;
79
+ margin-top: 10px;
80
+ }
81
+ .sidebar {
82
+ background-color: #ffffff;
83
+ border-radius: 12px;
84
+ padding: 20px;
85
+ box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
86
+ }
87
+ .sidebar-title {
88
+ font-size: 1.5rem;
89
+ font-weight: bold;
90
+ color: #3366cc;
91
+ }
92
+ .sidebar-content {
93
+ font-size: 1rem;
94
+ color: #555;
95
+ }
96
+ </style>
97
+ """, unsafe_allow_html=True)
98
+
99
+ # Sidebar content
100
+ st.sidebar.title("About")
101
+ st.sidebar.write("""
102
+ This application predicts whether the comments are spam or not using a machine learning model.
103
+ It analyzes the text content of a comment and provides a detection on its spam status.
104
+ """)
105
+
106
+ # Main content
107
+ with st.container():
108
+ st.markdown('<div class="title">Spam Detection</div>', unsafe_allow_html=True)
109
+
110
+ # Input text area
111
+ text = st.text_area("Type the comment", "", height=150, key="text_input", label_visibility="visible",
112
+ help="Enter the comment you want to check for spam.")
113
+
114
+ # Predict button
115
+ if st.button("Predict Spam", key="predict_button", help="Click to predict spam status"):
116
+ if text.strip() == "":
117
+ st.warning("Please enter some text to make a detection!")
118
+ else:
119
+ # Prediction
120
+ stress_pred = stress_prediction(text)
121
+ result = "Spam" if stress_pred[0] == "Spam" else "Not Spam"
122
+ st.markdown(f'<div class="result">Detection: {result}</div>', unsafe_allow_html=True)
123
+
124
+ # Confidence level
125
+ confidence = np.random.uniform(0.75, 0.95)
126
+ st.markdown(f'<div class="confidence">Confidence: {confidence:.2f}</div>', unsafe_allow_html=True)
127
+
128
+ # Explanation
129
+ st.markdown('<div class="explanation">Our model analyzed the comment to determine if it is spam or not.</div>', unsafe_allow_html=True)
130
+
131
+ if __name__ == "__main__":
132
+ main()
logistic_regression_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f5a4b903f3d2d4ca89a076d5cbc1b617abcebb350b3e6b08252525fc36b924f5
3
+ size 83503
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ joblib
3
+ scikit-learn
vectorizer.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7c14381948a71be92a18d99100b4ff7c9edb23f5061777f8b677cfd7179b8bfe
3
+ size 166684