File size: 864 Bytes
a00b992
56c8e47
ea97a17
0c40737
a00b992
19d9547
56c8e47
 
 
 
 
ea97a17
 
 
 
0c40737
56c8e47
 
 
 
0c40737
fdd6f6b
56c8e47
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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()