File size: 635 Bytes
f7dfb0f
9c52842
 
f7dfb0f
9c52842
 
 
f7dfb0f
9c52842
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import tensorflow as tf
import numpy as input

num_classes = 200
IMG_HEIGHT = 256
IMG_WIDTH = 256

def normalize_image(img):
    img = tf.cast(img, tf.float32)/255.
    img = tf.image.resize(img, (IMG_HEIGHT, IMG_WIDTH), method='bilinear')
    return img


def predict_fn(img):
    img = img.convert('RGB')
    img_data = normalize_image(img)
    x = np.array(img_data)
    x = np.expand_dims(x, axis=0)
    temp = model.predict(x)
    return temp


model = tf.keras.models.load_model("model.h5")

interface = gr.Interface(predict_fn, gr.inputs.Image(type='PIL'), outputs='label', examples=path,)
interface.launch()