-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp1.py
85 lines (65 loc) · 3.11 KB
/
app1.py
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
# -*- coding: utf-8 -*-
"""app1.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1KPGQNmCzYS2jYRmqsqOFKCkw6COyJ_o2
"""
import streamlit as st
import joblib
import numpy as np
# Load the model
def load_model(file_path):
return joblib.load(file_path)
# Main application
def main():
# Load Model 1
model_1 = load_model('model_1d.pkl')
# Application title and layout
st.title("CropCrafter: Unlock Your Perfect Yield")
st.write("Enter your Minimum Yield and Maximum Yield :")
# Input fields for user interaction
st.header("Input Fields for Yield Prediction")
yield_min = st.number_input("Yield Min: g/m^2", min_value=1000.0, max_value=3000.0, value=1000.0)
yield_max = st.number_input("Yield Max: g/m^2", min_value=3000.0, max_value=4000.0, value=3000.0)
# Predict and display results
if st.button("Predict Yield"):
# Prepare input data
input_data = np.array([[yield_min, yield_max]])
# Debug: Display the input shape
st.write(f"Input Shape: {input_data.shape}")
st.write(f"Input Data: {input_data}")
try:
prediction = model_1.predict(input_data)
# Break down prediction into temperature, precipitation, and relative humidity
temperature, precipitation, relative_humidity = map(lambda x: round(x, 2), prediction[0])
st.success("Predicted Yield Components:")
st.write(f"Temperature: {temperature}°C")
st.write(f"Precipitation: {precipitation} mm")
st.write(f"Relative Humidity: {relative_humidity}%")
# Use the predicted values for calculations
seedling_temp = round(temperature * 0.25, 2)
tillering_temp = round(temperature * 0.30, 2)
flowering_temp = round(temperature * 0.25, 2)
harvesting_temp = round(temperature * 0.20, 2)
seedling_prec = round(precipitation * 0.25, 2)
tillering_prec = round(precipitation * 0.30, 2)
flowering_prec = round(precipitation * 0.25, 2)
harvesting_prec = round(precipitation * 0.20, 2)
seedling_hum = round(relative_humidity * 0.25, 2)
tillering_hum = round(relative_humidity * 0.30, 2)
flowering_hum = round(relative_humidity * 0.25, 2)
harvesting_hum = round(relative_humidity * 0.20, 2)
st.write("Tailored Factors for Every Growth Stage:")
# Create a table for displaying the calculations
table_data = {
"Stage": ["Seedling", "Tillering", "Flowering", "Harvesting"],
"Temperature (°C)": [seedling_temp, tillering_temp, flowering_temp, harvesting_temp],
"Precipitation (mm)": [seedling_prec, tillering_prec, flowering_prec, harvesting_prec],
"Relative Humidity (%)": [seedling_hum, tillering_hum, flowering_hum, harvesting_hum],
}
st.table(table_data)
except Exception as e:
st.error(f"An error occurred during prediction: {e}")
# Run the application
if __name__ == "__main__":
main()