Salman Naqvi commited on
Commit
c2763a7
1 Parent(s): 2002edf

Created interface and app file.

Browse files
Files changed (2) hide show
  1. app.ipynb +0 -0
  2. app.py +42 -0
app.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['learner', 'cats', 'img', 'lbl', 'examples', 'title', 'description', 'article', 'interface', 'classify_img']
5
+
6
+ # %% app.ipynb 3
7
+ from fastai.vision.all import *
8
+ import gradio as gr
9
+
10
+ # %% app.ipynb 6
11
+ learner = load_learner('model/export.pkl')
12
+
13
+ # %% app.ipynb 9
14
+ cats = ('Grizzly Bear', 'Black Bear', 'Teddy Bear',)
15
+
16
+ def classify_img(img):
17
+ preds, idx, probs = learner.predict(img)
18
+ return dict(zip(cats, map(float, probs)))
19
+
20
+ # %% app.ipynb 12
21
+ img = gr.Image()
22
+ lbl = gr.Label()
23
+ examples = [str(img_path) for img_path in Path('example_images/').rglob('*.jpg')]
24
+
25
+ title = 'Bear Classifier'
26
+ description = 'My first AI model that can tell you whether an image contains a grizzly bear, a black bear, or a teddy bear. This model was trained on the ' \
27
+ 'ResNet18 architecture and used the fastai library.'
28
+ article = "<p style='text-align: center; font-size: 36px'><a href='https://forbo7.github.io/forblog/posts/2_bear_classifier_model.html' " \
29
+ "targets='_blank'><Blog Post</a></p>"
30
+
31
+ # %% app.ipynb 15
32
+ interface = gr.Interface(
33
+ fn=classify_img,
34
+ inputs='image',
35
+ outputs='label',
36
+ examples=examples,
37
+ title=title,
38
+ description=description,
39
+ article=article
40
+ )
41
+
42
+ interface.launch(inline=False, enable_queue=True)