IZDixit commited on
Commit
55c76b2
·
1 Parent(s): a8bedcb

Second commit, previous did not respond

Browse files
Files changed (3) hide show
  1. app.py +30 -4
  2. doggy.jpg +0 -0
  3. gato.jpg +0 -0
app.py CHANGED
@@ -1,7 +1,33 @@
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
1
+ # import gradio as gr
2
+
3
+ # def greet(name):
4
+ # return "Hello " + name + "!!"
5
+
6
+ # demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
+ # demo.launch()
8
+ from fastai.vision.all import *
9
  import gradio as gr
10
 
11
+ # We need to re-define the functions used in the models as the learner in the .pkl file uses these external functions and sousnt have the source code to the function
12
+ def is_cat(x): return x[0].isupper()
13
+
14
+ # we are loading the learner in the .pkl file to now do our project
15
+ learn = load_learner('/Users/izd/Library/Mobile Documents/com~apple~CloudDocs/Documents/fastai_course/minimal/model.pkl')
16
+
17
+ #N/b gradio does not handle pytorch tensors hence the need to convert to float
18
+ categories = ('Dog,','Cat')
19
+
20
+ def classify_image(img):
21
+ pred,id,probs = learn.predict(img)
22
+ # Read more on dict(zip())
23
+ return dict(zip(categories, map(float,probs)))
24
+
25
+ dog = '/Users/izd/Library/Mobile Documents/com~apple~CloudDocs/Documents/fastai_course/minimal/doggy.jpg'
26
+ cat = '/Users/izd/Library/Mobile Documents/com~apple~CloudDocs/Documents/fastai_course/minimal/gato.jpg'
27
+
28
+ image = gr.Image(height=192, width=192)
29
+ label = gr.Label()
30
+ examples = [dog,cat]
31
 
32
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
33
+ intf.launch(inline=False)
doggy.jpg ADDED
gato.jpg ADDED