navpan2 commited on
Commit
a8be889
·
verified ·
1 Parent(s): 5183e44

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +3 -3
main.py CHANGED
@@ -81,8 +81,8 @@ def preprocess_image(image_data, img_size=224):
81
  def predict_image(image_data):
82
  preprocessed_image = preprocess_image(image_data)
83
  predictions = model.predict(preprocessed_image)
84
- class_idx = np.argmax(predictions, axis=1)[0]
85
- confidence = predictions[0][class_idx]
86
  class_label = class_labels.get(class_idx, "Unknown")
87
  if class_label is None:
88
  return {
@@ -113,4 +113,4 @@ async def api_predict_image(file: UploadFile = File(...)):
113
 
114
  # Run the FastAPI app
115
  if __name__ == "__main__":
116
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
81
  def predict_image(image_data):
82
  preprocessed_image = preprocess_image(image_data)
83
  predictions = model.predict(preprocessed_image)
84
+ class_idx = int(np.argmax(predictions, axis=1)[0]) # Convert to int for JSON serialization
85
+ confidence = float(predictions[0][class_idx]) # Convert to float for JSON serialization
86
  class_label = class_labels.get(class_idx, "Unknown")
87
  if class_label is None:
88
  return {
 
113
 
114
  # Run the FastAPI app
115
  if __name__ == "__main__":
116
+ uvicorn.run(app, host="0.0.0.0", port=7860)