Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,27 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 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 |
-
print(classification_report(y_test, y_pred))
|
| 29 |
-
|
| 30 |
-
return model, vectorizer
|
| 31 |
-
|
| 32 |
-
def predict_spam(email_text):
|
| 33 |
-
email_count = vectorizer.transform([email_text])
|
| 34 |
-
prediction = model.predict(email_count)[0]
|
| 35 |
-
return "Spam ❌" if prediction == 1 else "Not Spam"
|
| 36 |
-
df = load_data()
|
| 37 |
-
model, vectorizer = train_model(df)
|
| 38 |
-
|
| 39 |
-
interface = gr.Interface(
|
| 40 |
-
fn=predict_spam,
|
| 41 |
-
inputs=gr.Textbox(lines=5, placeholder="Paste your email text here..."),
|
| 42 |
-
outputs="text",
|
| 43 |
-
title="Email Spam Detector",
|
| 44 |
-
description="A machine learning model using Naive Bayes to detect whether an email is spam or not."
|
| 45 |
-
)
|
| 46 |
-
interface.launch()
|
|
|
|
| 1 |
+
from flask import Flask, render_template, request
|
| 2 |
+
import joblib
|
| 3 |
+
|
| 4 |
+
app = Flask(__name__)
|
| 5 |
+
|
| 6 |
+
# Load trained model
|
| 7 |
+
model = joblib.load("EmailSpamdetection.joblib")
|
| 8 |
+
|
| 9 |
+
@app.route("/", methods=["GET", "POST"])
|
| 10 |
+
def index():
|
| 11 |
+
prediction = None
|
| 12 |
+
|
| 13 |
+
if request.method == "POST":
|
| 14 |
+
email_text = request.form["email"]
|
| 15 |
+
|
| 16 |
+
# Model expects list-like input
|
| 17 |
+
result = model.predict([email_text])[0]
|
| 18 |
+
|
| 19 |
+
if result == 1:
|
| 20 |
+
prediction = "🚫 Spam Email"
|
| 21 |
+
else:
|
| 22 |
+
prediction = "✅ Not Spam Email"
|
| 23 |
+
|
| 24 |
+
return render_template("index.html", prediction=prediction)
|
| 25 |
+
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
app.run(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|