Spaces:
Sleeping
Sleeping
| import joblib | |
| import pandas as pd | |
| import numpy as np | |
| from flask import Flask, request, jsonify | |
| # Load model | |
| model = joblib.load("tuned_random_forest.joblib") | |
| # Preprocessing pipeline must match training | |
| # For now, assume incoming JSON already matches feature schema | |
| app = Flask(__name__) | |
| # Define a route for the home page | |
| def home(): | |
| return "Welcome to the SuperKart Prediction API!" | |
| def health(): | |
| return jsonify({"status": "ok"}), 200 | |
| def predict(): | |
| try: | |
| data = request.get_json() | |
| df = pd.DataFrame([data]) # single row input | |
| y_pred_log = model.predict(df) | |
| y_pred = np.expm1(y_pred_log) # inverse log1p | |
| return jsonify({"prediction": float(y_pred[0])}) | |
| except Exception as e: | |
| return jsonify({"error": str(e)}), 400 | |
| if __name__ == '__main__': | |
| app.run(host="0.0.0.0", port=7860, debug=True) | |