yexuefeng commited on
Commit
8b03c49
·
1 Parent(s): 056f269
Files changed (1) hide show
  1. app.py +18 -19
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
- image = gr.Image(height=192, width=192)
16
- label = gr.Label()
17
- examples = [
18
- "examples/bears.jpg",
19
- "examples/grizzly.jpg"
20
- ]
 
 
 
 
21
 
22
- demo = gr.Interface(
23
- fn=classify_image,
24
- inputs=image,
25
- outputs=label,
26
- examples=examples,
27
- title="Bear Classifier",
28
- description="Classify different types of bears: grizzly, black, or teddy bears."
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()