Spaces:
Sleeping
Sleeping
File size: 703 Bytes
ee657f3 566023b ee657f3 566023b ee657f3 4c76fe7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import gradio as gr
from fastai.vision.all import *
import torch
learn = load_learner('food_classif_model_v1.pkl')
def predict_image(img):
pred,los,prob = learn.predict(img)
top_values, top_indx = torch.topk(prob, 3) # show 3 max values
return pred
# text_out = ''
# if (top_values < 0.4).all():
# text_out = 'I do not know what is that'
# else:
# text_out = f'{food_indx[top_indx[0]]} = {top_values[0]}\n{food_indx[top_indx[1]]} = {top_values[1]}\n{food_indx[top_indx[2]]} = {top_values[2]}'
# return text_out
# UI huggface
intrfce = gr.Interface(fn=predict_image,
inputs=gr.Image(type="pil"),
outputs=gr.Label()).launch() |