arjun-ms commited on
Commit
91e7a00
·
verified ·
1 Parent(s): 8b3c7f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
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
- import skimage
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
- labels = learn.dls.vocab
14
- def predict(img):
15
- img = PILImage.create(img)
16
- pred,pred_idx,probs = learn.predict(img)
17
- return {labels[i]: float(probs[i]) for i in range(len(labels))}
 
 
 
 
18
 
19
- title = "Cat v/s Dog Classifier"
20
- description = "Cat v/s Dog classifier "
21
- article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
22
  examples = ['siamese.jpg']
23
- interpretation='default'
24
- enable_queue=True
25
 
26
- gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch()
 
 
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)