Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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")
|