sergheevadrian commited on
Commit
46519ce
1 Parent(s): a9a2db7
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -1,17 +1,27 @@
1
- import gradio as gr
 
 
 
2
  from fastai.vision.all import *
3
- import skimage
 
4
 
5
  learn = load_learner('model.pkl')
6
 
7
  labels = learn.dls.vocab
8
- def predict(img):
9
- img = PILImage.create(img)
10
- pred,pred_idx,probs = learn.predict(img)
11
- return {labels[i]: float(probs[i]) for i in range(len(labels))}
 
 
 
 
 
12
 
13
  title = "Melons clasifier"
14
  interpretation='default'
15
  enable_queue=True
16
 
17
- gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch()
 
 
1
+ !pip install gradio
2
+
3
+ __all__ = ['learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
4
+
5
  from fastai.vision.all import *
6
+ import gradio as gr
7
+ import timm
8
 
9
  learn = load_learner('model.pkl')
10
 
11
  labels = learn.dls.vocab
12
+
13
+ def classify_image(img):
14
+ pred,idx,probs = learn.predict(img)
15
+ return dict(zip(categories, map(float,probs)))
16
+
17
+ image = gr.Image()
18
+ label = gr.Label()
19
+
20
+ examples = ['example.jpg']
21
 
22
  title = "Melons clasifier"
23
  interpretation='default'
24
  enable_queue=True
25
 
26
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
27
+ intf.launch()