behlil's picture
Update app.py
16c3c1f verified
raw
history blame contribute delete
855 Bytes
# app.py
from flask import Flask, render_template, request, jsonify
from utils import model_predict
app = Flask(__name__)
@app.route("/", methods=["GET"])
def index():
"""
Serve the main HTML page.
"""
return render_template("index.html")
@app.route("/predict", methods=["POST"])
def predict():
"""
Handle POST requests for email classification.
"""
data = request.json
email_content = data.get("email", "").strip()
if not email_content:
return jsonify({"error": "Please enter some text to classify."}), 400
prediction = model_predict(email_content)
result = "SPAM" if prediction == 1 else "NOT SPAM"
return jsonify({"result": result})
if __name__ == "__main__":
# Run the app on all available IPs (0.0.0.0) and port 7860
app.run(host="0.0.0.0", port=7860, debug=True)