Spaces:
Runtime error
Runtime error
Commit
·
b6e8250
1
Parent(s):
3970b3b
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from fastai.vision.all import *
|
3 |
+
from fastcore.all import *
|
4 |
+
|
5 |
+
learn = load_learner("animal_species_detection.pkl")
|
6 |
+
|
7 |
+
categories = ("cat","horse","rabbit")
|
8 |
+
|
9 |
+
def classify_img(img):
|
10 |
+
pred,idx,probs = learn.predict(img)
|
11 |
+
return dict(zip(categories, map(float,probs)))
|
12 |
+
|
13 |
+
with gr.Blocks(title ="which animal is this ?") as demo:
|
14 |
+
with gr.Row():
|
15 |
+
gr.Markdown("""
|
16 |
+
## Animal species detection
|
17 |
+
#### upload photo!
|
18 |
+
#### click on the photos to try
|
19 |
+
""")
|
20 |
+
with gr.Row():
|
21 |
+
image = gr.inputs.Image(shape=(192,192))
|
22 |
+
with gr.Row():
|
23 |
+
output = gr.outputs.Label()
|
24 |
+
with gr.Row():
|
25 |
+
image_button = gr.Button("PREDİCT")
|
26 |
+
image_button.click(classify_img, inputs=image, outputs=output)
|
27 |
+
|
28 |
+
with gr.Row():
|
29 |
+
with gr.Column():
|
30 |
+
gr.Examples(inputs=image,examples=["r1.jpg"],label="rabbit")
|
31 |
+
with gr.Column():
|
32 |
+
gr.Examples(inputs=image,examples=["r2.jpg"],label="rabbit")
|
33 |
+
with gr.Column():
|
34 |
+
gr.Examples(inputs=image,examples=["r2.jpg"],label="rabbit")
|
35 |
+
with gr.Column():
|
36 |
+
gr.Examples(inputs=image,examples=["h1.jpg"],label="horse")
|
37 |
+
with gr.Column():
|
38 |
+
gr.Examples(inputs=image,examples=["h2.jpg"],label="horse")
|
39 |
+
with gr.Column():
|
40 |
+
gr.Examples(inputs=image,examples=["h3.jpg"],label="horse")
|
41 |
+
with gr.Column():
|
42 |
+
gr.Examples(inputs=image,examples=["c1.jpg"],label="cat")
|
43 |
+
with gr.Column():
|
44 |
+
gr.Examples(inputs=image,examples=["c2.jpg"],label="cat")
|
45 |
+
with gr.Column():
|
46 |
+
gr.Examples(inputs=image,examples=["c3.jpg"],label="cat")
|
47 |
+
|
48 |
+
demo.launch()
|
49 |
+
|