import streamlit as st import numpy as np import urllib.request import io import skops.io as sio st.set_page_config(page_title="Iris Classifier", layout="centered") st.title("Iris Classifier") st.write( "Predict the species of an iris flower from its measurements, using the " "[mosesalphonse/iris-classifier](https://huggingface.co/mosesalphonse/iris-classifier) " "Random Forest model — running entirely in your browser." ) MODEL_URL = "https://huggingface.co/mosesalphonse/iris-classifier/resolve/main/model.skops" SPECIES = {0: "setosa", 1: "versicolor", 2: "virginica"} @st.cache_resource def load_model(): with urllib.request.urlopen(MODEL_URL) as response: data = response.read() buffer = io.BytesIO(data) untrusted_types = sio.get_untrusted_types(file=buffer) buffer.seek(0) return sio.load(buffer, trusted=untrusted_types) with st.spinner("Loading model..."): model = load_model() st.subheader("Flower measurements") col1, col2 = st.columns(2) with col1: sepal_length = st.slider("Sepal length (cm)", 4.0, 8.0, 5.1, 0.1) sepal_width = st.slider("Sepal width (cm)", 2.0, 4.5, 3.5, 0.1) with col2: petal_length = st.slider("Petal length (cm)", 1.0, 7.0, 1.4, 0.1) petal_width = st.slider("Petal width (cm)", 0.1, 2.5, 0.2, 0.1) features = np.array([[sepal_length, sepal_width, petal_length, petal_width]]) if st.button("Predict species", type="primary"): prediction = model.predict(features)[0] species_name = SPECIES.get(int(prediction), str(prediction)) st.success(f"Predicted species: **{species_name}**") if hasattr(model, "predict_proba"): proba = model.predict_proba(features)[0] st.subheader("Class probabilities") st.bar_chart( {SPECIES[i]: [p] for i, p in enumerate(proba)} ) with st.expander("Model details"): st.markdown( "- **Algorithm**: Random Forest (100 trees)\n" "- **Library**: scikit-learn\n" "- **Dataset**: Iris (150 samples, 4 features, 3 classes)\n" "- **Test accuracy**: 1.00\n" "- **Source**: [mosesalphonse/iris-classifier](https://huggingface.co/mosesalphonse/iris-classifier)" ) scikit-learn skops numpy