Spaces:
Sleeping
Sleeping
george sami commited on
Commit ·
4a51d89
1
Parent(s): 251a7c9
Add application file
Browse files
app.py
CHANGED
|
@@ -1,21 +1,18 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from fastai.vision.all import *
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
def is_cat(x): return x[0].isupper()
|
| 7 |
-
|
| 8 |
-
learner = load_learner('model.pkl')
|
| 9 |
-
|
| 10 |
-
categories = ('cat', 'dog')
|
| 11 |
|
| 12 |
def classify_image(img):
|
| 13 |
pred, pred_idx, probs = learner.predict(img)
|
| 14 |
-
return
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
demo
|
| 21 |
-
demo.launch(inline=False)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from fastai.vision.all import *
|
| 3 |
|
| 4 |
+
learner = load_learner("model.pkl")
|
| 5 |
+
categories = ("cat", "dog")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def classify_image(img):
|
| 8 |
pred, pred_idx, probs = learner.predict(img)
|
| 9 |
+
return {categories[i]: float(probs[i]) for i in range(len(categories))}
|
| 10 |
|
| 11 |
+
demo = gr.Interface(
|
| 12 |
+
fn=classify_image,
|
| 13 |
+
inputs=gr.Image(type="pil"),
|
| 14 |
+
outputs=gr.Label(),
|
| 15 |
+
examples=["cat1.jpeg", "dog1.avif", "cat2.jpeg", "dog2.webp"],
|
| 16 |
+
)
|
| 17 |
|
| 18 |
+
demo.launch()
|
|
|