File size: 801 Bytes
098ba89
 
a2aa870
 
 
 
 
 
 
 
098ba89
 
 
 
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=[r"D:\Website\Hyde\MachineLearning_Tensorflow\flower_photos\roses\568715474_bdb64ccc32.jpg", r'D:\Website\Hyde\MachineLearning_Tensorflow\flower_photos\sunflowers\44079668_34dfee3da1_n.jpg']).launch(share=True)