creativitysupreme's picture
Upload app.py with huggingface_hub
4d4fd92 verified
Raw History Blame Contribute Delete
1.01 kB
from flask import Flask, request, jsonify
import joblib
import pandas as pd
import numpy as np
app = Flask(__name__)
# Load the serialized model pipeline
model = joblib.load('superkart_model.pkl')
@app.route('/', methods=['GET'])
def home():
return jsonify({
'message': 'SuperKart Sales Prediction API is running!',
'status': 'healthy'
})
@app.route('/predict', methods=['POST'])
def predict():
try:
data = request.get_json()
# Handle both single and batch predictions
if isinstance(data, dict):
data = [data]
df = pd.DataFrame(data)
# Make predictions
predictions = model.predict(df)
return jsonify({
'predictions': predictions.tolist(),
'status': 'success'
})
except Exception as e:
return jsonify({'error': str(e), 'status': 'failure'}), 400
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860)