Spaces:
Runtime error
Runtime error
Kelly Nicholes commited on
Commit ·
60e25b2
1
Parent(s): 9288c51
Fix prediction code
Browse files
app.py
CHANGED
|
@@ -4,22 +4,29 @@ __all__ = ['is_cat', 'learn', 'classify_image', 'categories', 'image', 'label',
|
|
| 4 |
from fastai.vision.all import *
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
-
def is_cat(x): return x[0].isupper()
|
| 8 |
-
|
| 9 |
# Cell
|
| 10 |
learn = load_learner('model.pkl')
|
| 11 |
|
| 12 |
# Cell
|
| 13 |
-
categories = ('Toronto, Canada', 'Denver, Colorado, USA', 'Emeryville, California, USA','Lehi, Utah, USA', 'Los Angeles, California, USA', 'College Park, Maryland, USA','Mexico City, Mexico', 'Arden Hills, Minnesota, USA', 'São Paulo, Brazil','New York, New York, USA', 'Portland, Oregon, USA', 'San Francisco, California, USA','Seattle, Washington, USA', 'Shanghai, China', 'Guangzhou, China', 'Hong Kong, China','Noida, India', 'Dublin, Ireland', 'Milan, Italy', 'Rome, Italy', 'Chisinau, Moldova','Amsterdam, Netherlands', 'Austin, Texas, USA', 'McLean, Virginia, USA','Washington D.C., USA', 'Atlanta, Georgia, USA', 'Waltham, Massachusetts, USA','Cambridge, Massachusetts, USA', 'San Jose, California, USA', 'Chicago, Illinois, USA','Ottawa, Canada', 'Bangalore, India', 'Mumbai, India', 'Gurgaon, India','Tokyo, Japan', 'Seoul, South Korea', 'Singapore, Singapore', 'Shenzhen, China','Bangkok, Thailand', 'Taipei, Taiwan', 'Melbourne, Australia', 'Sydney, Australia','Canberra, Australia', 'Yerevan, Armenia', 'Diegem, Belgium', 'Copenhagen, Denmark','Paris, France', 'Munich, Germany', 'Berlin, Germany', 'Hamburg, Germany','Basel, Switzerland', 'Zurich, Switzerland', 'Warsaw, Poland', 'Bucharest, Romania','Johannesburg, South Africa', 'Madrid, Spain', 'Barcelona, Spain', 'Stockholm, Sweden','Maidenhead, United Kingdom', 'London, United Kingdom', 'Edinburgh, Scotland')
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
# Cell
|
| 20 |
-
image = gr.inputs.Image(shape=(192, 192))
|
| 21 |
-
label = gr.outputs.Label()
|
| 22 |
-
examples = []
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
intf.launch(inline=False)
|
|
|
|
| 4 |
from fastai.vision.all import *
|
| 5 |
import gradio as gr
|
| 6 |
|
|
|
|
|
|
|
| 7 |
# Cell
|
| 8 |
learn = load_learner('model.pkl')
|
| 9 |
|
| 10 |
# Cell
|
| 11 |
+
# categories = ('Toronto, Canada', 'Denver, Colorado, USA', 'Emeryville, California, USA','Lehi, Utah, USA', 'Los Angeles, California, USA', 'College Park, Maryland, USA','Mexico City, Mexico', 'Arden Hills, Minnesota, USA', 'São Paulo, Brazil','New York, New York, USA', 'Portland, Oregon, USA', 'San Francisco, California, USA','Seattle, Washington, USA', 'Shanghai, China', 'Guangzhou, China', 'Hong Kong, China','Noida, India', 'Dublin, Ireland', 'Milan, Italy', 'Rome, Italy', 'Chisinau, Moldova','Amsterdam, Netherlands', 'Austin, Texas, USA', 'McLean, Virginia, USA','Washington D.C., USA', 'Atlanta, Georgia, USA', 'Waltham, Massachusetts, USA','Cambridge, Massachusetts, USA', 'San Jose, California, USA', 'Chicago, Illinois, USA','Ottawa, Canada', 'Bangalore, India', 'Mumbai, India', 'Gurgaon, India','Tokyo, Japan', 'Seoul, South Korea', 'Singapore, Singapore', 'Shenzhen, China','Bangkok, Thailand', 'Taipei, Taiwan', 'Melbourne, Australia', 'Sydney, Australia','Canberra, Australia', 'Yerevan, Armenia', 'Diegem, Belgium', 'Copenhagen, Denmark','Paris, France', 'Munich, Germany', 'Berlin, Germany', 'Hamburg, Germany','Basel, Switzerland', 'Zurich, Switzerland', 'Warsaw, Poland', 'Bucharest, Romania','Johannesburg, South Africa', 'Madrid, Spain', 'Barcelona, Spain', 'Stockholm, Sweden','Maidenhead, United Kingdom', 'London, United Kingdom', 'Edinburgh, Scotland')
|
| 12 |
+
|
| 13 |
|
| 14 |
+
labels = learn.dls.vocab
|
| 15 |
+
def predict(img):
|
| 16 |
+
img = PILImage.create(img)
|
| 17 |
+
pred,pred_idx,probs = learn.predict(img)
|
| 18 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 19 |
+
|
| 20 |
+
# def classify_image(img):
|
| 21 |
+
# pred,idx,probs = learn.predict(img)
|
| 22 |
+
# return dict(zip(categories, map(float,probs)))
|
| 23 |
|
| 24 |
# Cell
|
| 25 |
+
# image = gr.inputs.Image(shape=(192, 192))
|
| 26 |
+
# label = gr.outputs.Label()
|
| 27 |
+
# examples = []
|
| 28 |
+
|
| 29 |
+
# intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 30 |
+
# intf.launch(inline=False)
|
| 31 |
|
| 32 |
+
gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3)).launch(share=True)
|
|
|