Spaces:
Runtime error
Runtime error
Download app.py from principle/bears_space: direct link, hf CLI and curl.
- Browser
- Download file 810 Bytes
-
https://huggingface.co/spaces/principle/bears_space/resolve/main/app.py
- Command line
-
hf download hf://spaces/principle/bears_space/app.py
-
curl -L -o app.py https://huggingface.co/spaces/principle/bears_space/resolve/main/app.py
810 Bytes
| import gradio as gr | |
| from fastai.vision.all import * | |
| from huggingface_hub import hf_hub_download | |
| # Download the model from Hugging Face | |
| model_path = hf_hub_download(repo_id="principle/bears-classifier-model", filename="bears_modle.pkl") | |
| # Load the model | |
| learn = load_learner(model_path) | |
| # Define the prediction function | |
| def classify_bear(img): | |
| pred, pred_idx, probs = learn.predict(img) | |
| return { | |
| 'black': float(probs[0]), | |
| 'grizzly': float(probs[1]), | |
| 'teddy': float(probs[2]) | |
| } | |
| # Create the Gradio interface | |
| iface = gr.Interface( | |
| fn=classify_bear, | |
| inputs=gr.Image(), | |
| outputs=gr.Label(num_top_classes=3), | |
| title="Bear Classifier", | |
| description="Upload an image to classify the type of bear: grizzly, black, or teddy." | |
| ) | |
| # ! | |
| # Launch the app | |
| iface.launch() |