Spaces:
Sleeping
Sleeping
| #__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'is_cat', 'classify_image'] | |
| #import timm | |
| # %% app.ipynb 2 | |
| from fastai.vision.all import * | |
| import gradio as gr | |
| #import timm | |
| def is_cat(x): return x[0].isupper() | |
| # %% app.ipynb 4 | |
| learn = load_learner('app.pkl') | |
| # %% app.ipynb 6 | |
| categories = ('Alpine', 'AstonMartin', 'Ferrari', 'Haas', 'McLaren', 'Mercedes', 'RB' , 'Redbull', 'Sauber', 'Williams') | |
| #categories = ( 'Mercedes cars', 'Ferrari cars', 'BMW cars', 'Bentley cars', 'Porsche cars', 'Aston Martin cars', 'Audi cars' , 'Maserati cars', 'McLaren cars', 'Lamborghini cars', 'Bugatti cars', 'Koenigsegg cars', 'Pagani cars', 'Tesla cars') | |
| #categories = ('Dog', 'Cat') | |
| def classify_image(img): | |
| pred, idx, probs = learn.predict(img) | |
| return dict(zip(categories, map(float, probs))) | |
| # %% app.ipynb 8 | |
| from gradio.components import Image, Label | |
| # %% app.ipynb 9 | |
| image = Image(width=300, height=240) | |
| label = Label() | |
| examples = ['mclaren.jpg', 'ferrari_f1.jpg', 'redbull_f1.jpg', | |
| 'merc.jpg', 'aston_martin.jpg', 'alpine.jpg', 'haas.jpg', | |
| 'sauber.jpg', 'rb.jpg', 'williams.jpg' | |
| ] | |
| intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) | |
| intf.launch(inline=False) |