Velar/Backend/AI/predict_api.py

28 lines
785 B
Python
Raw Normal View History

2025-05-23 05:51:16 -07:00
from flask import Flask, request, jsonify
import joblib # or pickle if you're using that
import sklearn # just to ensure compatibility if needed
import numpy as np
# Load your trained model and vectorizer
model = joblib.load("model/category_model.pkl")
vectorizer = joblib.load("model/vectorizer.pkl") # if used
app = Flask(__name__)
@app.route("/api/predict", methods=["POST"])
def predict():
data = request.json
description = data.get("description", "")
if not description:
return jsonify({"error": "Description is required"}), 400
# Preprocess and predict
X = vectorizer.transform([description])
prediction = model.predict(X)[0]
return jsonify({"category": prediction})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)