LovnishVerma commited on
Commit
d639100
·
verified ·
1 Parent(s): 5b10748

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -28,10 +28,17 @@ def predict():
28
  data["petal_width"]
29
  ]
30
 
31
- prediction = model.predict([features])[0] # Get scalar (0,1,2)
 
 
 
 
 
 
32
  target_names = load_iris().target_names
33
  return jsonify({"prediction": target_names[int(prediction)]})
34
 
35
 
 
36
  if __name__ == "__main__":
37
  app.run(host="0.0.0.0", port=7860)
 
28
  data["petal_width"]
29
  ]
30
 
31
+ prediction = model.predict([features])[0] # could be int or string
32
+
33
+ # If prediction is already a string (class label)
34
+ if isinstance(prediction, str):
35
+ return jsonify({"prediction": prediction})
36
+
37
+ # If prediction is numeric (0, 1, 2)
38
  target_names = load_iris().target_names
39
  return jsonify({"prediction": target_names[int(prediction)]})
40
 
41
 
42
+
43
  if __name__ == "__main__":
44
  app.run(host="0.0.0.0", port=7860)