File size: 1,098 Bytes
49619a7
 
 
 
 
 
d15307f
49619a7
 
 
 
0907920
 
 
 
49619a7
 
 
 
 
 
 
 
 
0907920
 
 
 
 
 
49619a7
 
0907920
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import gradio as gr
import tensorflow as tf
from tensorflow.keras.preprocessing import image
import numpy as np

# Load the trained model
model = tf.keras.models.load_model('Model_catsVSdogs.h5')

# Define a function to make predictions
def predict_image(img):
    # Preprocess the image
    img = img.resize((256,256))  # Resize the image to 224x224 pixels
    img_array = image.img_to_array(img)  # Convert the image to an array
    img_array = np.expand_dims(img_array, axis=0)  # Add a batch dimension
    img_array = img_array / 255.0  # Normalize the image

    # Make a prediction
    prediction = model.predict(img_array)
    if prediction[0] < 0.5:
        return "Cat"
    else:
        return "Dog"

# Create the Gradio interface

interface = gr.Interface(fn=predict_image, 
                         inputs=gr.Image(type="pil"), 
                         outputs="text",
                         title="Cat and Dog Classifier",
                         description="Upload an image of a cat or dog and the model will predict which one it is.")

# Launch the interface
interface.launch()