Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- app.py +69 -0
- fish dataset.ipynb +0 -0
- model.pkl +3 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pickle
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
# Load the pre-trained model
|
6 |
+
with open('model.pkl', 'rb') as file:
|
7 |
+
model = pickle.load(file)
|
8 |
+
|
9 |
+
# Define the mapping for encoded species values
|
10 |
+
# Bream', 'Roach', 'Whitefish', 'Parkki', 'Perch', 'Pike', 'Smelt
|
11 |
+
species_mapping = {
|
12 |
+
0: 'Bream',
|
13 |
+
1: 'Roach',
|
14 |
+
2: 'Whitefish',
|
15 |
+
3: 'Parkki',
|
16 |
+
4: 'Perch',
|
17 |
+
5: 'Pike',
|
18 |
+
6: 'Smelt',
|
19 |
+
# Add other species mappings as needed
|
20 |
+
}
|
21 |
+
|
22 |
+
# Create reverse mapping from species name to encoded value
|
23 |
+
reverse_species_mapping = {v: k for k, v in species_mapping.items()}
|
24 |
+
|
25 |
+
# Streamlit app
|
26 |
+
st.title('Fish Weight Prediction')
|
27 |
+
|
28 |
+
# Select box for species
|
29 |
+
species_options = list(species_mapping.values())
|
30 |
+
selected_species = st.selectbox('Select Species', species_options)
|
31 |
+
|
32 |
+
# Convert selected species to encoded value
|
33 |
+
species_encoded = reverse_species_mapping.get(selected_species, 0) # Default to 0 if not found
|
34 |
+
|
35 |
+
# Input fields for the user to enter data as text inputs
|
36 |
+
length1 = st.text_input('Length1 (cm) [Range: 0.0 - 100.0]', '0.0')
|
37 |
+
length2 = st.text_input('Length2 (cm) [Range: 0.0 - 100.0]', '0.0')
|
38 |
+
length3 = st.text_input('Length3 (cm) [Range: 0.0 - 100.0]', '0.0')
|
39 |
+
height = st.text_input('Height (cm) [Range: 0.0 - 30.0]', '0.0')
|
40 |
+
width = st.text_input('Width (cm) [Range: 0.0 - 30.0]', '0.0')
|
41 |
+
|
42 |
+
# Convert text inputs to floats and handle errors
|
43 |
+
try:
|
44 |
+
length1 = float(length1)
|
45 |
+
length2 = float(length2)
|
46 |
+
length3 = float(length3)
|
47 |
+
height = float(height)
|
48 |
+
width = float(width)
|
49 |
+
except ValueError:
|
50 |
+
st.error("Please enter valid numerical values.")
|
51 |
+
length1 = length2 = length3 = height = width = 0.0
|
52 |
+
|
53 |
+
# Button to make prediction
|
54 |
+
if st.button('Predict'):
|
55 |
+
# Prepare the input data for the model
|
56 |
+
input_data = np.array([[length1, length2, length3, height, width, species_encoded]])
|
57 |
+
|
58 |
+
# Make prediction
|
59 |
+
predicted_weight = model.predict(input_data)
|
60 |
+
|
61 |
+
# Display the result
|
62 |
+
st.write(f'The predicted weight is: {predicted_weight[0]:.2f} grams')
|
63 |
+
|
64 |
+
st.markdown("""
|
65 |
+
<div style='text-align: center; padding: 20px;'>
|
66 |
+
<h4>Created by Sukhman</h4>
|
67 |
+
<p>This Streamlit app predicts the weight of Fish based on its features.</p>
|
68 |
+
</div>
|
69 |
+
""", unsafe_allow_html=True)
|
fish dataset.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:755a02b128a0bca948081fa6f8a915c41bf56c22f5c8751c3c167f3a992ba794
|
3 |
+
size 651
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
scikit-learn
|
2 |
+
streamlit
|
3 |
+
numpy
|