Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../dino.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'demo', 'classify']
|
5 |
+
|
6 |
+
# %% ../dino.ipynb 1
|
7 |
+
from fastai.vision.all import *
|
8 |
+
import gradio as gr
|
9 |
+
|
10 |
+
|
11 |
+
# %% ../dino.ipynb 3
|
12 |
+
learn = load_learner('export.pkl')
|
13 |
+
|
14 |
+
|
15 |
+
# %% ../dino.ipynb 5
|
16 |
+
categories = ('ankylosaurus', 'brontosaurus', 'pterodactyl', 'trex', 'triceraptops')
|
17 |
+
|
18 |
+
def classify(img):
|
19 |
+
pred, idx, probs = learn.predict(img)
|
20 |
+
return dict(zip(categories, map(float,probs)))
|
21 |
+
|
22 |
+
# %% ../dino.ipynb 7
|
23 |
+
image = gr.Image(width=512, height=512)
|
24 |
+
label = gr.Label(num_top_classes=3)
|
25 |
+
examples = ['ankylosaurus.jpg', 'images.jpeg']
|
26 |
+
|
27 |
+
demo = gr.Interface(fn=classify, inputs=image, outputs=label, examples=examples)
|
28 |
+
demo.launch(inline=False)
|