Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,10 +9,10 @@ model = tf.keras.models.load_model('Model_catsVSdogs.h5')
|
|
| 9 |
# Define a function to make predictions
|
| 10 |
def predict_image(img):
|
| 11 |
# Preprocess the image
|
| 12 |
-
img = img.resize((
|
| 13 |
-
img_array = image.img_to_array(img)
|
| 14 |
-
img_array = np.expand_dims(img_array, axis=0)
|
| 15 |
-
img_array = img_array / 255.0
|
| 16 |
|
| 17 |
# Make a prediction
|
| 18 |
prediction = model.predict(img_array)
|
|
@@ -22,14 +22,12 @@ def predict_image(img):
|
|
| 22 |
return "Dog"
|
| 23 |
|
| 24 |
# Create the Gradio interface
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
examples=["cat_example.jpg", "dog_example.jpg"]
|
| 32 |
-
)
|
| 33 |
|
| 34 |
# Launch the interface
|
| 35 |
-
|
|
|
|
| 9 |
# Define a function to make predictions
|
| 10 |
def predict_image(img):
|
| 11 |
# Preprocess the image
|
| 12 |
+
img = img.resize((256,256)) # Resize the image to 224x224 pixels
|
| 13 |
+
img_array = image.img_to_array(img) # Convert the image to an array
|
| 14 |
+
img_array = np.expand_dims(img_array, axis=0) # Add a batch dimension
|
| 15 |
+
img_array = img_array / 255.0 # Normalize the image
|
| 16 |
|
| 17 |
# Make a prediction
|
| 18 |
prediction = model.predict(img_array)
|
|
|
|
| 22 |
return "Dog"
|
| 23 |
|
| 24 |
# Create the Gradio interface
|
| 25 |
+
|
| 26 |
+
interface = gr.Interface(fn=predict_image,
|
| 27 |
+
inputs=gr.Image(type="pil"),
|
| 28 |
+
outputs="text",
|
| 29 |
+
title="Cat and Dog Classifier",
|
| 30 |
+
description="Upload an image of a cat or dog and the model will predict which one it is.")
|
|
|
|
|
|
|
| 31 |
|
| 32 |
# Launch the interface
|
| 33 |
+
interface.launch()
|