Spaces:
Build error
Build error
File size: 2,294 Bytes
ea9610d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
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("""
<div style='text-align: center; padding: 20px;'>
<h4>Created by Sukhman</h4>
<p>This Streamlit app predicts the weight of Fish based on its features.</p>
</div>
""", unsafe_allow_html=True) |