Spaces:
Runtime error
Runtime error
new script
Browse files
app.py
CHANGED
|
@@ -1,23 +1,37 @@
|
|
| 1 |
-
|
| 2 |
-
from fastai.vision.all import *
|
| 3 |
-
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
with out_pl: display(img.to_thumb(128,128))
|
| 12 |
pred,pred_idx,probs = learn_inf.predict(img)
|
| 13 |
lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
btn_upload = widgets.FileUpload()
|
| 18 |
-
|
| 19 |
-
VBox([widgets.Label('Select your bear!'),
|
| 20 |
-
btn_upload, btn_run, out_pl, lbl_pred])
|
| 21 |
-
|
| 22 |
-
iface = gr.Interface(fn=on_click_classify, inputs=image, outputs=label)
|
| 23 |
-
iface.launch()
|
|
|
|
| 1 |
+
# gradio
|
|
|
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# fast.ai
|
| 5 |
+
import fastbook
|
| 6 |
+
fastbook.setup_book()
|
| 7 |
+
from fastbook import *
|
| 8 |
+
from fastai.vision.widgets import *
|
| 9 |
+
|
| 10 |
+
# pathlib
|
| 11 |
+
import pathlib
|
| 12 |
+
temp = pathlib.PosixPath
|
| 13 |
+
pathlib.PosixPath = pathlib.WindowsPath
|
| 14 |
+
path = Path()
|
| 15 |
+
# load model
|
| 16 |
+
learn_inf = load_learner(path/'model.pkl')
|
| 17 |
+
|
| 18 |
+
# Output of the uploaded image
|
| 19 |
+
# Resizes the image to 128x128
|
| 20 |
+
out_pl = widgets.Output()
|
| 21 |
+
out_pl.clear_output()
|
| 22 |
+
with out_pl: display(img.to_thumb(128,128))
|
| 23 |
+
out_pl
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|