deenasun commited on
Commit
32abb1a
·
1 Parent(s): 6706596

create jupyter notebook for app, add examples and requirements.txt

Browse files
Files changed (7) hide show
  1. .gitignore +1 -0
  2. app.ipynb +0 -0
  3. app.py +30 -4
  4. cat.jpg +3 -0
  5. dino.jpg +3 -0
  6. dog.jpg +3 -0
  7. requirements.txt +1 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .gradio/
app.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
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
+ # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['learn', 'categories', 'title', 'description', 'article', 'inputs', 'outputs', 'examples', 'intf', 'is_cat',
5
+ 'classify_image']
6
+
7
+ # %% app.ipynb 1
8
+ from fastai.vision.all import *
9
  import gradio as gr
10
 
11
+ def is_cat(x): return x[0].isupper()
12
+
13
+ # %% app.ipynb 8
14
+ learn = load_learner('model.pkl')
15
+
16
+ # %% app.ipynb 10
17
+ categories = ('Dog', 'Cat')
18
+
19
+ def classify_image(img):
20
+ img = PILImage.create(img)
21
+ pred,pred_idx,probs = learn.predict(img)
22
+ return {categories[i]: float(probs[i]) for i in range(len(categories))} # convert probs (pytorch tensor) into floats
23
+
24
+ # %% app.ipynb 12
25
+ title = "Cat and Dog Classifier"
26
+ description = "A classifier built with a fine-tuned Resnet 18 model."
27
+ article="<p style='text-align: center'><a href='https://github.com/deenasun' target='_blank'>Deena Sun on Github</a></p>"
28
+ inputs= gr.Image()
29
+ outputs= gr.Label()
30
+ examples = ['dog.jpg', 'cat.jpg', 'dino.jpg']
31
 
32
+ intf = gr.Interface(fn=classify_image, inputs=inputs, outputs=outputs, examples=examples, title=title, description=description, article=article)
33
+ intf.launch(share=True)
cat.jpg ADDED

Git LFS Details

  • SHA256: 1fc4606957938a3424483b07be35e8b68214832bd6059b41838bec4e07532af5
  • Pointer size: 131 Bytes
  • Size of remote file: 569 kB
dino.jpg ADDED

Git LFS Details

  • SHA256: b15b1177808c3e306922cc26ad20f6333ed9c5f699a2333eb01f66418cc5dcb9
  • Pointer size: 132 Bytes
  • Size of remote file: 1.25 MB
dog.jpg ADDED

Git LFS Details

  • SHA256: 857803547c901c3012a65161f6d82387ea9375f5536e6012a1681db8df81dcf1
  • Pointer size: 132 Bytes
  • Size of remote file: 1.04 MB
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ fastai