Spaces:
Runtime error
Runtime error
File size: 1,533 Bytes
f41df8e 525d918 f41df8e 9379114 70068e3 9379114 8173d3e d6181a9 525d918 f41df8e 525d918 ee200d3 8173d3e 56af423 5026fa9 8c84b07 525d918 3d06034 525d918 |
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 30 31 32 33 34 35 36 37 38 39 40 41 |
import gradio as gr
import tensorflow as tf
from huggingface_hub import from_pretrained_keras
import numpy as np
from huggingface_hub import hf_hub_download
from keras.layers import TFSMLayer
import numpy as np
# Download the model
model_path = hf_hub_download("keras-io/mobile-vit-xxs")
# Load the model using TFSMLayer
model = TFSMLayer(model_path, call_endpoint='serving_default')
''' model = from_pretrained_keras("keras-io/mobile-vit-xxs")
'''
classes=['dandelion','daisy','tulips','sunflower','rose']
image_size = 256
def classify_images(image):
image = tf.convert_to_tensor(image)
image = tf.image.resize(image, (image_size, image_size))
image = tf.expand_dims(image,axis=0)
prediction = model.predict(image)
prediction = tf.squeeze(tf.round(prediction))
text_output = str(f'{classes[(np.argmax(prediction))]}!')
return text_output
i = gr.inputs.Image()
o = gr.outputs.Textbox()
examples = [["./examples/tulip.jpg"], ["./examples/daisy.jpg"], ["./examples/dandelion.jpg"], ["./examples/rose.jpg"], ["./examples/sunflower.jpg"]]
title = "Flower Recognition Using Transfer Learning"
description = "Upload an image or Select from the examples below to classify flowers: "
article = "<div style='text-align: center;'><a href='https://www.linkedin.com/in/suryakiran-mg/' target='_blank'> Space by Suryakiran </a></div>"
gr.Interface(classify_images, i, o, allow_flagging=False, analytics_enabled=False,
title=title, examples=examples, description=description, article=article).launch(enable_queue=True)
|