Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,28 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
from fastai.vision.all import *
|
| 3 |
from fastai.vision.widgets import *
|
| 4 |
from fastai.vision.core import PILImage
|
| 5 |
from fastai.learner import load_learner
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
# Define the is_cat function that was used when creating the model
|
| 9 |
-
def is_cat(x): return x[0].isupper() # This is a common implementation, adjust if yours was different
|
| 10 |
|
|
|
|
| 11 |
learn = load_learner('model.pkl')
|
| 12 |
|
| 13 |
-
|
| 14 |
-
def
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
examples = ['siamese.jpg']
|
| 23 |
-
|
| 24 |
-
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
| 1 |
from fastai.vision.all import *
|
| 2 |
from fastai.vision.widgets import *
|
| 3 |
from fastai.vision.core import PILImage
|
| 4 |
from fastai.learner import load_learner
|
| 5 |
+
def is_cat(x):
|
| 6 |
+
return x[0].isupper()
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
# Load the learner
|
| 9 |
learn = load_learner('model.pkl')
|
| 10 |
|
| 11 |
+
categories = ('Dog','Cat')
|
| 12 |
+
def classify_image(img):
|
| 13 |
+
pred,idx,probs = learn.predict(img)
|
| 14 |
+
return dict(zip(categories, map(float,probs)))
|
| 15 |
+
|
| 16 |
+
#gradio interface
|
| 17 |
+
import gradio as gr
|
| 18 |
+
from gradio import Interface, Image as grImage, Label
|
| 19 |
+
from PIL import Image
|
| 20 |
|
| 21 |
+
# Create input and output components
|
| 22 |
+
image = gr.Image()
|
| 23 |
+
label = gr.Label()
|
| 24 |
examples = ['siamese.jpg']
|
| 25 |
+
# Create Gradio interface
|
| 26 |
+
intf = Interface(fn=classify_image, inputs=image, outputs=label, title="CAT and DOG Classifier", examples = examples)
|
| 27 |
|
| 28 |
+
intf.launch(inline=False)
|