File size: 855 Bytes
42ec8c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16c3c1f
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
# 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)