import streamlit as st import pandas as pd import pickle # Load the saved model with open("model.pkl", "rb") as file: model = pickle.load(file) # Title of the app st.title("Abalone Rings Predictor 🦪") st.write("An abalone is a type of shellfish, specifically a large sea snail belonging to the family Haliotidae. There are around 30 to 130 recognized species of abalone found in warm and cold coastal waters around the world. The rings, or rather the iridescent inner layer of the abalone shell, called mother-of-pearl, is what makes them so important. This layer is highly sought after for its beauty. It has a mesmerizing play of colors that shifts and changes depending on the light. These colors come from the way light interacts with the microscopic layers that make up the nacre.") st.image('https://i.pinimg.com/1200x/76/8c/e0/768ce06773574e045ff808e16ec341dc.jpg') # Instructions st.write("Enter the details of an abalone below to predict the number of rings it has.") # Prefilled example values example_data = { 'Sex': 'F', 'Length': 0.550, 'Diameter': 0.430, 'Height': 0.150, 'Whole weight': 0.7715, 'Whole weight.1': 0.3285, 'Whole weight.2': 0.1465, 'Shell weight': 0.2400, } # Input fields for the user sex = st.selectbox("Sex", ["M", "F", "I"], index=["M", "F", "I"].index(example_data['Sex'])) length = st.number_input("Length", min_value=0.0, max_value=1.0, step=0.1, value=example_data['Length']) diameter = st.number_input("Diameter", min_value=0.0, max_value=1.0, step=0.1, value=example_data['Diameter']) height = st.number_input("Height", min_value=0.0, max_value=1.0, step=0.1, value=example_data['Height']) whole_weight = st.number_input("Whole weight", min_value=0.0, step=0.1, value=example_data['Whole weight']) whole_weight_1 = st.number_input("Whole weight 1", min_value=0.0, step=0.1, value=example_data['Whole weight.1']) whole_weight_2 = st.number_input("Whole weight 2", min_value=0.0, step=0.1, value=example_data['Whole weight.2']) shell_weight = st.number_input("Shell weight", min_value=0.0, step=0.1, value=example_data['Shell weight']) # Prediction if st.button("Predict"): input_data = pd.DataFrame({ 'Sex': [sex], 'Length': [length], 'Diameter': [diameter], 'Height': [height], 'Whole weight': [whole_weight], 'Whole weight.1': [whole_weight_1], 'Whole weight.2': [whole_weight_2], 'Shell weight': [shell_weight] }) input_data['Sex'] = input_data['Sex'].map({'M': 0, 'F': 1, 'I': 2}) prediction = model.predict(input_data) st.header(f"The predicted number of rings is: ***{int(prediction[0])}***")