Spaces:
Runtime error
Runtime error
spam-email
Browse files- app.py +26 -0
- index.html +47 -0
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template, request, jsonify
|
| 2 |
+
from utils import model_predict
|
| 3 |
+
app = Flask(__name__)
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
@app.route("/")
|
| 7 |
+
def home():
|
| 8 |
+
return render_template("index.html")
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@app.route('/predict', methods=['POST'])
|
| 12 |
+
def predict():
|
| 13 |
+
email = request.form.get('content')
|
| 14 |
+
prediction = model_predict(email)
|
| 15 |
+
return render_template("index.html", prediction=prediction, email=email)
|
| 16 |
+
|
| 17 |
+
# Create an API endpoint
|
| 18 |
+
@app.route('/api/predict', methods=['POST'])
|
| 19 |
+
def predict_api():
|
| 20 |
+
data = request.get_json(force=True) # Get data posted as a json
|
| 21 |
+
email = data['content']
|
| 22 |
+
prediction = model_predict(email)
|
| 23 |
+
return jsonify({'prediction': prediction, 'email': email}) # Return prediction
|
| 24 |
+
|
| 25 |
+
if __name__ == "__main__":
|
| 26 |
+
app.run(host="0.0.0.0", port=8080, debug=True)
|
index.html
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
|
| 4 |
+
<head>
|
| 5 |
+
<title>
|
| 6 |
+
Email Spam Classifier
|
| 7 |
+
</title>
|
| 8 |
+
<style>
|
| 9 |
+
body {
|
| 10 |
+
text-align: center;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
button {
|
| 14 |
+
color: aliceblue;
|
| 15 |
+
background-color: blue;
|
| 16 |
+
}
|
| 17 |
+
</style>
|
| 18 |
+
</head>
|
| 19 |
+
|
| 20 |
+
<body>
|
| 21 |
+
<h1>Email Spam Classifier</h1>
|
| 22 |
+
<div>
|
| 23 |
+
<form method="post" action="/predict">
|
| 24 |
+
<textarea rows="12" cols="60" name="content" placeholder="Enter your email here"
|
| 25 |
+
autocomplete="off">{{ email }}</textarea>
|
| 26 |
+
<div>
|
| 27 |
+
<button type="submit">
|
| 28 |
+
Predict
|
| 29 |
+
</button>
|
| 30 |
+
<a href="/">Reset</a>
|
| 31 |
+
</div>
|
| 32 |
+
</form>
|
| 33 |
+
|
| 34 |
+
</div>
|
| 35 |
+
<div>
|
| 36 |
+
{% if prediction %}
|
| 37 |
+
{% if prediction == 1 %}
|
| 38 |
+
<h2 style="color: red">Spam</h2>
|
| 39 |
+
{% else %}
|
| 40 |
+
<h2 style="color: green">Not Spam</h2>
|
| 41 |
+
{% endif %}
|
| 42 |
+
{% endif %}
|
| 43 |
+
<!-- <p id="display"></p> -->
|
| 44 |
+
</div>
|
| 45 |
+
</body>
|
| 46 |
+
|
| 47 |
+
</html>
|