Spaces:
Runtime error
Runtime error
Commit ·
e491b5f
1
Parent(s): d346489
update from pets repo
Browse files- app.py +14 -18
- requirements.txt +5 -5
app.py
CHANGED
|
@@ -1,29 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastai.vision.all import *
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
# im = PILIMage.create('dog.jpg')
|
| 7 |
-
# im.thumbnail((192,192))
|
| 8 |
-
# im
|
| 9 |
-
|
| 10 |
learn = load_learner('model.pkl')
|
| 11 |
-
# learn.predict(im)
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
def classify_image(img):
|
| 15 |
pred,idx,probs = learn.predict(img)
|
| 16 |
-
return dict(zip(categories, map(float,
|
| 17 |
-
|
| 18 |
-
# def greet(name):
|
| 19 |
-
# return "Hello " + name + "!!"
|
| 20 |
-
|
| 21 |
-
# iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 22 |
-
# iface.launch()
|
| 23 |
|
|
|
|
| 24 |
image = gr.inputs.Image(shape=(192, 192))
|
| 25 |
label = gr.outputs.Label()
|
| 26 |
-
examples = ['dog.jpg'
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
| 1 |
+
__all__ = ['learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
|
| 2 |
+
|
| 3 |
+
# Cell
|
| 4 |
from fastai.vision.all import *
|
| 5 |
import gradio as gr
|
| 6 |
+
import timm
|
| 7 |
|
| 8 |
+
# Cell
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
learn = load_learner('model.pkl')
|
|
|
|
| 10 |
|
| 11 |
+
# Cell
|
| 12 |
+
categories = learn.dls.vocab
|
| 13 |
+
|
| 14 |
def classify_image(img):
|
| 15 |
pred,idx,probs = learn.predict(img)
|
| 16 |
+
return dict(zip(categories, map(float,probs)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
# Cell
|
| 19 |
image = gr.inputs.Image(shape=(192, 192))
|
| 20 |
label = gr.outputs.Label()
|
| 21 |
+
examples = ['dog.jpg']
|
| 22 |
|
| 23 |
+
# Cell
|
| 24 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 25 |
+
intf.launch()
|
requirements.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
fastai
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
|
|
|
| 1 |
+
fastai==2.7.12
|
| 2 |
+
gradio==3.34.0
|
| 3 |
+
timm==0.9.2
|
| 4 |
+
torch==2.0.1
|
| 5 |
+
torchvision==0.15.2
|