Spaces:
Sleeping
Sleeping
Keith Preston commited on
Commit ·
8ab57f7
1
Parent(s): 26dcf12
Add model
Browse files- app.py +14 -4
- testapp.py +7 -0
app.py
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
return "Hello " + name + "!!"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastai.vision.all import *
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
learn = load_learner('model.pkl')
|
|
|
|
| 5 |
|
| 6 |
+
def classify_image(img):
|
| 7 |
+
pred, idx, probs = learn.predict(img)
|
| 8 |
+
d = dict(zip(learn.dls.vocab, map(float,probs)))
|
| 9 |
+
ds = sorted(d.items(), key=lambda item: item[1], reverse=True)
|
| 10 |
+
return dict(ds[0:5])
|
| 11 |
+
|
| 12 |
+
image = gr.inputs.Image(shape=(244, 244))
|
| 13 |
+
label = gr.outputs.Label()
|
| 14 |
+
examples = ['dog1.jpg', 'dog2.jpg', 'dog3.jpg']
|
| 15 |
+
|
| 16 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 17 |
+
intf.launch(inline=False)
|
testapp.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|