vinsensius13 commited on
Commit
beb7870
Β·
1 Parent(s): 61bb578
Files changed (2) hide show
  1. README.md +108 -7
  2. app.py +1 -4
README.md CHANGED
@@ -1,10 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
- title: Iris
3
- emoji: πŸ’»
4
- colorFrom: red
5
- colorTo: gray
6
- sdk: docker
7
- pinned: false
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🌸 Iris Classifier API 🌸
2
+
3
+ A simple Flask API that predicts the species of iris flowers using a pre-trained Scikit-Learn model.
4
+ This app is deployed on [Hugging Face Spaces](https://huggingface.co/spaces/vnsd13/iris) and served via Docker using Gunicorn.
5
+
6
+ ---
7
+
8
+ ## πŸ” What is this?
9
+
10
+ This API receives 4 numeric features from the Iris dataset:
11
+
12
+ * Sepal Length
13
+ * Sepal Width
14
+ * Petal Length
15
+ * Petal Width
16
+
17
+ And returns the predicted iris species using a `DecisionTreeClassifier`.
18
+
19
+ ---
20
+
21
+ ## πŸ“† Model
22
+
23
+ * Trained with `scikit-learn==1.6.1`
24
+ * Saved with `joblib`
25
+ * Stored in `models/model.pkl`
26
+
27
+ ---
28
+
29
+ ## πŸš€ How to Use
30
+
31
+ ### πŸͺͺ API Endpoints
32
+
33
+ #### `GET /`
34
+
35
+ Returns basic info to confirm that the app is running.
36
+
37
+ **Response:**
38
+
39
+ ```
40
+ Iris Classifier API is running!
41
+ ```
42
+
43
+ ---
44
+
45
+ #### `POST /predict`
46
+
47
+ Predict the iris flower class based on features.
48
+
49
+ **Request Body (JSON):**
50
+
51
+ ```json
52
+ {
53
+ "sepal_length": 5.1,
54
+ "sepal_width": 3.5,
55
+ "petal_length": 1.4,
56
+ "petal_width": 0.2
57
+ }
58
+ ```
59
+
60
+ **Response:**
61
+
62
+ ```json
63
+ {
64
+ "prediction": "setosa"
65
+ }
66
+ ```
67
+
68
  ---
69
+
70
+ ## 🐳 Docker Support
71
+
72
+ App is built using the following `Dockerfile`:
73
+
74
+ ```dockerfile
75
+ FROM python:3.10
76
+
77
+ WORKDIR /app
78
+
79
+ COPY requirements.txt .
80
+ RUN pip install -r requirements.txt
81
+
82
+ COPY . .
83
+
84
+ CMD ["gunicorn", "-b", "0.0.0.0:7860", "app:app"]
85
+ ```
86
+
87
+ ---
88
+
89
+ ## πŸ“š Requirements
90
+
91
+ ```
92
+ flask
93
+ numpy
94
+ scikit-learn==1.6.1
95
+ joblib
96
+ gunicorn
97
+ ```
98
+
99
  ---
100
 
101
+ ## πŸ“± Deployment
102
+
103
+ This API is currently deployed to Hugging Face Spaces using Docker interface.
104
+
105
+ URL: [https://vnsd13-iris.hf.space](https://vnsd13-iris.hf.space)
106
+
107
+ ---
108
+
109
+ ## πŸ‘¨β€πŸ’» Author
110
+
111
+ Made by [@vnsd13](https://huggingface.co/vnsd13)
app.py CHANGED
@@ -21,9 +21,6 @@ def predict():
21
  float(data["petal_width"]),
22
  ]
23
  prediction = model.predict([features])
24
- return jsonify({"prediction": prediction[0]})
25
  except Exception as e:
26
  return jsonify({"error": str(e)}), 400
27
-
28
- # NOTE: Don't run app here if you're using Gunicorn
29
- # Gunicorn will handle the server initialization
 
21
  float(data["petal_width"]),
22
  ]
23
  prediction = model.predict([features])
24
+ return jsonify({"prediction": int(prediction[0])}) # <-- Fix disini
25
  except Exception as e:
26
  return jsonify({"error": str(e)}), 400