alperugurcan's picture
Create app.py
f02a8e0 verified
import streamlit as st
import pandas as pd
import joblib
# Page config
st.set_page_config(page_title="Blueberry Yield Predictor", layout="wide")
# Load model and scaler
@st.cache_resource
def load_model():
model = joblib.load('model.joblib')
scaler = joblib.load('scaler.joblib')
return model, scaler
model, scaler = load_model()
# App title
st.title('🫐 Blueberry Yield Predictor')
st.markdown('Enter field parameters to predict blueberry yield')
# Create two columns for inputs
col1, col2 = st.columns(2)
with col1:
st.subheader('Field Parameters')
clonesize = st.slider('Clone Size', 10.0, 40.0, 25.0)
honeybee = st.slider('Honeybee', 0.0, 1.0, 0.5)
bumbles = st.slider('Bumbles', 0.0, 1.0, 0.25)
andrena = st.slider('Andrena', 0.0, 1.0, 0.5)
with col2:
st.subheader('Environmental Parameters')
osmia = st.slider('Osmia', 0.0, 1.0, 0.5)
MaxOfUpperTRange = st.slider('Max Temperature (°F)', 60.0, 100.0, 80.0)
MinOfUpperTRange = st.slider('Min Temperature (°F)', 35.0, 60.0, 50.0)
RainingDays = st.slider('Raining Days', 1.0, 34.0, 20.0)
# Predict button
if st.button('Predict Yield'):
# Create input data
input_data = pd.DataFrame({
'clonesize': [clonesize],
'honeybee': [honeybee],
'bumbles': [bumbles],
'andrena': [andrena],
'osmia': [osmia],
'MaxOfUpperTRange': [MaxOfUpperTRange],
'MinOfUpperTRange': [MinOfUpperTRange],
'AverageOfUpperTRange': [(MaxOfUpperTRange + MinOfUpperTRange) / 2],
'MaxOfLowerTRange': [60.0],
'MinOfLowerTRange': [30.0],
'AverageOfLowerTRange': [45.0],
'RainingDays': [RainingDays],
'AverageRainingDays': [RainingDays/100],
'fruitset': [0.5],
'fruitmass': [0.45],
'seeds': [35.0]
})
# Scale and predict
input_scaled = scaler.transform(input_data)
prediction = model.predict(input_scaled)[0]
# Display prediction
st.success(f'Predicted Yield: {prediction:.2f}')