Prajwal3009 commited on
Commit
1f42382
·
verified ·
1 Parent(s): 9a280f0

Upload 4 files

Browse files
Crop_Insurance_Risk.py ADDED
@@ -0,0 +1,307 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import pydeck as pdk
4
+ import pickle
5
+ import time
6
+ import sum_insurance as insu
7
+ import gross_premimum as gross
8
+ import numpy as np
9
+
10
+ def sum_insurance_prediction(input_data,crop_insurance_sum_Raghu):
11
+ input_data_asarray = np.asarray(input_data)
12
+ input_data_reshaped = input_data_asarray.reshape(1,-1)
13
+ prediction = crop_insurance_sum_Raghu.predict(input_data_reshaped)
14
+ return prediction
15
+
16
+ def crop_grosspremimum_pred(input_data,crop_insurance_sum_Raghu):
17
+ input_data_asarray = np.asarray(input_data)
18
+ input_data_reshaped = input_data_asarray.reshape(1,-1)
19
+ prediction = crop_insurance_sum_Raghu.predict(input_data_reshaped)
20
+ return prediction
21
+
22
+ def insurance_app():
23
+ tab1, tab2,tab3 = st.tabs(["Maximum amount an insurance pay for a covered loss.","Total Amount insurance Paid by company in given period.","Feedback"])
24
+ with tab1:
25
+ st.title('Predict Insurance Payout on loss')
26
+ background_image = 'https://img.freepik.com/premium-photo/photo-coins-plant-black-background-with-empty-space-text-design-elements_176841-5042.jpg'
27
+ html_code = f"""
28
+ <style>
29
+ body {{
30
+ background-image: url('{background_image}');
31
+ background-size: cover;
32
+ background-position: center;
33
+ background-repeat: no-repeat;
34
+ height: 100vh; /* Set the height of the background to fill the viewport */
35
+ margin: 0; /* Remove default body margin */
36
+ display: flex;
37
+ flex-direction: column;
38
+ justify-content: center;
39
+ align-items: center;
40
+ }}
41
+ .stApp {{
42
+ background: none; /* Remove Streamlit app background */
43
+ }}
44
+ </style>
45
+ """
46
+ st.markdown(html_code, unsafe_allow_html=True)
47
+ # season,scheme,state_name,district_name,area_insured,sum_insured,farmer_share,goi_share,state_share,iu_count
48
+ # kharif,PMFBY,Andhra Pradesh,Anantapur,17.44,9493.41,453.87,285.46,285.46,85
49
+ @st.cache_resource
50
+ def load():
51
+ return pickle.load(open('crop_insurance_sum_Raghu.pkl','rb'))
52
+ crop_insurance_sum_Raghu = load()
53
+ # st.subheader('Enter Input Values')
54
+ col1,col2 = st.columns([1,1])
55
+ with col1:
56
+ season1 = st.selectbox('Season', ('kharif', 'rabi'),key=1)
57
+ with col1:
58
+ scheme1 = st.selectbox('Scheme', ('PMFBY', 'WBCIS'),key=2)
59
+ with col1:
60
+ state_name1 = st.selectbox('State Name',('Assam' ,'Chhattisgarh', 'Goa' ,'Haryana',
61
+ 'Himachal Pradesh', 'Karnataka', 'Kerala' ,'Madhya Pradesh' ,'Maharashtra',
62
+ 'Meghalaya', 'Odisha', 'Puducherry', 'Rajasthan', 'Sikkim', 'Tamil Nadu',
63
+ 'Tripura', 'Uttar Pradesh', 'Uttarakhand'),key=3)
64
+ with col1:
65
+ district_names = ('Anantapur', 'Chittoor', 'East Godavari', 'Guntur', 'Krishna',
66
+ 'Kurnool', 'Prakasam','Srikakulam', 'Vizianagaram',
67
+ 'West Godavari', 'Baksa', 'Barpeta', 'Bongaigaon', 'Cachar',
68
+ 'Chirang', 'Darrang', 'Dhemaji', 'Dhubri', 'Dibrugarh', 'Goalpara',
69
+ 'Golaghat', 'Hailakandi', 'Jorhat', 'Kamrup', 'Karbi Anglong',
70
+ 'Karimganj', 'Lakhimpur', 'Nagaon', 'Nalbari', 'Sivasagar',
71
+ 'Sonitpur', 'Tinsukia', 'Udalguri', 'Balod', 'Baloda Bazar',
72
+ 'Balrampur', 'Bastar', 'Bemetara', 'Bijapur', 'Bilaspur',
73
+ 'Dhamtari', 'Durg', 'Gariyaband', 'Janjgir-champa', 'Jashpur',
74
+ 'Kondagaon', 'Korba', 'Mahasamund', 'Mungeli', 'Narayanpur',
75
+ 'Raigarh', 'Raipur', 'Rajnandgaon', 'Sukma', 'Surajpur', 'Surguja',
76
+ 'North Goa', 'South Goa', 'Banas Kantha', 'Patan', 'Ambala',
77
+ 'Bhiwani', 'Faridabad', 'Fatehabad', 'Hisar', 'Jhajjar', 'Jind',
78
+ 'Kaithal', 'Karnal', 'Kurukshetra', 'Mahendragarh', 'Palwal',
79
+ 'Panchkula', 'Panipat', 'Rewari', 'Rohtak', 'Sirsa', 'Sonipat',
80
+ 'Yamunanagar', 'Chamba', 'Hamirpur', 'Kangra', 'Kullu', 'Mandi',
81
+ 'Shimla', 'Sirmaur', 'Solan', 'Una', 'Doda', 'Jammu', 'Kathua',
82
+ 'Kishtwar', 'Rajouri', 'Ramban', 'Reasi', 'Samba', 'Udhampur',
83
+ 'Bokaro', 'Chatra', 'Deoghar', 'Dhanbad', 'Dumka', 'Garhwa',
84
+ 'Giridih', 'Godda', 'Gumla', 'Hazaribagh', 'Jamtara', 'Khunti',
85
+ 'Latehar', 'Lohardaga', 'Pakur', 'Palamu', 'Ramgarh', 'Ranchi',
86
+ 'Simdega', 'Ballari', 'Belagavi', 'Bengaluru Rural',
87
+ 'Bengaluru Urban', 'Bidar', 'Chikkamagaluru', 'Chitradurga',
88
+ 'Dakshina Kannada', 'Davangere', 'Dharwad', 'Gadag', 'Haveri',
89
+ 'Kodagu', 'Kolar', 'Koppal', 'Mandya', 'Mysuru', 'Raichur',
90
+ 'Ramanagara', 'Shivamogga', 'Tumakuru', 'Udupi', 'Vijayapura',
91
+ 'Alappuzha', 'Ernakulam', 'Idukki', 'Kannur', 'Kasaragod',
92
+ 'Kollam', 'Kottayam', 'Kozhikode', 'Malappuram', 'Palakkad',
93
+ 'Pathanamthitta', 'Thiruvananthapuram', 'Thrissur', 'Wayanad',
94
+ 'Agar Malwa', 'Alirajpur', 'Anuppur', 'Ashoknagar', 'Balaghat',
95
+ 'Barwani', 'Betul', 'Bhind', 'Bhopal', 'Burhanpur', 'Chhatarpur',
96
+ 'Chhindwara', 'Damoh', 'Datia', 'Dewas', 'Dhar', 'Dindori', 'Guna',
97
+ 'Gwalior', 'Harda', 'Indore', 'Jabalpur', 'Jhabua', 'Katni',
98
+ 'Mandla', 'Mandsaur', 'Morena', 'Neemuch', 'Panna', 'Raisen',
99
+ 'Rajgarh', 'Ratlam', 'Rewa', 'Sagar', 'Satna', 'Sehore', 'Seoni',
100
+ 'Shahdol', 'Shajapur', 'Sheopur', 'Shivpuri', 'Sidhi', 'Singrauli',
101
+ 'Tikamgarh', 'Ujjain', 'Umaria', 'Vidisha', 'Akola', 'Amravati',
102
+ 'Aurangabad', 'Bhandara', 'Chandrapur', 'Dhule', 'Gadchiroli',
103
+ 'Hingoli', 'Jalgaon', 'Jalna', 'Kolhapur', 'Latur', 'Nagpur',
104
+ 'Nanded', 'Nandurbar', 'Nashik', 'Osmanabad', 'Palghar',
105
+ 'Parbhani', 'Pune', 'Ratnagiri', 'Sangli', 'Satara', 'Sindhudurg',
106
+ 'Solapur', 'Thane', 'Wardha', 'Washim', 'Yavatmal', 'Anugul',
107
+ 'Balangir', 'Baleshwar', 'Bargarh', 'Bhadrak', 'Cuttack',
108
+ 'Dhenkanal', 'Gajapati', 'Ganjam', 'Jagatsinghapur', 'Jajapur',
109
+ 'Jharsuguda', 'Kalahandi', 'Kandhamal', 'Kendrapara', 'Kendujhar',
110
+ 'Khordha', 'Koraput', 'Malkangiri', 'Mayurbhanj', 'Nayagarh',
111
+ 'Nuapada', 'Puri', 'Rayagada', 'Sambalpur', 'Sundargarh', 'Ajmer',
112
+ 'Alwar', 'Banswara', 'Baran', 'Barmer', 'Bharatpur', 'Bhilwara',
113
+ 'Bikaner', 'Bundi', 'Churu', 'Dausa', 'Dungarpur', 'Hanumangarh',
114
+ 'Jaipur', 'Jaisalmer', 'Jhalawar', 'Jhunjhunu', 'Jodhpur',
115
+ 'Karauli', 'Kota', 'Nagaur', 'Pali', 'Pratapgarh', 'Rajsamand',
116
+ 'Sawai Madhopur', 'Sikar', 'Sirohi', 'Tonk', 'Udaipur', 'Ariyalur',
117
+ 'Coimbatore', 'Cuddalore', 'Dharmapuri', 'Dindigul', 'Erode',
118
+ 'Kanniyakumari', 'Karur', 'Krishnagiri', 'Madurai', 'Nagapattinam',
119
+ 'Namakkal', 'Perambalur', 'Pudukkottai', 'Salem', 'Sivaganga',
120
+ 'Thanjavur', 'The Nilgiris', 'Theni', 'Thiruvallur', 'Thiruvarur',
121
+ 'Tiruchirappalli', 'Tirunelveli', 'Tiruppur', 'Tiruvannamalai',
122
+ 'Vellore', 'Virudhunagar', 'Adilabad', 'Kamareddy', 'Karimnagar',
123
+ 'Khammam', 'Mahabubabad', 'Mancherial', 'Medak', 'Nagarkurnool',
124
+ 'Nalgonda', 'Nirmal', 'Nizamabad', 'Peddapalli', 'Ranga Reddy',
125
+ 'Sangareddy', 'Siddipet', 'Suryapet', 'Vikarabad', 'Wanaparthy',
126
+ 'Agra', 'Aligarh', 'Ambedkar Nagar', 'Amethi', 'Amroha', 'Auraiya',
127
+ 'Azamgarh', 'Baghpat', 'Bahraich', 'Ballia', 'Banda', 'Barabanki',
128
+ 'Bareilly', 'Basti', 'Bhadohi', 'Bijnor', 'Budaun', 'Bulandshahr',
129
+ 'Chandauli', 'Chitrakoot', 'Deoria', 'Etah', 'Etawah',
130
+ 'Farrukhabad', 'Fatehpur', 'Firozabad', 'Gautam Buddha Nagar',
131
+ 'Ghaziabad', 'Ghazipur', 'Gonda', 'Gorakhpur', 'Hapur', 'Hardoi',
132
+ 'Hathras', 'Jalaun', 'Jaunpur', 'Jhansi', 'Kannauj',
133
+ 'Kanpur Dehat', 'Kanpur Nagar', 'Kasganj', 'Kaushambi', 'Kheri',
134
+ 'Kushi Nagar', 'Lalitpur', 'Lucknow', 'Mahoba', 'Mainpuri',
135
+ 'Mathura', 'Mau', 'Meerut', 'Mirzapur', 'Moradabad',
136
+ 'Muzaffarnagar', 'Pilibhit', 'Rae Bareli', 'Rampur', 'Saharanpur',
137
+ 'Sambhal', 'Shahjahanpur', 'Shamli', 'Siddharth Nagar', 'Sitapur',
138
+ 'Sonbhadra', 'Sultanpur', 'Unnao', 'Varanasi', 'Almora',
139
+ 'Bageshwar', 'Chamoli', 'Champawat', 'Dehradun', 'Nainital',
140
+ 'Pithoragarh', 'Rudra Prayag', 'Tehri Garhwal', 'Uttar Kashi',
141
+ 'Alipurduar', 'Bankura', 'Birbhum', 'Jalpaiguri', 'Jhargram',
142
+ 'Kalimpong', 'Maldah', 'Murshidabad', 'Nadia', 'Paschim Bardhaman',
143
+ 'Purba Bardhaman', 'Kokrajhar', 'Arvalli', 'Bharuch', 'Bhavnagar',
144
+ 'Gandhinagar', 'Kheda', 'Mahesana', 'Panch Mahals', 'Porbandar',
145
+ 'Surendranagar', 'Kinnaur', 'Karaikal', 'Ramanathapuram', 'Dhalai',
146
+ 'Gomati', 'Khowai', 'North Tripura', 'Sepahijala', 'Unakoti',
147
+ 'West Tripura', 'Dima Hasao', 'Ahmadabad', 'Niwari', 'Bishnupur',
148
+ 'Chandel', 'Churachandpur', 'Imphal East', 'Imphal West',
149
+ 'Senapati', 'Thoubal', 'East Khasi Hills', 'North Garo Hills',
150
+ 'Ri Bhoi', 'South West Garo Hills', 'West Garo Hills',
151
+ 'West Khasi Hills', 'Mulugu', 'Narayanpet', 'South Tripura',
152
+ 'West Jaintia Hills', 'Chengalpattu', 'Kallakurichi', 'Ranipet',
153
+ 'Tenkasi', 'Tirupathur', 'Anantnag', 'Biswanath', 'Hojai',
154
+ 'Kamrup Metro', 'Majuli', 'Marigaon', 'South Salmara Mancachar',
155
+ 'West Karbi Anglong', 'Ukhrul', 'Mayiladuthurai',
156
+ 'Alluri Sitharama Raju', 'Anakapalli', 'Annamayya', 'Bapatla',
157
+ 'Eluru', 'Kakinada', 'Nandyal', 'Ntr', 'Palnadu',
158
+ 'Parvathipuram Manyam', 'Spsr Nellore', 'Sri Sathya Sai',
159
+ 'Tirupati', 'Visakhapatanam', 'Bajali', 'Charaideo', 'Dantewada',
160
+ 'Gaurella Pendra Marwahi', 'Kabirdham', 'Kanker', 'Korea',
161
+ 'Gurugram', 'Nuh', 'Lahul And Spiti', 'East Nimar', 'Khargone',
162
+ 'Narsinghpur', 'Ahmednagar', 'Beed', 'Buldhana', 'Gondia',
163
+ 'Raigad', 'Tamenglong', 'South Garo Hills', 'Boudh', 'Deogarh',
164
+ 'Nabarangpur', 'Sonepur', 'Pondicherry', 'Chittorgarh', 'Dholpur',
165
+ 'Jalore', 'Gangtok', 'Gyalshing', 'Namchi', 'Ayodhya',
166
+ 'Maharajganj', 'Prayagraj', 'Shravasti', 'Haridwar',
167
+ 'Pauri Garhwal', 'Kanchipuram', 'Tuticorin', 'Villupuram')
168
+ district_name1 = st.selectbox('District Name',district_names,key=4)
169
+ with col2:
170
+ area_insured1 = st.number_input('Total Area Covered for Insurence', value=17.44,min_value=1.0,max_value=3777.0,step=1.0,key=5)
171
+ with col2:
172
+ farmer_share1 = st.number_input('Premium Paid by Individual', value=453.87,min_value=1.0,max_value=8600.32,step=10.0,key=6)
173
+ with col2:
174
+ goi_share1 = st.number_input('Premium Paid by GOI', value=285.46,min_value=1.0,max_value=33292.16,step=10.0,key=7)
175
+ with col2:
176
+ state_share1 = st.number_input('Premium Paid by Govt', value=285.46,min_value=1.0,max_value=40723.02,step=10.0,key=8)
177
+ with col1:
178
+ iu_count1 = st.number_input('Count of Insurence Units', value=85.0,min_value=1.0,max_value=2492.00,step=5.0,key=9)
179
+
180
+
181
+ prediction1 = ''
182
+ input_data = [season1,scheme1,state_name1,district_name1,area_insured1,farmer_share1,goi_share1,state_share1,iu_count1]
183
+ if st.button('Predict'):
184
+ encode = insu.encoding(input_data)
185
+ try:
186
+ prediction1 = sum_insurance_prediction(encode,crop_insurance_sum_Raghu)
187
+ progress = st.progress(0)
188
+ for i in range(100):
189
+ time.sleep(0.005)
190
+ progress.progress(i+1)
191
+ st.subheader(f"Sum Insured: {round(prediction1[0],3)} Rupees")
192
+ except:
193
+ st.error("Invalid Inputs")
194
+
195
+
196
+
197
+
198
+ with tab2:
199
+ st.title('Gross Premium')
200
+ # background_image = 'https://img.freepik.com/premium-photo/photo-coins-plant-black-background-with-empty-space-text-design-elements_176841-5042.jpg'
201
+ # html_code = f"""
202
+ # <style>
203
+ # body {{
204
+ # background-image: url('{background_image}');
205
+ # background-size: cover;
206
+ # background-position: center;
207
+ # background-repeat: no-repeat;
208
+ # height: 100vh; /* Set the height of the background to fill the viewport */
209
+ # margin: 0; /* Remove default body margin */
210
+ # display: flex;
211
+ # flex-direction: column;
212
+ # justify-content: center;
213
+ # align-items: center;
214
+ # }}
215
+ # .stApp {{
216
+ # background: none; /* Remove Streamlit app background */
217
+ # }}
218
+ # </style>
219
+ # """
220
+ # st.markdown(html_code, unsafe_allow_html=True)
221
+
222
+ # season,scheme,state_name,district_name,area_insured,sum_insured,farmer_share,goi_share,state_share,iu_count,gross_premium
223
+ # kharif,PMFBY,Andhra Pradesh,Anantapur,17.44,9493.41,453.87,285.46,285.46,85,1024.79
224
+ def loada():
225
+ return pickle.load(open('crop_grosspremimum_Jp.pkl','rb'))
226
+ crop_grosspremimum = loada()
227
+ # st.subheader('Enter Input Values')
228
+ col1,col2 = st.columns([1,1])
229
+ with col1:
230
+ season = st.selectbox('Season', ('kharif', 'rabi'))
231
+ with col1:
232
+ scheme = st.selectbox('Scheme', ('PMFBY', 'WBCIS'))
233
+ with col1:
234
+ state_name = st.selectbox('State Name',('Assam' ,'Chhattisgarh', 'Goa' ,'Haryana',
235
+ 'Himachal Pradesh', 'Karnataka', 'Kerala' ,'Madhya Pradesh' ,'Maharashtra',
236
+ 'Meghalaya', 'Odisha', 'Puducherry', 'Rajasthan', 'Sikkim', 'Tamil Nadu',
237
+ 'Tripura', 'Uttar Pradesh', 'Uttarakhand'))
238
+ with col1:
239
+ district_name = st.selectbox('District Name', district_names,key = 34)
240
+ with col2:
241
+ area_insured = st.number_input('Total Area Covered for Insurence', value=17.44,min_value=1.0,max_value=3777.0,step=1.0)
242
+ with col2:
243
+ farmer_share = st.number_input('Premium Paid by Individual', value=453.87,min_value=1.0,max_value=8600.32,step=10.0)
244
+ with col2:
245
+ goi_share = st.number_input('Premium Paid by GOI', value=285.46,min_value=1.0,max_value=33292.15,step=10.0)
246
+ with col2:
247
+ state_share = st.number_input('Premium Paid by Govt', value=285.46,min_value=1.0,max_value=40723.02,step=10.0)
248
+ with col1:
249
+ iu_count = st.number_input('Count of Insurence Units', value=85.0,min_value=1.0,max_value=2492.00,step=5.0)
250
+ with col2:
251
+ sum_insured = st.number_input('YOur Sum Insured For The Crop', value=9493.41,min_value=1.0,max_value=535572.47,step=50.0)
252
+
253
+ prediction = ''
254
+ input_data = [season,scheme,state_name,district_name,area_insured,sum_insured,farmer_share,goi_share,state_share,iu_count]
255
+ if st.button('Predict',key=10):
256
+ encode = gross.encoding(input_data)
257
+ try:
258
+ prediction = crop_grosspremimum_pred(encode,crop_grosspremimum)
259
+ progress = st.progress(0)
260
+ for i in range(100):
261
+ time.sleep(0.005)
262
+ progress.progress(i+1)
263
+ st.subheader(f"gross premium: {round(prediction[0],3)} Rupees ")
264
+ except:
265
+ st.error("Invalid Inputs")
266
+
267
+ with tab3:
268
+ df = pd.read_csv('insurance.csv')
269
+ st.write('Current Dataset',df)
270
+ col1,col2 = st.columns(2)
271
+ with col1:
272
+ season = st.selectbox('Season', ('kharif', 'rabi'),key = 101)
273
+ with col1:
274
+ scheme = st.selectbox('Scheme', ('PMFBY', 'WBCIS'),key = 102)
275
+ with col1:
276
+ state_name = st.selectbox('State Name',('Assam' ,'Chhattisgarh', 'Goa' ,'Haryana',
277
+ 'Himachal Pradesh', 'Karnataka', 'Kerala' ,'Madhya Pradesh' ,'Maharashtra',
278
+ 'Meghalaya', 'Odisha', 'Puducherry', 'Rajasthan', 'Sikkim', 'Tamil Nadu',
279
+ 'Tripura', 'Uttar Pradesh', 'Uttarakhand'),key = 103)
280
+ with col1:
281
+ district_name = st.selectbox('District Name', district_names,key =104)
282
+ with col2:
283
+ area_insured = st.number_input('Total Area Covered for Insurence', value=17.44,min_value=1.0,max_value=3777.0,step=1.0,key = 105)
284
+ with col2:
285
+ farmer_share = st.number_input('Premium Paid by Individual', value=453.87,min_value=1.0,max_value=8600.32,step=10.0,key = 106)
286
+ with col2:
287
+ goi_share = st.number_input('Premium Paid by GOI', value=285.46,min_value=1.0,max_value=33292.15,step=10.0,key = 1062)
288
+ with col2:
289
+ state_share = st.number_input('Premium Paid by Govt', value=285.46,min_value=1.0,max_value=40723.02,step=10.0,key = 107)
290
+ with col1:
291
+ iu_count = st.number_input('Count of Insurence Units', value=85.0,min_value=1.0,max_value=2492.00,step=5.0,key = 108)
292
+ with col2:
293
+ sum_insured = st.number_input('YOur Sum Insured For The Crop', value=9493.41,min_value=1.0,max_value=535572.47,step=50.0,key = 109)
294
+ with col1:
295
+ gross_premium = st.number_input('Enter the amount after policy mature', value=2255.6,min_value=0.0,max_value=80103.4,step=5.0,key = 110)
296
+
297
+ if st.button('submit',key = 10111):
298
+ new_row = {'season':season, 'scheme':scheme, 'state_name':state_name, 'district_name':district_name, 'area_insured':area_insured,
299
+ 'sum_insured':sum_insured, 'farmer_share':farmer_share, 'goi_share':goi_share, 'state_share':state_share, 'iu_count':iu_count,
300
+ 'gross_premium':gross_premium}
301
+ df = df.append(new_row,ignore_index= True)
302
+ df.to_csv('insurance.csv')
303
+ st.success("Thanks for the feedback")
304
+ st.write("Updated Dataset",df)
305
+
306
+ if __name__=='__main__':
307
+ insurance_app()
Crop_disease_prediction.py ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import matplotlib.pyplot as plt
3
+ import tensorflow as tf
4
+ from tensorflow.keras.models import load_model
5
+
6
+ # Load the saved model from Google Drive
7
+ @st.cache_resource
8
+ def loadu():
9
+ reso = load_model("model.h5")
10
+ return reso
11
+ loaded_model = loadu()
12
+ class_names = ['Apple___Apple_scab', 'Apple___Black_rot', 'Apple___Cedar_apple_rust', 'Apple___healthy',
13
+ 'Blueberry___healthy', 'Cherry_(including_sour)___Powdery_mildew',
14
+ 'Cherry_(including_sour)___healthy', 'Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot',
15
+ 'Corn_(maize)___Common_rust_', 'Corn_(maize)___Northern_Leaf_Blight', 'Corn_(maize)___healthy',
16
+ 'Grape___Black_rot', 'Grape___Esca_(Black_Measles)', 'Grape___Leaf_blight_(Isariopsis_Leaf_Spot)',
17
+ 'Grape___healthy', 'Orange___Haunglongbing_(Citrus_greening)', 'Peach___Bacterial_spot',
18
+ 'Peach___healthy', 'Pepper,_bell___Bacterial_spot', 'Pepper,_bell___healthy', 'Potato___Early_blight',
19
+ 'Potato___Late_blight', 'Potato___healthy', 'Raspberry___healthy', 'Soybean___healthy',
20
+ 'Squash___Powdery_mildew', 'Strawberry___Leaf_scorch', 'Strawberry___healthy',
21
+ 'Tomato___Bacterial_spot', 'Tomato___Early_blight', 'Tomato___Late_blight', 'Tomato___Leaf_Mold',
22
+ 'Tomato___Septoria_leaf_spot', 'Tomato___Spider_mites Two-spotted_spider_mite', 'Tomato___Target_Spot',
23
+ 'Tomato___Tomato_Yellow_Leaf_Curl_Virus', 'Tomato___Tomato_mosaic_virus', 'Tomato___healthy']
24
+
25
+ crop_medicines = {
26
+ 'Apple___Apple_scab': ['Fungicides (e.g., sulfur or copper-based products)', 'Sanitation practices'],
27
+ 'Apple___Black_rot': ['Fungicides', 'Proper sanitation practices'],
28
+ 'Apple___Cedar_apple_rust': ['Fungicides', 'Removal of infected juniper plants'],
29
+ 'Apple___healthy': ['No specific treatment'],
30
+
31
+ 'Blueberry___healthy': ['Well-drained soil', 'Proper irrigation'],
32
+
33
+ 'Cherry_(including_sour)___Powdery_mildew': ['Fungicides', 'Pruning for air circulation', 'Proper sanitation'],
34
+ 'Cherry_(including_sour)___healthy': ['No specific treatment'],
35
+
36
+ 'Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot': ['Fungicides', 'Crop rotation'],
37
+ 'Corn_(maize)___Common_rust_': ['Fungicides', 'Resistant varieties'],
38
+ 'Corn_(maize)___Northern_Leaf_Blight': ['Fungicides', 'Crop rotation'],
39
+ 'Corn_(maize)___healthy': ['No specific treatment'],
40
+
41
+ 'Grape___Black_rot': ['Fungicides', 'Proper pruning'],
42
+ 'Grape___Esca_(Black_Measles)': ['Pruning', 'Cultural practices'],
43
+ 'Grape___Leaf_blight_(Isariopsis_Leaf_Spot)': ['Fungicides', 'Proper canopy management'],
44
+ 'Grape___healthy': ['No specific treatment'],
45
+
46
+ 'Orange___Haunglongbing_(Citrus_greening)': ['Vector control', 'Removing infected trees'],
47
+
48
+ 'Peach___Bacterial_spot': ['Copper-based fungicides', 'Proper sanitation'],
49
+ 'Peach___healthy': ['No specific treatment'],
50
+
51
+ 'Pepper,_bell___Bacterial_spot': ['Copper-based fungicides', 'Resistant varieties'],
52
+ 'Pepper,_bell___healthy': ['No specific treatment'],
53
+
54
+ 'Potato___Early_blight': ['Fungicides', 'Crop rotation', 'Proper field hygiene'],
55
+ 'Potato___Late_blight': ['Fungicides', 'Resistant varieties', 'Proper plant spacing'],
56
+ 'Potato___healthy': ['No specific treatment'],
57
+
58
+ 'Raspberry___healthy': ['Well-drained soil', 'Proper pruning'],
59
+
60
+ 'Soybean___healthy': ['Proper crop rotation'],
61
+
62
+ 'Squash___Powdery_mildew': ['Fungicides', 'Proper spacing for air circulation'],
63
+
64
+ 'Strawberry___Leaf_scorch': ['Fungicides', 'Proper irrigation'],
65
+ 'Strawberry___healthy': ['No specific treatment'],
66
+
67
+ 'Tomato___Bacterial_spot': ['Copper-based fungicides', 'Resistant varieties'],
68
+ 'Tomato___Early_blight': ['Fungicides', 'Resistant varieties', 'Proper plant spacing'],
69
+ 'Tomato___Late_blight': ['Fungicides', 'Resistant varieties', 'Proper plant spacing'],
70
+ 'Tomato___Leaf_Mold': ['Fungicides', 'Proper ventilation'],
71
+ 'Tomato___Septoria_leaf_spot': ['Fungicides', 'Proper plant spacing'],
72
+ 'Tomato___Spider_mites Two-spotted_spider_mite': ['Miticides', 'Biological control'],
73
+ 'Tomato___Target_Spot': ['Fungicides', 'Proper plant hygiene'],
74
+ 'Tomato___Tomato_Yellow_Leaf_Curl_Virus': ['Vector control', 'Resistant varieties'],
75
+ 'Tomato___Tomato_mosaic_virus': ['Resistant varieties', 'Vector control'],
76
+ 'Tomato___healthy': ['No specific treatment']
77
+ }
78
+
79
+
80
+ IMAGE_SIZE = (224, 224)
81
+
82
+ def load_and_preprocess_image(image_path):
83
+ try:
84
+ img = tf.io.read_file(image_path)
85
+ img = tf.image.decode_image(img)
86
+ img = tf.image.resize(img, size=IMAGE_SIZE)
87
+ return img
88
+ except Exception as e:
89
+ st.error(f"Error loading or preprocessing image: {e}")
90
+ return None
91
+
92
+ # def disease_predict(image_path):
93
+ # image = load_and_preprocess_image(image_path)
94
+
95
+ # if image is not None:
96
+ # try:
97
+ # pred = loaded_model.predict(tf.expand_dims(image, axis=0))
98
+ # predicted_value = class_names[pred.argmax()]
99
+ # display_prediction(predicted_value, image)
100
+ # except Exception as e:
101
+ # st.error(f"Error predicting disease: {e}")
102
+
103
+ def disease_predict(image_path):
104
+ image = load_and_preprocess_image(image_path)
105
+
106
+ if image is not None:
107
+ try:
108
+ pred = loaded_model.predict(tf.expand_dims(image, axis=0))
109
+ if max(pred[0]) >= 0.90:
110
+ predicted_value = class_names[pred.argmax()]
111
+ display_prediction(predicted_value, image)
112
+ else:
113
+ st.error("Invalid Image")
114
+ except Exception as e:
115
+ st.error(f"Error predicting disease: {e}")
116
+
117
+ def display_prediction(predicted_value, image):
118
+ st.image(image.numpy() / 255., caption=f"Predicted Disease: {predicted_value}", use_column_width=True)
119
+ st.success(f"Disease: **{predicted_value }**")
120
+ treatment(predicted_value)
121
+ # st.write(f"Image Shape: {image.shape}")
122
+
123
+ def treatment(predicted_value):
124
+ medicines = crop_medicines.get(predicted_value, [])
125
+ st.subheader("Solution for this Disease:")
126
+ st.write("Medicines:")
127
+ for medicine in medicines:
128
+ st.write(f"- {medicine}")
129
+
130
+ def disease_app():
131
+ st.title('Agricultural Disease Detector 🦠')
132
+ uploaded_file = st.file_uploader("Upload an Image for Disease Analysis", type="jpg")
133
+ if uploaded_file is None:
134
+ uploaded_file = st.camera_input("Capture a photo")
135
+ if uploaded_file is not None:
136
+ img_path = f"uploaded_image.jpg"
137
+ with open(img_path, "wb") as f:
138
+ f.write(uploaded_file.read())
139
+ disease_predict(img_path)
140
+
141
+ # if __name__ == "__main__":
142
+
crop_grosspremimum_Jp.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bfc136c4d837b3425ddbcd14b7010e1f6eebb7b6838efb92a0aa172455b5fb16
3
+ size 778
crop_insurance_sum_Raghu.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:668518f12d1300fd92188941af6ec087b1c5b3db51ed3e851436fb98c9770236
3
+ size 123777233