Battu007's picture
Update app.py
1263220
Raw History Blame Contribute Delete
1.11 kB
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)