File size: 1,046 Bytes
c0f15ab
 
e62cc45
 
 
 
 
c0f15ab
 
 
b1ba841
 
c0f15ab
 
7d71559
c0f15ab
7d71559
 
c0f15ab
e62cc45
c0f15ab
e62cc45
 
c0f15ab
e62cc45
72a21b5
 
 
 
 
 
c0f15ab
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
# examples = [["Examples/img1.png"], ["Examples/img2.png"],["Examples/img3.png"], ["Examples/img4.png"]]

import gradio as gr
import tensorflow as tf
import numpy as np
from tensorflow.keras.models import load_model

HEIGHT, WIDTH = 224, 224
IMG_SIZE = 224
model = load_model('Models/best_model1.h5')

def classify_image(inp):
    NUM_CLASSES = 2
    labels = ['Cat', 'Dog']
    inp = tf.image.resize(inp, [IMG_SIZE, IMG_SIZE])
    inp = inp.numpy().reshape((-1, IMG_SIZE, IMG_SIZE, 3))
    inp = tf.keras.applications.vgg16.preprocess_input(inp)
    prediction = model.predict(inp).flatten()
    return {labels[i]: float(prediction[i]) for i in range(NUM_CLASSES)}  # Fixed: return floats

image = gr.Image(height=HEIGHT, width=WIDTH, label='Input')
label = gr.Label(num_top_classes=2)

examples = [["Examples/img1.png"], ["Examples/img2.png"],["Examples/img3.png"], ["Examples/img4.png"]]

gr.Interface(
    fn=classify_image, 
    inputs=image, 
    outputs=label, 
    title='Smart Pet Classifier',
    examples=examples
).launch(debug=False)