wip
Browse files
app.py
CHANGED
|
@@ -1,7 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb.
|
| 2 |
+
|
| 3 |
+
# %% auto 0
|
| 4 |
+
__all__ = ['learn', 'categories', 'image', 'label', 'intf', 'classify_image']
|
| 5 |
+
|
| 6 |
+
# %% ../app.ipynb 2
|
| 7 |
+
from fastai.vision.all import *
|
| 8 |
+
from PIL import Image
|
| 9 |
+
import matplotlib.pyplot as plt
|
| 10 |
import gradio as gr
|
| 11 |
+
from nbdev.export import nb_export
|
| 12 |
+
|
| 13 |
+
# %% ../app.ipynb 5
|
| 14 |
+
learn = load_learner('models/02.pkl')
|
| 15 |
+
|
| 16 |
+
# %% ../app.ipynb 7
|
| 17 |
+
categories = ('tfs', 'xk', 'dbt', 'pbs', 'rwo', 'hth', 'itb')
|
| 18 |
+
|
| 19 |
+
def classify_image(img):
|
| 20 |
+
pred, idx, probs = learn.predict(img)
|
| 21 |
+
|
| 22 |
+
return dict(zip(sorted(categories), map(float, probs)))
|
| 23 |
|
| 24 |
+
# %% ../app.ipynb 9
|
| 25 |
+
image = gr.Image(height=192, width=192)
|
| 26 |
+
label = gr.Label()
|
| 27 |
|
| 28 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=example_image_paths)
|
| 29 |
+
intf.launch(inline=False)
|