Ahmed235 commited on
Commit
d0c5f8e
1 Parent(s): e52c06e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -23,7 +23,7 @@ def preprocess_image(image):
23
  def predict_image(image):
24
  # Save the image to a file-like object
25
  image_bytes = io.BytesIO()
26
- image.save(image_bytes, format="jpg")
27
  image_bytes.seek(0) # Reset file pointer to start
28
 
29
  # Load the image from the file-like object
@@ -32,9 +32,16 @@ def predict_image(image):
32
  img_array = preprocess_image(image)
33
  outputs = model.predict(img_array)
34
  predictions = tf.nn.softmax(outputs.logits, axis=-1)
35
- predicted_class = np.argmax(predictions)
36
- #confidence = float(np.max(predictions))
37
- return{"prediction": predicted_class}
 
 
 
 
 
 
 
38
  #return json.dumps(prediction_dict, indent=1)
39
 
40
  # Create the interface
 
23
  def predict_image(image):
24
  # Save the image to a file-like object
25
  image_bytes = io.BytesIO()
26
+ image.save(image_bytes, format="jpeg")
27
  image_bytes.seek(0) # Reset file pointer to start
28
 
29
  # Load the image from the file-like object
 
32
  img_array = preprocess_image(image)
33
  outputs = model.predict(img_array)
34
  predictions = tf.nn.softmax(outputs.logits, axis=-1)
35
+ predicted_class_index = np.argmax(predictions)
36
+
37
+ # Map class index to label
38
+ if predicted_class_index == 0:
39
+ predicted_label = "Clean"
40
+ else:
41
+ predicted_label = "Carries"
42
+
43
+ return {"prediction": predicted_label}
44
+
45
  #return json.dumps(prediction_dict, indent=1)
46
 
47
  # Create the interface