Instructions to use AIM-Focus-DEV/Image_classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use AIM-Focus-DEV/Image_classifier with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://AIM-Focus-DEV/Image_classifier") - Notebooks
- Google Colab
- Kaggle
Download st.py from AIM-Focus-DEV/Image_classifier: direct link, hf CLI and curl.
- Browser
- Download file 973 Bytes
-
https://huggingface.co/AIM-Focus-DEV/Image_classifier/resolve/main/st.py
- Command line
-
hf download hf://AIM-Focus-DEV/Image_classifier/st.py
-
curl -L -o st.py https://huggingface.co/AIM-Focus-DEV/Image_classifier/resolve/main/st.py
973 Bytes
| import streamlit as st | |
| import requests | |
| from PIL import Image | |
| from io import BytesIO | |
| CLASS_LABELS = { | |
| 0: "airplane", | |
| 1: "bird", | |
| 2: "car", | |
| 3: "cat", | |
| 4: "deer", | |
| 5: "dog", | |
| 6: "horse", | |
| 7: "monkey", | |
| 8: "ship", | |
| 9: "truck", | |
| } | |
| def get_classification(image_bytes): | |
| response = requests.post("http://localhost:5000/classify", files={"file": image_bytes}) | |
| class_id = response.json()["classification"] | |
| return CLASS_LABELS[class_id] | |
| st.title("Image Classification") | |
| st.write("Upload an image to classify") | |
| uploaded_file = st.file_uploader("Choose an image", type=["jpg", "jpeg", "png"]) | |
| if uploaded_file is not None: | |
| image = Image.open(uploaded_file) | |
| st.image(image, caption="Uploaded Image", use_column_width=True) | |
| if st.button("Classify"): | |
| img_bytes = uploaded_file.read() | |
| label = get_classification(img_bytes) | |
| st.write("Prediction:", label) | |