karolina-malolepsza commited on
Commit
682fdb5
·
1 Parent(s): e77bd6a

Add gradio code

Browse files
Files changed (2) hide show
  1. app.py +27 -4
  2. requirements.txt +2 -0
app.py CHANGED
@@ -1,7 +1,30 @@
 
 
 
 
 
 
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
+ # AUTOGENERATED! DO NOT EDIT! File to edit: . (unless otherwise specified).
2
+
3
+ __all__ = ['is_cat', 'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
4
+
5
+ # Cell
6
+ from fastai.vision.all import *
7
  import gradio as gr
8
 
9
+ def is_cat(x): return x[0].isupper()
10
+
11
+ import sys
12
+ sys.modules["__main__"].is_cat = is_cat
13
+
14
+ # Cell
15
+ learn = load_learner('model-2024.pkl')
16
+
17
+ # Cell
18
+ categories = ('Dog', 'Cat')
19
+
20
+ def classify_image(img):
21
+ pred,idx,probs = learn.predict(img)
22
+ return dict(zip(categories, map(float,probs)))
23
+
24
+ # Cell
25
+ image = gr.Image(height=192, width=192)
26
+ label = gr.Label()
27
+ examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']
28
 
29
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
30
+ intf.launch(inline=False)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastai
2
+ gradio