Spaces:
Runtime error
Runtime error
new script 2
Browse files
app.py
CHANGED
|
@@ -1,37 +1,27 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
# Label Function that will disply our prediction data to the user
|
| 26 |
-
lbl_pred = widgets.Label()
|
| 27 |
-
|
| 28 |
-
# Logic function that will run the image classifier on the classify button click
|
| 29 |
-
def on_click_classify(input_img):
|
| 30 |
-
img = PILImage.create(input_img)
|
| 31 |
-
with out_pl: display(img.to_thumb(128,128))
|
| 32 |
-
pred,pred_idx,probs = learn_inf.predict(img)
|
| 33 |
-
lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'
|
| 34 |
-
return lbl_pred.value
|
| 35 |
-
|
| 36 |
-
demo = gr.Interface(on_click_classify, gr.Image(shape=(512, 512)), "text")
|
| 37 |
-
demo.launch()
|
|
|
|
| 1 |
+
__all__ = ['learn', 'categories', 'examples', 'interface', 'classify_image']
|
| 2 |
+
|
| 3 |
+
# %% 02_app.ipynb 1
|
| 4 |
+
from fastai.vision.all import *
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
+
print(gr.__version__)
|
| 8 |
+
|
| 9 |
+
# %% 02_app.ipynb 2
|
| 10 |
+
learn = load_learner('model.pkl')
|
| 11 |
+
|
| 12 |
+
# %% 02_app.ipynb 4
|
| 13 |
+
categories = ('black', 'grizzly', 'teddy')
|
| 14 |
+
|
| 15 |
+
def classify_image(img):
|
| 16 |
+
pred, pred_idx, probs = learn.predict(img)
|
| 17 |
+
return dict(zip(categories, map(float, probs)))
|
| 18 |
+
|
| 19 |
+
# %% 02_app.ipynb 5
|
| 20 |
+
# create a gradio interface
|
| 21 |
+
|
| 22 |
+
# image = gr.inputs.Image(shape=(192,192))
|
| 23 |
+
# label = gr.outputs.Label()
|
| 24 |
+
examples = ['examples/black.jpg', 'examples/grizzly.jpg', 'examples/teddy.jpg']
|
| 25 |
+
|
| 26 |
+
interface = gr.Interface(fn=classify_image, inputs="image", outputs="label", examples=examples)
|
| 27 |
+
interface.launch(inline=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|