File size: 1,437 Bytes
07934cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7fadc44
07934cc
 
 
 
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
from huggingface_hub import from_pretrained_keras
import numpy as np

model = from_pretrained_keras("keras-io/deit")

classes=['dandelion','daisy','tulip','sunflower','rose']
image_size = 224

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.png"], ["./examples/daisy.jpeg"], ["./examples/dandelion.jpeg"], ["./examples/rose.png"], ["./examples/sunflower.png"]]
title = "Distill ViT Flowers Classification"
description = "Upload an image or select from examples to classify flowers. [Explore model](https://huggingface.co/keras-io/deit) | [Keras Example](https://keras.io/examples/vision/deit/)"

article = "<div style='text-align: center;'><a href='https://twitter.com/SatpalPatawat' target='_blank'>Space by Satpal Singh Rathore</a><br><a href='https://twitter.com/RisingSayak' target='_blank'>Keras example by Sayak Paul</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, debug=True)