Spaces:
Runtime error
Runtime error
yexuefeng commited on
Commit ·
8b03c49
1
Parent(s): 056f269
fix bugs
Browse files
app.py
CHANGED
|
@@ -1,32 +1,31 @@
|
|
| 1 |
from fastai.vision.all import *
|
| 2 |
import gradio as gr
|
| 3 |
-
import os
|
| 4 |
-
|
| 5 |
-
print(gr.__version__)
|
| 6 |
|
| 7 |
categories = ("grizzly bear", "black bear", "teddy bear")
|
| 8 |
-
|
| 9 |
learn = load_learner("export.pkl")
|
| 10 |
|
| 11 |
def classify_image(img):
|
| 12 |
pred, idx, probs = learn.predict(img)
|
| 13 |
return dict(zip(categories, map(float, probs)))
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
)
|
| 30 |
|
| 31 |
if __name__ == "__main__":
|
| 32 |
-
demo.launch()
|
|
|
|
| 1 |
from fastai.vision.all import *
|
| 2 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
categories = ("grizzly bear", "black bear", "teddy bear")
|
|
|
|
| 5 |
learn = load_learner("export.pkl")
|
| 6 |
|
| 7 |
def classify_image(img):
|
| 8 |
pred, idx, probs = learn.predict(img)
|
| 9 |
return dict(zip(categories, map(float, probs)))
|
| 10 |
|
| 11 |
+
with gr.Blocks() as demo:
|
| 12 |
+
gr.Markdown("# 🐻 Bear Classifier")
|
| 13 |
+
gr.Markdown("Classify different types of bears: grizzly, black, or teddy bears.")
|
| 14 |
+
|
| 15 |
+
with gr.Row():
|
| 16 |
+
image_input = gr.Image(height=192, width=192)
|
| 17 |
+
label_output = gr.Label()
|
| 18 |
+
|
| 19 |
+
btn = gr.Button("Classify")
|
| 20 |
+
btn.click(fn=classify_image, inputs=image_input, outputs=label_output)
|
| 21 |
|
| 22 |
+
gr.Examples(
|
| 23 |
+
examples=[
|
| 24 |
+
["examples/bears.jpg"],
|
| 25 |
+
["examples/grizzly.jpg"]
|
| 26 |
+
],
|
| 27 |
+
inputs=image_input
|
| 28 |
+
)
|
|
|
|
| 29 |
|
| 30 |
if __name__ == "__main__":
|
| 31 |
+
demo.launch()
|