Spaces:
Sleeping
Sleeping
Download app.py from rahularorarahul/ExtraaLearn: direct link, hf CLI and curl.
- Browser
- Download file 932 Bytes
-
https://huggingface.co/spaces/rahularorarahul/ExtraaLearn/resolve/main/app.py
- Command line
-
hf download hf://spaces/rahularorarahul/ExtraaLearn/app.py
-
curl -L -o app.py https://huggingface.co/spaces/rahularorarahul/ExtraaLearn/resolve/main/app.py
932 Bytes
| from flask import Flask, request, jsonify | |
| import joblib | |
| import pandas as pd | |
| app = Flask(__name__) | |
| # Load the serialized model | |
| # Ensure 'extraalearn_lead_model.joblib' is in the same directory | |
| model = joblib.load('extraalearn_lead_model.joblib') | |
| def predict(): | |
| try: | |
| # Get JSON data from the request | |
| data = request.get_json() | |
| # Convert the dictionary to a DataFrame | |
| # The keys in the JSON must match the column names expected by the model | |
| df = pd.DataFrame([data]) | |
| # Make a prediction | |
| prediction = model.predict(df) | |
| # Return the result as JSON | |
| return jsonify({'prediction': int(prediction[0])}) | |
| except Exception as e: | |
| return jsonify({'error': str(e)}) | |
| if __name__ == '__main__': | |
| # Hugging Face Spaces defaults to port 7860 | |
| app.run(host='0.0.0.0', port=7860) |