Spaces:
Build error
Build error
File size: 4,397 Bytes
e3fd509 b3211ba 5cffa45 ca1f114 383b57d e3fd509 37cc055 1e5e6bc 37cc055 ca1f114 37cc055 ca1f114 37cc055 b3211ba 37cc055 b3211ba ca1f114 b3211ba 37cc055 b3211ba ca1f114 37cc055 ca1f114 37cc055 ca1f114 383b57d b3211ba 37cc055 b3211ba 37cc055 b3211ba 37cc055 b3211ba 37cc055 ca1f114 37cc055 ca1f114 37cc055 ca1f114 37cc055 ca1f114 37cc055 ca1f114 37cc055 ca1f114 37cc055 ca1f114 37cc055 ca1f114 37cc055 ca1f114 37cc055 ca1f114 1fcec90 | 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.graph_objects as go
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
# Page Configuration
st.set_page_config(page_title="Agriculture and Crop Monitoring", layout="wide")
# Prediction Function
def predict_growth(crop_data, weeks_to_predict=8):
X = crop_data[['هفته', 'رشد']].dropna().values
y = crop_data['رشد'].dropna().values
model = LinearRegression()
model.fit(X, y)
future_weeks = [[week, crop_data[crop_data['هفته'] == week]['رشد'].mean()] for week in range(1, weeks_to_predict + 1)]
future_weeks_df = pd.DataFrame(future_weeks, columns=['هفته', 'رشد'])
predictions = model.predict(future_weeks_df)
future_weeks_df['Prediction Growth'] = predictions
return future_weeks_df
# Sidebar
st.sidebar.title("Menu")
menu = st.sidebar.selectbox("Choose an option", ["Show Charts", "Predict Crop Growth using Machine Learning", "Chat Bot"])
# Chat Bot
if menu == "Chat Bot":
st.sidebar.markdown("""
<script src="https://cdn.botpress.cloud/webchat/v2/inject.js"></script>
<script>
window.botpressWebChat.init({
hostUrl: "https://cdn.botpress.cloud/webchat/v2",
messagingUrl: "https://mediafiles.botpress.cloud/29d24895-b0fa-4941-a3c4-8afa638f8b28",
botId: "your-bot-id",
})
</script>
""", unsafe_allow_html=True)
# Show Charts
elif menu == "Show Charts":
st.title("Charts and Graphs of Sugarcane Farm Growth and Height")
if 'crop_data' not in st.session_state:
uploaded_file = st.file_uploader("Upload growth and height data file", type="csv")
if uploaded_file:
st.session_state.crop_data = pd.read_csv(uploaded_file)
st.write("Growth and height data uploaded.")
else:
crop_data = st.session_state.crop_data
farms = crop_data['مزرعه'].unique()
selected_farm = st.selectbox("Select Farm", farms)
farm_data = crop_data[crop_data['مزرعه'] == selected_farm]
st.subheader("Growth and Height of Plant Over Different Weeks")
fig, ax = plt.subplots(1, 2, figsize=(14, 6))
sns.lineplot(x="هفته", y="رشد", data=farm_data, ax=ax[0], color="b")
ax[0].set_title("Plant Growth")
ax[0].set_xlabel("Week")
ax[0].set_ylabel("Growth")
sns.lineplot(x="هفته", y="ارتفاع", data=farm_data, ax=ax[1], color="g")
ax[1].set_title("Plant Height")
ax[1].set_xlabel("Week")
ax[1].set_ylabel("Height")
st.pyplot(fig)
st.subheader("3D Plant Height Chart")
fig = go.Figure(data=[go.Surface(z=farm_data.pivot(index='هفته', columns='مزرعه', values='ارتفاع').values)])
fig.update_layout(
title='3D Plant Height Chart',
autosize=True,
scene=dict(
zaxis_title='Height',
xaxis_title='Week',
yaxis_title='Farm'
),
margin=dict(l=65, r=50, b=65, t=90)
)
st.plotly_chart(fig)
# Predict Crop Growth using Machine Learning
elif menu == "Predict Crop Growth using Machine Learning":
st.title("Predict Crop Growth using Machine Learning")
if 'crop_data' not in st.session_state:
uploaded_file = st.file_uploader("Upload growth and height data file", type="csv")
if uploaded_file:
st.session_state.crop_data = pd.read_csv(uploaded_file)
st.write("Growth and height data uploaded.")
else:
crop_data = st.session_state.crop_data
farms = crop_data['مزرعه'].unique()
selected_farm = st.selectbox("Select Farm", farms)
farm_data = crop_data[crop_data['مزرعه'] == selected_farm]
predicted_growth = predict_growth(farm_data)
st.subheader("Predicted Growth for Week 8")
st.write(predicted_growth)
st.subheader("Predicted Growth Chart")
fig, ax = plt.subplots(figsize=(10, 6))
sns.lineplot(x=predicted_growth['هفته'], y=predicted_growth['Prediction Growth'], ax=ax, color="m")
ax.set_title("Predicted Growth")
ax.set_xlabel("Week")
ax.set_ylabel("Predicted Growth")
st.pyplot(fig)
|