Spaces:
Runtime error
Runtime error
Download app.py from aalst/tmp-dat255: direct link, hf CLI and curl.
- Browser
- Download file 712 Bytes
-
https://huggingface.co/spaces/aalst/tmp-dat255/resolve/main/app.py
- Command line
-
hf download hf://spaces/aalst/tmp-dat255/app.py
-
curl -L -o app.py https://huggingface.co/spaces/aalst/tmp-dat255/resolve/main/app.py
712 Bytes
| # Import the necessary libraries | |
| from fastai.vision.all import * | |
| import gradio as gr | |
| # Load the trained model | |
| learn = load_learner('export.pkl') | |
| # Get the labels from the model's dataloader | |
| labels = learn.dls.vocab | |
| # Function to classify an image using the model | |
| def classify_image(img): | |
| pred,pred_idx,probs = learn.predict(img) | |
| return dict(zip(labels, probs)) | |
| # Create the Gradio interface | |
| image_input = gr.components.Image() | |
| label_output = gr.components.Label() | |
| examples = [f"assets/{fn}" for fn in ["bergen.jpg", "oslo.jpg", "newyork.jpg"]] | |
| iface = gr.Interface( | |
| fn=classify_image, | |
| inputs=image_input, | |
| outputs=label_output, | |
| examples=examples | |
| ) | |
| iface.launch(inline=False) |