-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
38 lines (30 loc) · 1.06 KB
/
app.py
File metadata and controls
38 lines (30 loc) · 1.06 KB
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
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
import pickle
# Load the saved vectorizer and model
tfidf = pickle.load(open('vectorizer.pkl', 'rb'))
model = pickle.load(open('model.pkl', 'rb'))
def predict_spam(text):
# Transform the input text using the loaded vectorizer
vector_input = tfidf.transform([text])
# Predict using the loaded model
result = model.predict(vector_input)[0]
return "Spam" if result == 1 else "Not Spam"
# Example usage
message = "Congratulations! You've won a free prize. Click here to claim."
print(predict_spam(message))
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict', methods=['POST'])
def predict():
msg = request.json['message']
print("Prediction: ",msg)
# TODO: Add your spam classification logic here
# For now, returning a placeholder response
return jsonify({
'prediction': predict_spam(msg), # Replace with actual prediction
'message': msg
})
if __name__ == '__main__':
app.run(debug=True)