TheVixhal commited on
Commit
d98beaa
1 Parent(s): 7706094

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +41 -0
  2. spam.pkl +3 -0
  3. templates/index.html +94 -0
  4. vector.pkl +3 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, render_template
2
+ import joblib
3
+ import numpy as np
4
+
5
+ # Initialize the Flask application
6
+ app = Flask(__name__)
7
+
8
+ # Load the trained model and TF-IDF vectorizer
9
+ model = joblib.load('spam.pkl')
10
+ vectorizer = joblib.load('vector.pkl')
11
+
12
+ @app.route('/', methods=['GET', 'POST'])
13
+ def index():
14
+ if request.method == 'POST':
15
+ # Get the comment from the form
16
+ comment = request.form['comment']
17
+
18
+ # Debug: Print the received comment
19
+ print(f"Received comment: {comment}")
20
+
21
+ # Transform the comment using the loaded vectorizer
22
+ comment_transformed = vectorizer.transform([comment])
23
+
24
+ # Debug: Print the transformed comment
25
+ print(f"Transformed comment: {comment_transformed.toarray()}")
26
+
27
+ # Predict using the loaded model
28
+ prediction = model.predict(comment_transformed)
29
+
30
+ # Debug: Print the prediction
31
+ print(f"Prediction: {prediction}")
32
+
33
+ # Determine if it's spam or not
34
+ result = 'SPAM' if prediction == 'Spam' else 'NOT-SPAM'
35
+
36
+ return render_template('index.html', comment=comment, result=result)
37
+
38
+ return render_template('index.html')
39
+
40
+ if __name__ == '__main__':
41
+ app.run(debug=True)
spam.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:972763aa315963feea4c13e302e16a04a411bb38d7163e93dca4cdfdeb49132a
3
+ size 21607
templates/index.html ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Spam Comment Detection</title>
7
+ <style>
8
+ body {
9
+ font-family: Arial, sans-serif;
10
+ background-color: #f4f4f9;
11
+ margin: 0;
12
+ padding: 0;
13
+ display: flex;
14
+ justify-content: center;
15
+ align-items: center;
16
+ min-height: 100vh;
17
+ color: #333;
18
+ }
19
+ .container {
20
+ background-color: #fff;
21
+ padding: 20px;
22
+ border-radius: 8px;
23
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
24
+ max-width: 500px;
25
+ width: 90%;
26
+ text-align: center;
27
+ animation: fadeIn 1s ease-in-out;
28
+ }
29
+ h1 {
30
+ margin-bottom: 20px;
31
+ }
32
+ label {
33
+ display: block;
34
+ margin-bottom: 10px;
35
+ font-weight: bold;
36
+ }
37
+ textarea {
38
+ width: 100%;
39
+ padding: 10px;
40
+ border-radius: 5px;
41
+ border: 1px solid #ccc;
42
+ margin-bottom: 20px;
43
+ resize: vertical;
44
+ min-height: 100px;
45
+ transition: all 0.3s ease;
46
+ }
47
+ textarea:focus {
48
+ border-color: #007BFF;
49
+ box-shadow: 0 0 8px rgba(0, 123, 255, 0.2);
50
+ }
51
+ input[type="submit"] {
52
+ background-color: #007BFF;
53
+ color: white;
54
+ border: none;
55
+ padding: 10px 20px;
56
+ border-radius: 5px;
57
+ cursor: pointer;
58
+ font-size: 16px;
59
+ transition: background-color 0.3s ease;
60
+ }
61
+ input[type="submit"]:hover {
62
+ background-color: #0056b3;
63
+ }
64
+ .result {
65
+ margin-top: 20px;
66
+ font-size: 18px;
67
+ animation: fadeIn 1s ease-in-out;
68
+ }
69
+ @keyframes fadeIn {
70
+ from {
71
+ opacity: 0;
72
+ }
73
+ to {
74
+ opacity: 1;
75
+ }
76
+ }
77
+ </style>
78
+ </head>
79
+ <body>
80
+ <div class="container">
81
+ <h1>Spam Comment Detection</h1>
82
+ <form method="POST">
83
+ <label for="comment">Enter your comment:</label>
84
+ <textarea id="comment" name="comment" rows="1" cols="1" placeholder="Type your comment here..."></textarea><br>
85
+ <input type="submit" value="Check">
86
+ </form>
87
+ {% if result %}
88
+ <div class="result">
89
+ <h2>Result: {{ result }}</h2>
90
+ </div>
91
+ {% endif %}
92
+ </div>
93
+ </body>
94
+ </html>
vector.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5e2ca94b965ba804d25758adf1f1aba9f70820111e84e934eb5f62ee6b2eee72
3
+ size 7540