import gradio as gr from huggingface_hub import from_pretrained_keras from tensorflow.keras.preprocessing.image import array_to_img, img_to_array from .labels import CLASS_LABELS model = from_pretrained_keras("jsolow/grubguesser") def _preprocess(imgage_input): img = array_to_img(imgage_input, scale=False) img = img.resize((224, 224)) img = img_to_array(img) return img / 255.0 def predict(image): image_array = _preprocess(image) predictions = model.predict(image_array) return {k: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()