Esmaeilkiani commited on
Commit
513866d
·
verified ·
1 Parent(s): 9312c1d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import matplotlib.pyplot as plt
5
+ from sklearn.linear_model import LinearRegression
6
+ from PIL import Image
7
+
8
+ def welcome():
9
+ return "Welcome to the Sugarcane Growth Analysis App"
10
+
11
+ def analyze_data(data):
12
+ # Assuming the data has a 'Week' column for the week number and a 'Growth' column for the growth value
13
+ X = data['Week'].values.reshape(-1,1)
14
+ y = data['Growth'].values.reshape(-1,1)
15
+ model = LinearRegression()
16
+ model.fit(X, y)
17
+ y_pred = model.predict(X)
18
+ return X, y, y_pred
19
+
20
+ def predict_future_growth(data, future_weeks):
21
+ # Assuming the data has a 'Week' column for the week number and a 'Growth' column for the growth value
22
+ X = data['Week'].values.reshape(-1,1)
23
+ y = data['Growth'].values.reshape(-1,1)
24
+ model = LinearRegression()
25
+ model.fit(X, y)
26
+ future_weeks = np.array(future_weeks).reshape(-1,1)
27
+ future_growth = model.predict(future_weeks)
28
+ return future_weeks, future_growth
29
+
30
+ def main():
31
+ st.title(welcome())
32
+ menu = ["Upload File", "Input Weekly Growth", "Upload Previous Years' Growth and Satellite Images"]
33
+ choice = st.sidebar.selectbox("Menu", menu)
34
+
35
+ if choice == "Upload File":
36
+ file = st.file_uploader("Upload your file", type=["csv", "xlsx", "ppt", "pptx", "doc", "docx"])
37
+ if file is not None:
38
+ st.success("File uploaded successfully")
39
+
40
+ elif choice == "Input Weekly Growth":
41
+ data = st.file_uploader("Upload your CSV file", type=["csv"])
42
+ if data is not None:
43
+ df = pd.read_csv(data)
44
+ X, y, y_pred = analyze_data(df)
45
+ st.write("Week vs Growth")
46
+ plt.scatter(X, y, color='blue')
47
+ plt.plot(X, y_pred, color='red')
48
+ plt.show()
49
+
50
+ elif choice == "Upload Previous Years' Growth and Satellite Images":
51
+ data = st.file_uploader("Upload your CSV file", type=["csv"])
52
+ image = st.file_uploader("Upload your satellite image", type=["png", "jpg", "jpeg"])
53
+ future_weeks = st.number_input("Enter the number of future weeks for prediction")
54
+ if data is not None and image is not None and future_weeks is not None:
55
+ df = pd.read_csv(data)
56
+ future_weeks, future_growth = predict_future_growth(df, future_weeks)
57
+ st.write("Future Weeks vs Predicted Growth")
58
+ plt.plot(future_weeks, future_growth, color='green')
59
+ plt.show()
60
+ st.image(Image.open(image), caption='Satellite Image')
61
+
62
+ if __name__ == '__main__':
63
+ main()