Spaces:
Runtime error
Runtime error
Elam
commited on
Commit
·
e90d11e
1
Parent(s):
9a4f29c
New interface with images
Browse files
app.py
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 7 |
-
iface.launch()
|
|
|
|
| 1 |
+
|
| 2 |
+
__all__ = ['learn','classify_image','categories','image','label','examples','intf']
|
| 3 |
+
|
| 4 |
+
from fastai.vision.all import *
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
+
learn = load_learner('model.pkl')
|
| 8 |
+
|
| 9 |
+
categories = ('Car', 'Bike')
|
| 10 |
+
def classify_image(img):
|
| 11 |
+
is_car,_,probs = learn.predict(PILImage.create(img))
|
| 12 |
+
return dict(zip(categories, map(float,probs))) #gradio only supports floats and it doesn't handle PyTorch tensors
|
| 13 |
+
|
| 14 |
+
image = gr.inputs.Image(shape=(192,192))
|
| 15 |
+
label = gr.outputs.Label()
|
| 16 |
+
examples = ['volkswagen.jpg','motorbike.jpg']
|
| 17 |
+
|
| 18 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 19 |
+
intf.launch(inline=False)
|
| 20 |
|
|
|
|
|
|