Spaces:
Runtime error
Runtime error
Create app.py
Browse files- examples/app.py +29 -0
examples/app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
from huggingface_hub import from_pretrained_keras
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
model = from_pretrained_keras("keras-io/mobile-vit-xxs")
|
7 |
+
|
8 |
+
classes=['dandelion','daisy','tulip','sunflower','rose']
|
9 |
+
image_size = 256
|
10 |
+
|
11 |
+
def classify_images(image):
|
12 |
+
image = tf.convert_to_tensor(image)
|
13 |
+
image = tf.image.resize(image, (image_size, image_size))
|
14 |
+
image = tf.expand_dims(image,axis=0)
|
15 |
+
prediction = model.predict(image)
|
16 |
+
prediction = tf.squeeze(tf.round(prediction))
|
17 |
+
text_output = str(f'{classes[(np.argmax(prediction))]}!')
|
18 |
+
return text_output
|
19 |
+
|
20 |
+
i = gr.inputs.Image()
|
21 |
+
o = gr.outputs.Textbox()
|
22 |
+
|
23 |
+
examples = [["./examples/tulip.png"], ["./examples/daisy.jpeg"], ["./examples/dandelion.jpeg"], ["./examples/rose.png"], ["./examples/sunflower.png"]]
|
24 |
+
title = "Flowers Classification MobileViT"
|
25 |
+
description = "Upload an image or select from examples to classify flowers"
|
26 |
+
|
27 |
+
article = "<div style='text-align: center;'><a href='https://twitter.com/SatpalPatawat' target='_blank'>Space by Satpal Singh Rathore</a><br><a href='https://keras.io/examples/vision/mobilevit/' target='_blank'>Keras example by Sayak Paul</a></div>"
|
28 |
+
gr.Interface(classify_images, i, o, allow_flagging=False, analytics_enabled=False,
|
29 |
+
title=title, examples=examples, description=description, article=article).launch(enable_queue=True)
|