Spaces:
Sleeping
Sleeping
| 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() |