Spaces:
Runtime error
Runtime error
Commit
·
2046ca8
1
Parent(s):
2b74037
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from huggingface_hub import from_pretrained_keras
|
| 5 |
+
import cv2
|
| 6 |
+
|
| 7 |
+
img_size = 28
|
| 8 |
+
model = from_pretrained_keras("keras-io/keras-reptile")
|
| 9 |
+
|
| 10 |
+
def read_image(image):
|
| 11 |
+
image = tf.convert_to_tensor(image)
|
| 12 |
+
image = cv2.resize()
|
| 13 |
+
image = image / 127.5 - 1
|
| 14 |
+
return image
|
| 15 |
+
|
| 16 |
+
def infer(model, image_tensor):
|
| 17 |
+
predictions = model.predict(np.expand_dims((image_tensor), axis=0))
|
| 18 |
+
predictions = np.squeeze(predictions)
|
| 19 |
+
predictions = np.argmax(predictions, axis=0)
|
| 20 |
+
return predictions
|
| 21 |
+
def display_result(input_image):
|
| 22 |
+
image_tensor = read_image(input_image)
|
| 23 |
+
prediction_label = infer(model=model, image_tensor=image_tensor)
|
| 24 |
+
return prediction_label
|
| 25 |
+
|
| 26 |
+
input = gr.inputs.Image()
|
| 27 |
+
examples = [["/content/drive/MyDrive/boot.jpg"], ["/content/drive/MyDrive/sneaker.jpg"]]
|
| 28 |
+
title = "Few shot learning"
|
| 29 |
+
description = "Upload an image or select from examples to classify fashion items."
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
gr.Interface(display_result, input, outputs="text", examples=examples, allow_flagging=False, analytics_enabled=False,
|
| 33 |
+
title=title, description=description).launch(enable_queue=True)
|