File size: 669 Bytes
098ba89
 
a2aa870
 
 
 
 
 
 
 
098ba89
 
 
4e2c3ab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import gradio as gr

def predict_image(opened_image):
    img_array = tf.keras.utils.img_to_array(opened_image)
    img_array = tf.expand_dims(img_array, 0) #Convert image to one empty batch -> Model was trained on batches
    prediction = model.predict(img_array)
    score = tf.nn.softmax(prediction[0])
    return ("Class of Flower: " + str(class_names[np.argmax(score)]), "Confidence level: " + str(100 * np.max(score)))


gr.Interface(fn=predict_image, 
             inputs=gr.Image(shape=(180, 180)),
             outputs=[gr.Label(num_top_classes=5), "text"],
              examples=['1775233884_12ff5a124f.jpg', '40410814_fba3837226_n.jpg']).launch(share=True)