Spaces:
Runtime error
Runtime error
Download pages/1_Image_Classification.py from PatternGroup5/pattern: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/spaces/PatternGroup5/pattern/resolve/faecf5b4f20034e092b2173ddaa9bfb8d83f14eb/pages/1_Image_Classification.py
- Command line
-
hf download hf://spaces/PatternGroup5/pattern@faecf5b4f20034e092b2173ddaa9bfb8d83f14eb/pages/1_Image_Classification.py
-
curl -L -o 1_Image_Classification.py https://huggingface.co/spaces/PatternGroup5/pattern/resolve/faecf5b4f20034e092b2173ddaa9bfb8d83f14eb/pages/1_Image_Classification.py
1.08 kB
| from utils.layout import render_layout | |
| import streamlit as st | |
| from PIL import Image | |
| from model.classifier import get_model, predict | |
| def classification_page(): | |
| st.markdown("## 🖼️ Task A: Image Classification") | |
| st.markdown(""" | |
| <div class="about-box"> | |
| This module classifies images into <b>Onion, Pear, Strawberry, or Tomato</b> | |
| using an EfficientNet-B0 model. | |
| </div> | |
| """, unsafe_allow_html=True) | |
| model = load_model() | |
| uploaded = st.file_uploader("📤 Upload an image (JPG/PNG)", type=["jpg", "jpeg", "png"]) | |
| if uploaded: | |
| img = Image.open(uploaded).convert("RGB") | |
| label, confidence = predict(img, model) | |
| print(label) | |
| st.success(f"🎯 Prediction: **{label.upper()}** ({confidence*100:.2f}% confidence)") | |
| st.markdown("<div style='text-align: center;'>", unsafe_allow_html=True) | |
| st.image(img, caption="Uploaded Image", width=300) | |
| st.markdown("</div>", unsafe_allow_html=True) | |
| def load_model(): | |
| return get_model() | |
| render_layout(classification_page) | |