Spaces:
Runtime error
Runtime error
import numpy as np | |
import tensorflow as tf | |
import gradio as gr | |
from huggingface_hub import from_pretrained_keras | |
import cv2 | |
img_size = 28 | |
model = from_pretrained_keras("keras-io/keras-reptile") | |
def read_image(image): | |
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
image = tf.image.resize(images=image, size=[img_size, img_size]) | |
return image | |
def infer(model, image): | |
predictions = model.predict(image) | |
def display_result(input_image): | |
image_tensor = read_image(input_image) | |
prediction_label = infer(model=model, image=image) | |
return prediction_label | |
input = gr.inputs.Image() | |
examples = [["./example0.JPG"], ["./example1.JPG"]] | |
title = "Few shot learning" | |
description = "Upload an image or select from examples to classify fashion items." | |
gr.Interface(display_result, input, outputs="text", examples=examples, allow_flagging=False, analytics_enabled=False, | |
title=title, description=description).launch(enable_queue=True) | |
gr.launch() |