PAkerstrand navneetkumar commited on
Commit
e462b4a
1 Parent(s): 960a4a8

Update app.py (#4)

Browse files

- Update app.py (800d3b49977d51852b29f8e1f72121071b70ba2a)


Co-authored-by: p <navneetkumar@users.noreply.huggingface.co>

Files changed (1) hide show
  1. app.py +29 -4
app.py CHANGED
@@ -1,7 +1,32 @@
 
 
 
 
 
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
+
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
+ # Some magic according to https://forums.fast.ai/t/lesson-2-official-topic/96033/376?page=17
10
+ def is_happy(x):
11
+ return x[0].isupper() # Used by model
12
+
13
+ import sys
14
+ sys.modules["__main__"].is_happy = is_happy
15
+
16
+ # Upload your model
17
+ learn = load_learner('model.pkl')
18
+
19
+ categories = learn.dls.vocab
20
+
21
+ def classify_image(img):
22
+ pred,idx,probs = learn.predict(img)
23
+ return dict(zip(categories, map(float,probs)))
24
+
25
+ image = gr.Image()
26
+ label = gr.Label()
27
 
28
+ # Upload your own images and link them
29
+ examples = ['basset.jpg']
30
 
31
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
32
+ intf.launch()