import streamlit as st import pickle import numpy as np # Load the pre-trained model with open('model.pkl', 'rb') as file: model = pickle.load(file) # Define the mapping for encoded species values # Bream', 'Roach', 'Whitefish', 'Parkki', 'Perch', 'Pike', 'Smelt species_mapping = { 0: 'Bream', 1: 'Roach', 2: 'Whitefish', 3: 'Parkki', 4: 'Perch', 5: 'Pike', 6: 'Smelt', # Add other species mappings as needed } # Create reverse mapping from species name to encoded value reverse_species_mapping = {v: k for k, v in species_mapping.items()} # Streamlit app st.title('Fish Weight Prediction') # Select box for species species_options = list(species_mapping.values()) selected_species = st.selectbox('Select Species', species_options) # Convert selected species to encoded value species_encoded = reverse_species_mapping.get(selected_species, 0) # Default to 0 if not found # Input fields for the user to enter data as text inputs length1 = st.text_input('Length1 (cm) [Range: 0.0 - 100.0]', '0.0') length2 = st.text_input('Length2 (cm) [Range: 0.0 - 100.0]', '0.0') length3 = st.text_input('Length3 (cm) [Range: 0.0 - 100.0]', '0.0') height = st.text_input('Height (cm) [Range: 0.0 - 30.0]', '0.0') width = st.text_input('Width (cm) [Range: 0.0 - 30.0]', '0.0') # Convert text inputs to floats and handle errors try: length1 = float(length1) length2 = float(length2) length3 = float(length3) height = float(height) width = float(width) except ValueError: st.error("Please enter valid numerical values.") length1 = length2 = length3 = height = width = 0.0 # Button to make prediction if st.button('Predict'): # Prepare the input data for the model input_data = np.array([[length1, length2, length3, height, width, species_encoded]]) # Make prediction predicted_weight = model.predict(input_data) # Display the result st.write(f'The predicted weight is: {predicted_weight[0]:.2f} grams') st.markdown("""

Created by Sukhman

This Streamlit app predicts the weight of Fish based on its features.

""", unsafe_allow_html=True)