-
Notifications
You must be signed in to change notification settings - Fork 37
/
app.py
77 lines (62 loc) · 2.95 KB
/
app.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
import streamlit as st
import pandas as pd
import numpy as np
import os
import pickle
import warnings
st.beta_set_page_config(page_title="Crop Recommender", page_icon="🌿", layout='centered', initial_sidebar_state="collapsed")
def load_model(modelfile):
loaded_model = pickle.load(open(modelfile, 'rb'))
return loaded_model
def main():
# title
html_temp = """
<div>
<h1 style="color:MEDIUMSEAGREEN;text-align:left;"> Crop Recommendation 🌱 </h1>
</div>
"""
st.markdown(html_temp, unsafe_allow_html=True)
col1,col2 = st.beta_columns([2,2])
with col1:
with st.beta_expander(" ℹ️ Information", expanded=True):
st.write("""
Crop recommendation is one of the most important aspects of precision agriculture. Crop recommendations are based on a number of factors. Precision agriculture seeks to define these criteria on a site-by-site basis in order to address crop selection issues. While the "site-specific" methodology has improved performance, there is still a need to monitor the systems' outcomes.Precision agriculture systems aren't all created equal.
However, in agriculture, it is critical that the recommendations made are correct and precise, as errors can result in significant material and capital loss.
""")
'''
## How does it work ❓
Complete all the parameters and the machine learning model will predict the most suitable crops to grow in a particular farm based on various parameters
'''
with col2:
st.subheader(" Find out the most suitable crop to grow in your farm 👨🌾")
N = st.number_input("Nitrogen", 1,10000)
P = st.number_input("Phosporus", 1,10000)
K = st.number_input("Potassium", 1,10000)
temp = st.number_input("Temperature",0.0,100000.0)
humidity = st.number_input("Humidity in %", 0.0,100000.0)
ph = st.number_input("Ph", 0.0,100000.0)
rainfall = st.number_input("Rainfall in mm",0.0,100000.0)
feature_list = [N, P, K, temp, humidity, ph, rainfall]
single_pred = np.array(feature_list).reshape(1,-1)
if st.button('Predict'):
loaded_model = load_model('model.pkl')
prediction = loaded_model.predict(single_pred)
col1.write('''
## Results 🔍
''')
col1.success(f"{prediction.item().title()} are recommended by the A.I for your farm.")
#code for html ☘️ 🌾 🌳 👨🌾 🍃
st.warning("Note: This A.I application is for educational/demo purposes only and cannot be relied upon. Check the source code [here](https://github.com/gabbygab1233/Crop-Recommendation)")
hide_menu_style = """
<style>
#MainMenu {visibility: hidden;}
</style>
"""
hide_menu_style = """
<style>
#MainMenu {visibility: hidden;}
</style>
"""
st.markdown(hide_menu_style, unsafe_allow_html=True)
if __name__ == '__main__':
main()