Spaces:
Sleeping
Sleeping
# app.py | |
from flask import Flask, render_template, request, jsonify | |
from utils import model_predict | |
app = Flask(__name__) | |
def index(): | |
""" | |
Serve the main HTML page. | |
""" | |
return render_template("index.html") | |
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) |