Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,22 +19,25 @@ def predict_image(image):
|
|
| 19 |
image.save(image_bytes, format="JPEG")
|
| 20 |
|
| 21 |
# Load the image from the file-like object
|
| 22 |
-
image = tf.keras.preprocessing.image.load_img(image_bytes, target_size=(256, 256))
|
| 23 |
-
image =
|
| 24 |
image = np.expand_dims(image, axis=0)
|
| 25 |
|
| 26 |
-
|
| 27 |
prediction = model.predict(image)
|
| 28 |
|
| 29 |
-
# Get the probability of being '
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
-
"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"
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
return result
|
| 38 |
|
| 39 |
|
| 40 |
# Create the interface
|
|
@@ -44,9 +47,7 @@ output_interface = "json"
|
|
| 44 |
iface = gr.Interface(
|
| 45 |
fn=predict_image,
|
| 46 |
inputs=input_interface,
|
| 47 |
-
outputs=output_interface
|
| 48 |
-
title="<h1 style='color: lightgreen; text-align: center;'>Dentella</h1><p style='text-align: left; color: skyblue; font-size: 25px;'>Please Enter Your Teeth Here...</p>",)
|
| 49 |
-
|
| 50 |
|
| 51 |
# Launch the interface
|
| 52 |
iface.launch(share=True)
|
|
|
|
| 19 |
image.save(image_bytes, format="JPEG")
|
| 20 |
|
| 21 |
# Load the image from the file-like object
|
| 22 |
+
image = tf.keras.preprocessing.image.load_img(image_bytes, target_size=(256, 256,3))
|
| 23 |
+
image = np.array(image)/255
|
| 24 |
image = np.expand_dims(image, axis=0)
|
| 25 |
|
| 26 |
+
# Make a prediction
|
| 27 |
prediction = model.predict(image)
|
| 28 |
|
| 29 |
+
# Get the probability of being 'Clean' or 'Carries'
|
| 30 |
+
probabilities = tf.nn.softmax(prediction, axis=-1)
|
| 31 |
+
predicted_class_index = np.argmax(probabilities)
|
| 32 |
+
if predicted_class_index == 1:
|
| 33 |
+
predicted_label = "Clean"
|
| 34 |
+
predicted_probability = probabilities[0][1] * 100 # Convert to percentage
|
| 35 |
+
elif predicted_class_index == 0:
|
| 36 |
+
predicted_label = "Carries"
|
| 37 |
+
predicted_probability = probabilities[0][0] * 100 # Convert to percentage
|
| 38 |
|
| 39 |
+
# Return the prediction result as a dictionary
|
| 40 |
+
return {"Predicted Label": predicted_label}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
# Create the interface
|
|
|
|
| 47 |
iface = gr.Interface(
|
| 48 |
fn=predict_image,
|
| 49 |
inputs=input_interface,
|
| 50 |
+
outputs=output_interface)
|
|
|
|
|
|
|
| 51 |
|
| 52 |
# Launch the interface
|
| 53 |
iface.launch(share=True)
|