Ahmed235 commited on
Commit
185fddd
·
verified ·
1 Parent(s): 8f5b1b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -14
app.py CHANGED
@@ -9,20 +9,26 @@ model_path = 'final_teath_classifier.h5'
9
  model = tf.keras.models.load_model(model_path)
10
  # Define prediction function
11
  def predict_image(image):
12
- image = image.resize((256, 256))
13
- img_array = np.array(image) / 255.0
14
- img_array = np.expand_dims(img_array, axis=0)
15
- outputs = model.predict(img_array)
16
- predictions = tf.nn.softmax(outputs.logits, axis=-1)
17
- predicted_class_index = np.argmax(predictions)
18
-
19
- # Map class index to label
20
- if predicted_class_index == 0:
21
- predicted_label = "Clean"
22
- else:
23
- predicted_label = "Carries"
24
-
25
- return {"prediction": predicted_label}
 
 
 
 
 
 
26
 
27
  # Create the interface
28
  input_interface = gr.Image(type="pil")
 
9
  model = tf.keras.models.load_model(model_path)
10
  # Define prediction function
11
  def predict_image(image):
12
+ image_bytes = io.BytesIO()
13
+ image.save(image_bytes, format="JPEG")
14
+
15
+ # Load the image from the file-like object
16
+ image = tf.keras.preprocessing.image.load_img(image_bytes, target_size=(256, 256))
17
+ image = tf.keras.preprocessing.image.img_to_array(image)
18
+ image = np.expand_dims(image, axis=0)
19
+
20
+ # Make a prediction
21
+ prediction = model.predict(image)
22
+
23
+ # Get the probability of being 'Good'
24
+ probability_good = prediction[0][0] # Assuming it's a binary classification
25
+
26
+ # Define the prediction result
27
+ result = {
28
+ "prediction": "Your Teeth are Good & You Don't Need To Visit Doctor" if probability_good > 0.5 else "Your Teeth are Bad & You Need To Visit Doctor"
29
+ }
30
+
31
+ return result
32
 
33
  # Create the interface
34
  input_interface = gr.Image(type="pil")