File size: 791 Bytes
a272233
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from tensorflow import keras
import numpy as np
from PIL import Image

model = keras.models.load_model('dog_cat.keras')

def classify_image(image):
    image = image.resize((255, 255)) 
    img_array = np.array(image) / 255.0 
    img_array = np.expand_dims(img_array, axis=0)
    print(img_array.shape)
    # Predict using the model
    prediction = model.predict(img_array)[0][0] 
    
    # Interpret the prediction
    if prediction > 0.50:
        result = "Dog"
    else:
        result = "Cat"
    return result

# Gradio Interface
demo = gr.Interface(
    fn=classify_image,
    inputs=gr.Image(type='pil'),
    outputs="text",
    title="Dog vs Cat Classifier",
    description="Upload an image to classify it as a Dog or Cat."
)

# Launch the app
demo.launch()