Ivan Rodrigues
commited on
Commit
•
27c1be4
1
Parent(s):
a35a168
Imported trained model + setup for Gradio UI
Browse files- app.py +23 -4
- examples/max.jpg +0 -0
- examples/nymo.jpg +0 -0
- model.pkl +3 -0
app.py
CHANGED
@@ -1,7 +1,26 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.vision.all import *
|
2 |
import gradio as gr
|
3 |
|
4 |
+
# Import trained model
|
5 |
+
learn = load_learner("model.pkl")
|
6 |
|
7 |
+
# Define an object with labels (keys) and tensors (values)
|
8 |
+
categories = {"Cat", "Dog"}
|
9 |
+
def classify_image(img):
|
10 |
+
pred,_,probs = learn.predict(img)
|
11 |
+
return dict(zip(categories, map(float,probs)))
|
12 |
+
|
13 |
+
# Build the Gradio interface
|
14 |
+
image = gr.inputs.Image(shape=(192, 192))
|
15 |
+
label = gr.outputs.Label()
|
16 |
+
examples = ["examples/max.jpg", "examples/nymo.jpg"]
|
17 |
+
|
18 |
+
intf = gr.Interface(
|
19 |
+
fn=classify_image,
|
20 |
+
inputs=image,
|
21 |
+
outputs=label,
|
22 |
+
examples=examples
|
23 |
+
)
|
24 |
+
|
25 |
+
# Start the server
|
26 |
+
intf.launch(inline=False)
|
examples/max.jpg
ADDED
![]() |
examples/nymo.jpg
ADDED
![]() |
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ec8dc96fafec2f360e9e0eaa60bbd8219a729bfd4a4b3dd1f20f0269438dca9e
|
3 |
+
size 46952857
|