Update app.py
Browse files
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/
|
| 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 |
-
|
| 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 |
|