Download app.py from vnsd13/iris: direct link, hf CLI and curl.
- Browser
- Download file 937 Bytes
-
https://huggingface.co/spaces/vnsd13/iris/resolve/main/app.py
- Command line
-
hf download hf://spaces/vnsd13/iris/app.py
-
curl -L -o app.py https://huggingface.co/spaces/vnsd13/iris/resolve/main/app.py
937 Bytes
| from flask import Flask, request, jsonify | |
| import joblib | |
| import json | |
| app = Flask(__name__) | |
| # Load model | |
| model = joblib.load("models/model.pkl") | |
| # Load label mapping | |
| with open("models/labels.json", "r") as f: | |
| label_map = json.load(f) | |
| def index(): | |
| return "Iris Classifier API is running!" | |
| def predict(): | |
| try: | |
| data = request.get_json() | |
| features = [ | |
| float(data["sepal_length"]), | |
| float(data["sepal_width"]), | |
| float(data["petal_length"]), | |
| float(data["petal_width"]), | |
| ] | |
| prediction = model.predict([features]) | |
| pred_index = int(prediction[0]) | |
| pred_label = label_map.get(str(pred_index), "unknown") | |
| return jsonify({ | |
| "prediction": pred_index, | |
| "label": pred_label | |
| }) | |
| except Exception as e: | |
| return jsonify({"error": str(e)}), 400 | |