Download app.py from devudilip/test2: direct link, hf CLI and curl.
- Browser
- Download file 883 Bytes
-
https://huggingface.co/spaces/devudilip/test2/resolve/bd4c503c5d3efaaa34c011205d5dc6a59cd5398d/app.py
- Command line
-
hf download hf://spaces/devudilip/test2@bd4c503c5d3efaaa34c011205d5dc6a59cd5398d/app.py
-
curl -L -o app.py https://huggingface.co/spaces/devudilip/test2/resolve/bd4c503c5d3efaaa34c011205d5dc6a59cd5398d/app.py
883 Bytes
| # AUTOGENERATED! DO NOT EDIT! File to edit: test.ipynb. | |
| # %% auto 0 | |
| __all__ = ['learn', 'categories', 'image', 'label', 'examples', 'inf', 'classify_img'] | |
| # %% test.ipynb 2 | |
| from fastai.vision.all import * | |
| import gradio as gr | |
| # %% test.ipynb 4 | |
| learn = load_learner('model.pkl') | |
| # %% test.ipynb 5 | |
| categories = ('Art Deco', 'Baroque', 'Classical', 'Craftsman', 'Gothic', 'Renaissance', 'Tudor', 'Victorian') | |
| def classify_img(img): | |
| pred,idx,probs = learn.predict(img) | |
| # Convert each tensor probability to a float properly | |
| return dict(zip(categories, map(float, probs))) | |
| # %% test.ipynb 8 | |
| # Define Gradio interface | |
| image = gr.Image(image_mode="RGB", type="pil") | |
| label = gr.Label() | |
| examples = ['classical.jpg', 'artdec.jpg', 'victorian.jpeg'] | |
| inf = gr.Interface(fn=classify_img, inputs=image, outputs=label, examples=examples) | |
| # Launch the app | |
| inf.launch(inline=False) | |