GameHasNoGame commited on
Commit
ee657f3
·
verified ·
1 Parent(s): 5c13f09

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from fastai.vision.all import *
3
+ import torch
4
+
5
+ learn = load_learner('food_classif_model_v1.pkl')
6
+
7
+ def predict_image(img):
8
+ pred,los,prob = learn.predict(img)
9
+ top_values, top_indx = torch.topk(prob, 3) # show 3 max values
10
+
11
+ if (top_values < 0.4).all():
12
+ return 'I do not know what is that'
13
+ else:
14
+ return 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]}'
15
+
16
+
17
+ # UI huggface
18
+
19
+ intrfce = gr.Interface(fn=predict_image,
20
+ inputs=gr.Image(type="pil"),
21
+ outputs=gr.Label(num_top_classes=3)).launch()