Sadia commited on
Commit
ce6b8c9
·
1 Parent(s): 3fbe06e

prediction model

Browse files
Files changed (5) hide show
  1. app.py +18 -7
  2. cat.jpeg +0 -0
  3. cat2.jpeg +0 -0
  4. dog.jpeg +0 -0
  5. dog2.jpeg +0 -0
app.py CHANGED
@@ -1,11 +1,22 @@
1
- import gradio as gr
 
 
 
 
 
 
2
 
3
  learn = load_learner('model.pkl')
 
4
 
5
- labels = learn.dls.vocab
6
- def predict(img):
7
- img = PILImage.create(img)
8
- pred,pred_idx,probs = learn.predict(img)
9
- return {labels[i]: float(probs[i]) for i in range(len(labels))}
10
 
11
- gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3)).launch(share=True)
 
 
 
 
 
1
+ from fastai.vision.all import *
2
+
3
+ def is_cat(x): return x[0].isupper()
4
+
5
+ im = PILImage.create('dog.jpeg')
6
+ im.thumbnail((192,192))
7
+ im
8
 
9
  learn = load_learner('model.pkl')
10
+ categories = ('Dog', 'Cat')
11
 
12
+ def classify_image(img):
13
+ pred,idx,probs = learn.predict(img)
14
+ return dict(zip(categories, map(float,probs)))
15
+
16
+ import gradio as gr
17
 
18
+ image = gr.inputs.Image(shape=(192,192))
19
+ label = gr.outputs.Label()
20
+ examples = ['dog.jpg', 'cat.jpg']
21
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
22
+ intf.launch(inline=False, share=True)
cat.jpeg ADDED
cat2.jpeg ADDED
dog.jpeg ADDED
dog2.jpeg ADDED