Spaces:
Runtime error
Runtime error
tomengland
commited on
Commit
•
f52777c
1
Parent(s):
f0f915b
remove share
Browse files
app.py
CHANGED
@@ -1,31 +1,34 @@
|
|
1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: chapt2.ipynb.
|
2 |
|
3 |
# %% auto 0
|
4 |
-
__all__ = [
|
5 |
|
6 |
-
# %% chapt2.ipynb 14
|
7 |
-
from fastai.vision.all import *
|
8 |
import gradio as gr
|
9 |
import skimage
|
10 |
|
|
|
|
|
|
|
11 |
# %% chapt2.ipynb 15
|
12 |
-
learn = load_learner(
|
13 |
labels = learn.dls.vocab
|
14 |
|
|
|
15 |
def predict(img):
|
16 |
img = PILImage.create(img)
|
17 |
-
pred,pred_idx,probs = learn.predict(img)
|
18 |
print(pred)
|
19 |
print(pred_idx)
|
20 |
print(probs)
|
21 |
-
|
22 |
if probs[pred_idx] > 0.8:
|
23 |
message = f"I am {round((float(probs[pred_idx])*100),4)}% confident that the picture you uploaded is me. I am a {pred} bear."
|
24 |
else:
|
25 |
message = f"Hmm.. I know what a bear looks like, considering... but do you? Try uploading an image of a bear, thank you."
|
26 |
-
#message = "hi"
|
27 |
return message
|
28 |
|
|
|
29 |
# %% chapt2.ipynb 16
|
30 |
examples = ["a_bear.jpg"]
|
31 |
|
@@ -35,13 +38,14 @@ with demo:
|
|
35 |
gr.Markdown("Upload an image, preferably an image of a bear...")
|
36 |
with gr.Row():
|
37 |
image_input = gr.Image(type="pil", shape=(512, 512), interactive=True)
|
38 |
-
text_output = gr.Textbox(
|
|
|
|
|
39 |
submit_button = gr.Button("Submit")
|
40 |
clear_button = gr.Button("Clear")
|
41 |
-
|
42 |
submit_button.click(predict, inputs=image_input, outputs=text_output)
|
43 |
clear_button.click(lambda: None, None, image_input)
|
44 |
-
clear_button.click(lambda:None, None, text_output)
|
45 |
-
|
46 |
-
demo.launch(share=True)
|
47 |
|
|
|
|
1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: chapt2.ipynb.
|
2 |
|
3 |
# %% auto 0
|
4 |
+
__all__ = ["learn", "labels", "examples", "demo", "predict"]
|
5 |
|
|
|
|
|
6 |
import gradio as gr
|
7 |
import skimage
|
8 |
|
9 |
+
# %% chapt2.ipynb 14
|
10 |
+
from fastai.vision.all import *
|
11 |
+
|
12 |
# %% chapt2.ipynb 15
|
13 |
+
learn = load_learner("model.pkl")
|
14 |
labels = learn.dls.vocab
|
15 |
|
16 |
+
|
17 |
def predict(img):
|
18 |
img = PILImage.create(img)
|
19 |
+
pred, pred_idx, probs = learn.predict(img)
|
20 |
print(pred)
|
21 |
print(pred_idx)
|
22 |
print(probs)
|
23 |
+
|
24 |
if probs[pred_idx] > 0.8:
|
25 |
message = f"I am {round((float(probs[pred_idx])*100),4)}% confident that the picture you uploaded is me. I am a {pred} bear."
|
26 |
else:
|
27 |
message = f"Hmm.. I know what a bear looks like, considering... but do you? Try uploading an image of a bear, thank you."
|
28 |
+
# message = "hi"
|
29 |
return message
|
30 |
|
31 |
+
|
32 |
# %% chapt2.ipynb 16
|
33 |
examples = ["a_bear.jpg"]
|
34 |
|
|
|
38 |
gr.Markdown("Upload an image, preferably an image of a bear...")
|
39 |
with gr.Row():
|
40 |
image_input = gr.Image(type="pil", shape=(512, 512), interactive=True)
|
41 |
+
text_output = gr.Textbox(
|
42 |
+
label="Response from Bear", placeholder="I'm waiting for an image"
|
43 |
+
)
|
44 |
submit_button = gr.Button("Submit")
|
45 |
clear_button = gr.Button("Clear")
|
46 |
+
|
47 |
submit_button.click(predict, inputs=image_input, outputs=text_output)
|
48 |
clear_button.click(lambda: None, None, image_input)
|
49 |
+
clear_button.click(lambda: None, None, text_output)
|
|
|
|
|
50 |
|
51 |
+
demo.launch()
|