Ahmed235 commited on
Commit
1acad40
·
verified ·
1 Parent(s): 95c2dbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -10
app.py CHANGED
@@ -10,14 +10,7 @@ model_path = 'final_teath_classifier.h5'
10
  model = tf.keras.models.load_model(model_path)
11
 
12
  # Define preprocessing function
13
- def preprocess_image(image):
14
- # Resize the image to match input size
15
- #image = image.resize((256, 256))
16
- # Convert image to array and preprocess input
17
- image = tf.keras.preprocessing.image.img_to_array(image)
18
- # Add batch dimension
19
- img_array = np.expand_dims(image, axis=0)
20
- return img_array
21
 
22
  # Define prediction function
23
  def predict_image(image):
@@ -26,7 +19,8 @@ def predict_image(image):
26
  image.save(image_bytes, format="JPEG")
27
  # Load the image from the file-like object
28
  image = tf.keras.preprocessing.image.load_img(image_bytes, target_size=(256, 256))
29
- img_array = preprocess_image(image)
 
30
  outputs = model.predict(img_array)
31
  predictions = tf.nn.softmax(outputs.logits, axis=-1)
32
  predicted_class = np.argmax(predictions)
@@ -36,7 +30,9 @@ def predict_image(image):
36
  predict_label = "Carries"
37
  confidence = float(np.max(predictions))
38
  prediction_dict = {"prediction": predict_label, "confidence": confidence}
39
- return prediction_dict
 
 
40
 
41
  # Create the interface
42
  input_interface = gr.Image(type = "pil")
 
10
  model = tf.keras.models.load_model(model_path)
11
 
12
  # Define preprocessing function
13
+
 
 
 
 
 
 
 
14
 
15
  # Define prediction function
16
  def predict_image(image):
 
19
  image.save(image_bytes, format="JPEG")
20
  # Load the image from the file-like object
21
  image = tf.keras.preprocessing.image.load_img(image_bytes, target_size=(256, 256))
22
+ image = tf.keras.preprocessing.image.img_to_array(image)
23
+ img_array = np.expand_dims(image, axis=0)
24
  outputs = model.predict(img_array)
25
  predictions = tf.nn.softmax(outputs.logits, axis=-1)
26
  predicted_class = np.argmax(predictions)
 
30
  predict_label = "Carries"
31
  confidence = float(np.max(predictions))
32
  prediction_dict = {"prediction": predict_label, "confidence": confidence}
33
+ #return prediction_dict
34
+ probability_good = outputs[0][0]
35
+ return probability_good
36
 
37
  # Create the interface
38
  input_interface = gr.Image(type = "pil")