CropSync / app.py
hardin009's picture
Update app.py
200ab7e verified
import streamlit as st
from datetime import datetime
import pandas as pd
# Import your PotatoPricePredictor class
from potato_price_model import PotatoPricePredictor # Replace 'your_module' with the actual module name
# Initialize the predictor
predictor = PotatoPricePredictor()
# Set up the Streamlit app
st.title("Agri Commodity Price Prediction App")
# Sidebar for user inputs
st.sidebar.header("Input Parameters")
def get_user_input():
date = st.sidebar.date_input("Date", datetime.now())
arrival_quantity = st.sidebar.number_input("Arrival Quantity", min_value=0, value=1000)
temperature = st.sidebar.number_input("Temperature (°C)", min_value=-30, max_value=50, value=25)
humidity = st.sidebar.slider("Humidity (%)", min_value=0, max_value=100, value=60)
wind_direction = st.sidebar.number_input("Wind Direction (°)", min_value=0, max_value=360, value=180)
events = st.sidebar.text_input("Events Description", "Normal day")
impacts = st.sidebar.text_input("Impacts Description", "No significant impacts")
price_lag1 = st.sidebar.number_input("Price Lag 1", min_value=0.0, value=50.0)
price_lag7 = st.sidebar.number_input("Price Lag 7", min_value=0.0, value=50.0)
price_rolling_mean7 = st.sidebar.number_input("Price Rolling Mean 7", min_value=0.0, value=50.0)
price_rolling_std7 = st.sidebar.number_input("Price Rolling Std 7", min_value=0.0, value=2.0)
prev_week_avg_price = st.sidebar.number_input("Previous Week Avg Price", min_value=0.0, value=50.0)
data = {
'Date': date.strftime('%Y-%m-%d'),
'ArrivalQuantity': arrival_quantity,
'Temperature': temperature,
'Humidity': humidity,
'Wind direction': wind_direction,
'Events': events,
'Impacts': impacts,
'PriceLag1': price_lag1,
'PriceLag7': price_lag7,
'PriceRollingMean7': price_rolling_mean7,
'PriceRollingStd7': price_rolling_std7,
'PrevWeekAvgPrice': prev_week_avg_price
}
return data
# Get user input
user_input = get_user_input()
# Button to predict current price
if st.button('Predict Current Price'):
prediction = predictor.predict(user_input)
st.write(f"Predicted Price: ₹{prediction['predicted_price']:.2f}")
# Input for predicting future prices
st.sidebar.header("Predict Future Prices")
days_to_predict = st.sidebar.number_input("Days to Predict", min_value=1, max_value=365, value=30)
# Button to predict future prices
if st.sidebar.button('Predict Future Prices'):
future_prices = predictor.predict_future(days_to_predict)
future_df = pd.DataFrame(future_prices['future_prices'])
st.write(f"Predicted Prices for the next {days_to_predict} days")
st.dataframe(future_df)
# Plotting future prices
st.line_chart(future_df.set_index('date')['price'])