Choucri FAHED commited on
Commit
ca49f8f
1 Parent(s): d238edf
Files changed (8) hide show
  1. .gitattributes +1 -0
  2. .gitignore +2 -0
  3. README.md +20 -0
  4. app.py +25 -4
  5. cat.jpg +0 -0
  6. dog.jpg +0 -0
  7. dogsvscats.ipynb +0 -0
  8. model.pkl +3 -0
.gitattributes CHANGED
@@ -6,6 +6,7 @@
6
  *.gz filter=lfs diff=lfs merge=lfs -text
7
  *.h5 filter=lfs diff=lfs merge=lfs -text
8
  *.joblib filter=lfs diff=lfs merge=lfs -text
 
9
  *.lfs.* filter=lfs diff=lfs merge=lfs -text
10
  *.model filter=lfs diff=lfs merge=lfs -text
11
  *.msgpack filter=lfs diff=lfs merge=lfs -text
6
  *.gz filter=lfs diff=lfs merge=lfs -text
7
  *.h5 filter=lfs diff=lfs merge=lfs -text
8
  *.joblib filter=lfs diff=lfs merge=lfs -text
9
+ *.jpg filter=lfs diff=lfs merge=lfs -text
10
  *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
  *.model filter=lfs diff=lfs merge=lfs -text
12
  *.msgpack filter=lfs diff=lfs merge=lfs -text
.gitignore CHANGED
@@ -1 +1,3 @@
1
  .idea
 
 
1
  .idea
2
+ .ipynb_checkpoints
3
+ .DS_Store
README.md CHANGED
@@ -11,3 +11,23 @@ license: apache-2.0
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
14
+
15
+ # Train and download the model
16
+
17
+ The notebook that generated the model pickle file `model.pkl` is
18
+ [here](https://www.kaggle.com/code/cfahed/saving-a-basic-fastai-model/edit).
19
+
20
+ # Setup a fully working Fastai environment on Mac
21
+
22
+ Install [Mamba](https://mamba.readthedocs.io/en/latest/installation.html) which is a faster Conda.
23
+ And both are preferred to _pip_ because _pip_ doesn't install GPU dependencies.
24
+
25
+ Then, run the following commands:
26
+
27
+ mamba init
28
+ mamba install -c fastchan fastai
29
+ mamba install -c fastai nbdev
30
+ mamba install jupyter
31
+ pip install gradio
32
+
33
+ Finally, launch Jupyter with `jupyter notebook`.
app.py CHANGED
@@ -1,7 +1,28 @@
 
 
 
 
 
 
 
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: ../dogsvscats.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'is_cat', 'classify_image']
5
+
6
+ # %% ../dogsvscats.ipynb 2
7
+ from fastai.vision.all import *
8
  import gradio as gr
9
 
10
+ def is_cat(x): return x[0].isupper()
11
+
12
+ # %% ../dogsvscats.ipynb 4
13
+ learn = load_learner('model.pkl')
14
+
15
+ # %% ../dogsvscats.ipynb 13
16
+ categories = ('Dog', 'Cat')
17
+
18
+ def classify_image(img):
19
+ pred,idx,probs = learn.predict(img)
20
+ return dict(zip(categories, map(float, probs)))
21
+
22
+ # %% ../dogsvscats.ipynb 15
23
+ image = gr.inputs.Image(shape=(192, 192))
24
+ label = gr.outputs.Label()
25
+ examples = ['dog.jpg', 'cat.jpg']
26
 
27
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
28
+ intf.launch(inline=False)
cat.jpg ADDED
dog.jpg ADDED
dogsvscats.ipynb ADDED
The diff for this file is too large to render. See raw diff
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0220c047d5d29a0a69fc681fd7ed4ad025f3eb8e95dd515a5628529981237c83
3
+ size 47061355