Update app.py
Browse files
app.py
CHANGED
|
@@ -2,23 +2,16 @@
|
|
| 2 |
# coding: utf-8
|
| 3 |
# Dogs vs Cats
|
| 4 |
|
| 5 |
-
# In[7]:
|
| 6 |
-
|
| 7 |
#|export
|
| 8 |
from fastai.vision.all import *
|
| 9 |
import gradio as gr
|
|
|
|
| 10 |
|
| 11 |
def is_cat(x): return x[0].isupper()
|
| 12 |
|
| 13 |
-
|
| 14 |
-
# In[9]:
|
| 15 |
-
|
| 16 |
#|export
|
| 17 |
learn = load_learner('model.pkl')
|
| 18 |
|
| 19 |
-
|
| 20 |
-
# In[12]:
|
| 21 |
-
|
| 22 |
#|export
|
| 23 |
categories = ('Dog', 'Cat')
|
| 24 |
|
|
@@ -26,11 +19,22 @@ def classify_image(img):
|
|
| 26 |
pred, idx, probs = learn.predict(img)
|
| 27 |
return dict(zip(categories, map(float, probs)))
|
| 28 |
|
| 29 |
-
|
| 30 |
#|export
|
| 31 |
-
image = gr.components.Image(shape=(192, 192))
|
| 32 |
-
label = gr.components.Label()
|
| 33 |
-
examples = [
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
# coding: utf-8
|
| 3 |
# Dogs vs Cats
|
| 4 |
|
|
|
|
|
|
|
| 5 |
#|export
|
| 6 |
from fastai.vision.all import *
|
| 7 |
import gradio as gr
|
| 8 |
+
import os
|
| 9 |
|
| 10 |
def is_cat(x): return x[0].isupper()
|
| 11 |
|
|
|
|
|
|
|
|
|
|
| 12 |
#|export
|
| 13 |
learn = load_learner('model.pkl')
|
| 14 |
|
|
|
|
|
|
|
|
|
|
| 15 |
#|export
|
| 16 |
categories = ('Dog', 'Cat')
|
| 17 |
|
|
|
|
| 19 |
pred, idx, probs = learn.predict(img)
|
| 20 |
return dict(zip(categories, map(float, probs)))
|
| 21 |
|
|
|
|
| 22 |
#|export
|
| 23 |
+
image = gr.components.Image(shape=(192, 192))
|
| 24 |
+
label = gr.components.Label()
|
| 25 |
+
examples = [
|
| 26 |
+
os.path.join(os.path.dirname(__file__), "dog.jpg"),
|
| 27 |
+
os.path.join(os.path.dirname(__file__), "cat.jpg"),
|
| 28 |
+
os.path.join(os.path.dirname(__file__), "dunno.jpg"),
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
intf = gr.Interface(
|
| 32 |
+
fn=classify_image,
|
| 33 |
+
inputs=image,
|
| 34 |
+
outputs=label,
|
| 35 |
+
examples=examples,
|
| 36 |
+
flagging_options=["incorrect", "other"] # Adjust flagging options as needed
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
if __name__ == "__main__":
|
| 40 |
+
intf.launch(inline=False, share=True)
|