Spaces:
Runtime error
Runtime error
Max
commited on
Commit
·
6a60e36
1
Parent(s):
32b2785
Rebasing for model.pkl
Browse files- app.py +23 -4
- humid_subtropical.jpg +0 -0
- mediterranean.jpg +0 -0
- polar.jpg +0 -0
app.py
CHANGED
|
@@ -1,7 +1,26 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
|
| 4 |
+
categories = ("alpine", "desert", "humid continental", "humid subtropical", "ice cap",
|
| 5 |
+
"oceanic plant", "subarctic plant", "semi-arid plant", "mediterranean", "tropical monsoon",
|
| 6 |
+
"tropical rainforest plant", "tropical savanna plant", "tundra plant", "polar")
|
| 7 |
|
| 8 |
+
learn = load_learner("model.pkl")
|
| 9 |
+
|
| 10 |
+
# Gradio needs a function
|
| 11 |
+
def classify_image(img):
|
| 12 |
+
pred, idx, probs = learn.predict(img)
|
| 13 |
+
return dict(zip(categories, map(float, probs)))
|
| 14 |
+
|
| 15 |
+
# Build the Gradio interface
|
| 16 |
+
image = gr.inputs.Image(shape=(192,192))
|
| 17 |
+
label = gr.outputs.label()
|
| 18 |
+
examples = ["polar.jpg", "mediterranean.jpg", "humid_subtropical.jpg"]
|
| 19 |
+
|
| 20 |
+
intf = gr.Interface(fn=classify_image,
|
| 21 |
+
inputs=image,
|
| 22 |
+
outputs=label,
|
| 23 |
+
examples=examples)
|
| 24 |
+
|
| 25 |
+
# This will give us a link to play with the model in app
|
| 26 |
+
intf.launch(inline=False)
|
humid_subtropical.jpg
ADDED
|
mediterranean.jpg
ADDED
|
polar.jpg
ADDED
|