Spaces:
Sleeping
Sleeping
create jupyter notebook for app, add examples and requirements.txt
Browse files- .gitignore +1 -0
- app.ipynb +0 -0
- app.py +30 -4
- cat.jpg +3 -0
- dino.jpg +3 -0
- dog.jpg +3 -0
- 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
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 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
|
dino.jpg
ADDED
|
Git LFS Details
|
dog.jpg
ADDED
|
Git LFS Details
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
fastai
|