navjotk commited on
Commit
09e3794
·
verified ·
1 Parent(s): a2e34d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -35
app.py CHANGED
@@ -5,31 +5,31 @@ from sklearn.model_selection import train_test_split
5
  from sklearn.preprocessing import LabelEncoder
6
 
7
  # Load dataset
8
- url = "https://raw.githubusercontent.com/sehajpreet22/data/refs/heads/main/cleaned_crop_data_with_pbi_labels.csv"
9
  data = pd.read_csv(url)
10
 
11
  # Define the crops in Punjabi
12
  crops = [
13
- 'ਚੌਲ',
14
- 'ਮੱਕੀ',
15
- 'ਛੋਲੇ',
16
- 'ਰਾਜ਼ਮਾ',
17
- 'ਅਰਹਰ ਦੀ ਦਾਲ',
18
- 'ਮੋਠ ਦੀ ਦਾਲ',
19
- 'ਮੂੰਗ ਦੀ ਦਾਲ',
20
- 'ਮਾਂਹ ਦੀ ਦਾਲ',
21
- 'ਮਸਰ ਦੀ ਦਾਲ',
22
- 'ਅਨਾਰ',
23
- 'ਕੇਲਾ',
24
- 'ਅੰਬ',
25
- 'ਤਰਬੂਜ਼',
26
- 'ਖਰਬੂਜ਼ਾ',
27
- 'ਸੰਤਰਾ',
28
- 'ਪਪੀਤਾ',
29
- 'ਨਾਰੀਅਲ',
30
- 'ਕਪਾਹ',
31
- 'ਜੂਟ',
32
- 'ਕੌਫ਼ੀ'
33
  ]
34
 
35
  # Fit the label encoder
@@ -39,15 +39,8 @@ data['crop_encoded'] = le.transform(data['label']) # ✅ Then transform
39
 
40
  # Prepare for reverse prediction
41
  reverse_X = data[['crop_encoded']]
42
- y_cols = [
43
- 'ਨਾਈਟ੍ਰੋਜਨ (kg/ha)',
44
- 'ਫਾਸਫੋਰਸ (kg/ha)',
45
- 'ਪੋਟਾਸ਼ੀਅਮ (kg/ha)',
46
- 'ਤਾਪਮਾਨ (°C)',
47
- 'ਨਮੀ (%)',
48
- 'ਮਿੱਟੀ ਦਾ pH',
49
- 'ਵਰਖਾ (mm)'
50
- ]
51
 
52
  # Train reverse models
53
  reverse_models = {}
@@ -65,7 +58,7 @@ label_to_encoded = {label: le.transform([label])[0] for label in le.classes_}
65
  def predict_crop_parameters(crop_name):
66
  crop_name = crop_name.strip()
67
  if crop_name not in label_to_encoded:
68
- return f"❌ '<b>{crop_name}</b>' ਲਈ ਡਾਟਾ ਨਹੀਂ ਮਿਲਿਆ।"
69
 
70
  encoded_value = label_to_encoded[crop_name]
71
  input_data = [[encoded_value]]
@@ -84,10 +77,10 @@ def predict_crop_parameters(crop_name):
84
 
85
 
86
  with gr.Blocks() as demo:
87
- gr.Markdown("# 🌾 **AgroVision: ਫਸਲ ਤੋਂ ਪੈਰਾਮੀਟਰ**")
88
- crop_input = gr.Dropdown(choices=crops, label="🌿 ਫਸਲ ਦਾ ਨਾਂ ਲਿਖੋ")
89
- result_output = gr.Markdown(label="🧪 ਅਨੁਕੂਲ ਪੈਰਾਮੀਟਰ")
90
- run_btn = gr.Button("➡️ ਭਵਿੱਖਬਾਣੀ ਲਵੋ")
91
  run_btn.click(fn=predict_crop_parameters, inputs=[crop_input], outputs=[result_output])
92
 
93
 
 
5
  from sklearn.preprocessing import LabelEncoder
6
 
7
  # Load dataset
8
+ url = "https://raw.githubusercontent.com/Pushpinder-Singh06/CSV-Files/refs/heads/main/crop_cleaned%20data.csv "
9
  data = pd.read_csv(url)
10
 
11
  # Define the crops in Punjabi
12
  crops = [
13
+ 'rice',
14
+ 'maize',
15
+ 'chickpea',
16
+ 'kidneybeans',
17
+ 'pigeonpeas',
18
+ 'mothbeans',
19
+ 'mungbean',
20
+ 'blackgram',
21
+ 'lentil',
22
+ 'pomegranate',
23
+ 'banana',
24
+ 'mango',
25
+ 'watermelon',
26
+ 'muskmelon',
27
+ 'orange',
28
+ 'papaya',
29
+ 'coconut',
30
+ 'cotton',
31
+ 'jute',
32
+ 'coffee'
33
  ]
34
 
35
  # Fit the label encoder
 
39
 
40
  # Prepare for reverse prediction
41
  reverse_X = data[['crop_encoded']]
42
+ y_cols = ['N', 'P', 'K', 'temperature', 'humidity', 'ph', 'rainfall']
43
+
 
 
 
 
 
 
 
44
 
45
  # Train reverse models
46
  reverse_models = {}
 
58
  def predict_crop_parameters(crop_name):
59
  crop_name = crop_name.strip()
60
  if crop_name not in label_to_encoded:
61
+ return f"❌ No data found for '<b>{crop_name}</b>'."
62
 
63
  encoded_value = label_to_encoded[crop_name]
64
  input_data = [[encoded_value]]
 
77
 
78
 
79
  with gr.Blocks() as demo:
80
+ gr.Markdown("# 🌾 **AgroVision: Crop-Based Parameters**")
81
+ crop_input = gr.Dropdown(choices=crops, label="🌿 Select Crop Name")
82
+ result_output = gr.Markdown(label="🧪 Recommended Parameters")
83
+ run_btn = gr.Button("➡️ Predict Parameters")
84
  run_btn.click(fn=predict_crop_parameters, inputs=[crop_input], outputs=[result_output])
85
 
86