saibsund's picture
Upload app.py with huggingface_hub
1f18949 verified
raw
history blame contribute delete
598 Bytes
from flask import Flask, request, jsonify
import joblib
import pandas as pd
import os
app = Flask(__name__)
# Verify model file exists
model_path = 'best_model.pkl'
if not os.path.exists(model_path):
raise FileNotFoundError(f"Model file {model_path} not found in {os.getcwd()}")
model = joblib.load(model_path)
@app.route('/predict', methods=['POST'])
def predict():
data = request.get_json(force=True)
df = pd.DataFrame([data])
prediction = model.predict(df)
return jsonify({'prediction': prediction[0]})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860)