Kryko7 commited on
Commit
f529e19
1 Parent(s): 0334873

finished app.py

Browse files
Files changed (5) hide show
  1. app.py +21 -4
  2. bird.jfif +0 -0
  3. cat.jfif +0 -0
  4. dog.jfif +0 -0
  5. koala.jfif +0 -0
app.py CHANGED
@@ -1,7 +1,24 @@
 
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.all import *
2
  import gradio as gr
3
 
 
 
4
 
5
+ learn = load_learner('model.pkl')
6
+
7
+ categories = {'Dog', 'Cat', 'Bird', 'Koala'}
8
+
9
+ def predict_image(img):
10
+ pred, pred_idx, probs = learn.predict(img)
11
+ probs_float = probs[0].item()
12
+ if probs_float > 0.5:
13
+ return dict(zip(categories, map(float, probs)))
14
+ else:
15
+ return "Not a dog, cat, bird, or koala"
16
+
17
+ image = gr.inputs.Image(shape=(192, 192))
18
+ label = gr.outputs.Label()
19
+ examples = ['dog.jpg', 'cat.jpg', 'bird.jpg', 'koala.jpg']
20
+
21
+ intf = gr.Interface(fn=predict_image, inputs=image, outputs=label, examples=examples)
22
+ intf.launch(inline=False)
23
+
24
+
bird.jfif ADDED
Binary file (6.73 kB). View file
 
cat.jfif ADDED
Binary file (6.11 kB). View file
 
dog.jfif ADDED
Binary file (5.69 kB). View file
 
koala.jfif ADDED
Binary file (9.75 kB). View file