Spaces:
Sleeping
Sleeping
| import joblib | |
| import numpy as np | |
| import pandas as pd | |
| from flask import Flask, request, jsonify | |
| superkart_api = Flask(__name__) | |
| print("π Loading model...") | |
| model = joblib.load("superkart_model.joblib") | |
| print("β Model loaded.") | |
| def index(): | |
| print(f"π‘ Incoming {request.method} request to /") | |
| if request.method == "POST": | |
| try: | |
| data = request.get_json(force=True) | |
| print(f"π₯ Received JSON: {data}") | |
| input_dict = { | |
| "Product_Weight": data.get("Product_Weight", 0.0), | |
| "Product_Sugar_Content": data.get("Product_Sugar_Content", "Regular"), | |
| "Product_Allocated_Area": data.get("Product_Allocated_Area", 0.0), | |
| "Product_Type": data.get("Product_Type", "Other"), | |
| "Product_MRP": data.get("Product_MRP", 0.0), | |
| "Store_Establishment_Year": data.get("Store_Establishment_Year", 2000), | |
| "Store_Size": data.get("Store_Size", "Medium"), | |
| "Store_Location_City_Type": data.get("Store_Location_City_Type", "Tier 2"), | |
| "Store_Type": data.get("Store_Type", "Supermarket Type1") | |
| } | |
| input_df = pd.DataFrame([input_dict]) | |
| prediction = model.predict(input_df) | |
| return jsonify({"prediction": float(prediction[0])}) | |
| except Exception as e: | |
| print(f"β Error: {str(e)}") | |
| return jsonify({"error": str(e)}), 400 | |
| else: | |
| return "β SuperKart API root: ready." | |
| if __name__ == "__main__": | |
| print("π Starting Flask server...") | |
| superkart_api.run(host="0.0.0.0", port=7860) | |