jsolow's picture
Float the preds
fdd6f6b
import gradio as gr
from huggingface_hub import from_pretrained_keras
import tensorflow as tf
import numpy as np
from labels import CLASS_LABELS
model = from_pretrained_keras("jsolow/grubguesser")
def _preprocess(image_path: str):
image = tf.keras.utils.load_img(image_path, target_size=(224, 224))
input_arr = tf.keras.utils.img_to_array(image)
input_arr = np.array([input_arr]) # Convert single image to a batch.
return input_arr / 255.
def predict(image):
image_array = _preprocess(image)
predictions = model.predict(image_array)[0] # single pred batch
return {k: float(v) for k, v in zip(CLASS_LABELS, predictions)}
gr.Interface(
predict,
inputs=gr.inputs.Image(label="Upload food image", type="filepath"),
outputs=gr.outputs.Label(num_top_classes=10),
title="Grubguesser - What is this food?",
).launch()