File size: 1,107 Bytes
098ba89
 
9496ed4
688e1ec
9496ed4
 
 
ea9feac
 
7079f36
 
142bb9b
7079f36
c5e39dc
1263220
ea9feac
a2aa870
 
 
 
 
 
 
 
098ba89
 
 
4e2c3ab
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
import gradio as gr

import tensorflow as tf
import numpy as np

import gradio as gr

from transformers import AutoTokenizer, pipeline,  AutoModelForTokenClassification

#tokenizer = AutoTokenizer.from_pretrained("Battu007/1_Image_Classification")
#model = AutoModelForTokenClassification.from_pretrained("Battu007/1_Image_Classification")

class_names = ['daisy', 'dandelion', 'roses', 'sunflowers', 'tulips']

model = tf.keras.models.load_model(r'/Model')

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)