joseluistorres commited on
Commit
e491b5f
·
1 Parent(s): d346489

update from pets repo

Browse files
Files changed (2) hide show
  1. app.py +14 -18
  2. requirements.txt +5 -5
app.py CHANGED
@@ -1,29 +1,25 @@
 
 
 
1
  from fastai.vision.all import *
2
  import gradio as gr
 
3
 
4
- def is_cat(x): return x[0].isupper()
5
-
6
- # im = PILIMage.create('dog.jpg')
7
- # im.thumbnail((192,192))
8
- # im
9
-
10
  learn = load_learner('model.pkl')
11
- # learn.predict(im)
12
 
13
- categories = ('Dog', 'Cat')
 
 
14
  def classify_image(img):
15
  pred,idx,probs = learn.predict(img)
16
- return dict(zip(categories, map(float, probs)))
17
-
18
- # def greet(name):
19
- # return "Hello " + name + "!!"
20
-
21
- # iface = gr.Interface(fn=greet, inputs="text", outputs="text")
22
- # iface.launch()
23
 
 
24
  image = gr.inputs.Image(shape=(192, 192))
25
  label = gr.outputs.Label()
26
- examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']
27
 
28
- iface = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
29
- iface.launch(inline=False)
 
 
1
+ __all__ = ['learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
2
+
3
+ # Cell
4
  from fastai.vision.all import *
5
  import gradio as gr
6
+ import timm
7
 
8
+ # Cell
 
 
 
 
 
9
  learn = load_learner('model.pkl')
 
10
 
11
+ # Cell
12
+ categories = learn.dls.vocab
13
+
14
  def classify_image(img):
15
  pred,idx,probs = learn.predict(img)
16
+ return dict(zip(categories, map(float,probs)))
 
 
 
 
 
 
17
 
18
+ # Cell
19
  image = gr.inputs.Image(shape=(192, 192))
20
  label = gr.outputs.Label()
21
+ examples = ['dog.jpg']
22
 
23
+ # Cell
24
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
25
+ intf.launch()
requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
- fastai
2
- torch==1.12.1
3
- gradio
4
- numpy
5
- pandas <2.0.0
 
1
+ fastai==2.7.12
2
+ gradio==3.34.0
3
+ timm==0.9.2
4
+ torch==2.0.1
5
+ torchvision==0.15.2