File size: 753 Bytes
40d1897
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image

new_model = tf.keras.models.load_model("./MobileNet-V2-Cats-Dogs.keras")

def image_classifier(inp):
    
      # Convert PIL image to TensorFlow tensor
    img = tf.convert_to_tensor(inp, dtype=tf.float32)
    
    # Resize the image
    img = tf.image.resize(img, (160,160))
    
    

    out = new_model.predict(tf.expand_dims(img,0)).flatten()
    predictions = tf.where(out < 0.5, 0, 1)
    predictions = tf.squeeze(predictions)

    print("The out : ", out[0])
    if out[0] > 0.5 :
        return {'dog': 1}
    else:
        return {'cat': 1}
        
        
demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label")
demo.launch(debug=True)