Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from sklearn.linear_model import LinearRegression | |
from PIL import Image | |
def welcome(): | |
return "Welcome to the Sugarcane Growth Analysis App" | |
def analyze_data(data): | |
# Assuming the data has a 'Week' column for the week number and a 'Growth' column for the growth value | |
X = data['Week'].values.reshape(-1,1) | |
y = data['Growth'].values.reshape(-1,1) | |
model = LinearRegression() | |
model.fit(X, y) | |
y_pred = model.predict(X) | |
return X, y, y_pred | |
def predict_future_growth(data, future_weeks): | |
# Assuming the data has a 'Week' column for the week number and a 'Growth' column for the growth value | |
X = data['Week'].values.reshape(-1,1) | |
y = data['Growth'].values.reshape(-1,1) | |
model = LinearRegression() | |
model.fit(X, y) | |
future_weeks = np.array(future_weeks).reshape(-1,1) | |
future_growth = model.predict(future_weeks) | |
return future_weeks, future_growth | |
def main(): | |
st.title(welcome()) | |
menu = ["Upload File", "Input Weekly Growth", "Upload Previous Years' Growth and Satellite Images"] | |
choice = st.sidebar.selectbox("Menu", menu) | |
if choice == "Upload File": | |
file = st.file_uploader("Upload your file", type=["csv", "xlsx", "ppt", "pptx", "doc", "docx"]) | |
if file is not None: | |
st.success("File uploaded successfully") | |
elif choice == "Input Weekly Growth": | |
data = st.file_uploader("Upload your CSV file", type=["csv"]) | |
if data is not None: | |
df = pd.read_csv(data) | |
X, y, y_pred = analyze_data(df) | |
st.write("Week vs Growth") | |
plt.scatter(X, y, color='blue') | |
plt.plot(X, y_pred, color='red') | |
plt.show() | |
elif choice == "Upload Previous Years' Growth and Satellite Images": | |
data = st.file_uploader("Upload your CSV file", type=["csv"]) | |
image = st.file_uploader("Upload your satellite image", type=["png", "jpg", "jpeg"]) | |
future_weeks = st.number_input("Enter the number of future weeks for prediction") | |
if data is not None and image is not None and future_weeks is not None: | |
df = pd.read_csv(data) | |
future_weeks, future_growth = predict_future_growth(df, future_weeks) | |
st.write("Future Weeks vs Predicted Growth") | |
plt.plot(future_weeks, future_growth, color='green') | |
plt.show() | |
st.image(Image.open(image), caption='Satellite Image') | |
if __name__ == '__main__': | |
main() | |