flobbit commited on
Commit
3f7b352
1 Parent(s): 1bcbe5a

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
7
+ # Cell
8
+ #learn = load_learner('ohbugger2k.pkl')
9
+ learn = load_learner('flobbit/ohbugger2k')
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(num_top_classes=5)
21
+ examples = ['carolina.jpg','abb.jpg','lady.jpg','mantis.jpg','monarch.jpg','western striped cucumber.jpg','carolina2.jpg', 'large milkweed bug.jpg', 'twice-stabbed.jpg', 'viceroy.jpg', 'lubber.jpg', 'GrashopperAulocaraElliotti958.webp']
22
+
23
+ # Cell
24
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples,
25
+ title="Oh! Bugger! 2k", description="Trained on 130133 images over 2000 species using ResNet18. Provide an image or select from one below.")
26
+ intf.launch()