Spaces:
Running
Running
Merge branch 'main' of https://huggingface.co/spaces/Chipmunk91/MyFastAI into main
Browse files- app.py +30 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../Untitled-1.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['model_path', 'learn', 'categories', 'is_cat', 'classify_image']
|
5 |
+
|
6 |
+
# %% ../../Untitled-1.ipynb 0
|
7 |
+
import gradio as gr
|
8 |
+
from fastai.vision.all import *
|
9 |
+
def is_cat(x): return x[0].isupper()
|
10 |
+
|
11 |
+
# %% ../../Untitled-1.ipynb 2
|
12 |
+
model_path = Path('model.pkl')
|
13 |
+
learn = load_learner(model_path)
|
14 |
+
|
15 |
+
# %% ../../Untitled-1.ipynb 4
|
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 |
+
|
23 |
+
# %% ../../Untitled-1.ipynb 6
|
24 |
+
gr.Interface(fn = classify_image,
|
25 |
+
inputs="image",
|
26 |
+
outputs="label",
|
27 |
+
title = "Dog or Cat",
|
28 |
+
description="Sample workflow",
|
29 |
+
examples = ['dog.jpg']
|
30 |
+
).launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
fastai
|