Spaces:
Runtime error
Runtime error
| # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb. | |
| # %% auto 0 | |
| __all__ = ['learn', 'categorie', 'img', 'lbl', 'esempi', 'intfc', 'is_cat', 'classify_images'] | |
| # %% app.ipynb 2 | |
| from fastai.vision.all import * | |
| import gradio as gr | |
| def is_cat(x): return x[0].isupper() | |
| # %% app.ipynb 4 | |
| learn = load_learner('model.pkl') | |
| # %% app.ipynb 6 | |
| categorie = ('Cane', 'Gatto') | |
| def classify_images(immagine): | |
| immagine = immagine.resize((512, 512)) # Resize to 512x512 -> non credo funzioni, serviva perche shape(192, 192) non si usa più | |
| immagine = PILImage.create(immagine) # stesso motivo di sopra | |
| pred, idx, probs = learn.predict(immagine) | |
| return dict(zip(categorie, map(float, probs))) | |
| # %% app.ipynb 8 | |
| img = gr.Image(type="pil", image_mode="RGB") # stesso motivo di sopra | |
| lbl = gr.Label() | |
| esempi = ['dog.jpg', 'cat.jpg', 'elephant.jpg'] | |
| intfc = gr.Interface(fn=classify_images, inputs=img, outputs=lbl, examples=esempi) | |
| intfc.launch(inline=False, share=True) | |