Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,30 +5,30 @@ from sklearn.model_selection import train_test_split
|
|
| 5 |
import gradio as gr
|
| 6 |
import random
|
| 7 |
|
| 8 |
-
# Generate synthetic dataset for
|
| 9 |
def generate_synthetic_dataset(num_samples=5000):
|
| 10 |
np.random.seed(42)
|
| 11 |
|
| 12 |
-
# Common crops in
|
| 13 |
crops = [
|
| 14 |
-
'Rice', '
|
| 15 |
-
'
|
| 16 |
-
'
|
| 17 |
-
'Banana', '
|
| 18 |
]
|
| 19 |
|
| 20 |
-
# Soil types common in
|
| 21 |
-
soil_types = ['
|
| 22 |
|
| 23 |
-
# Seasons in
|
| 24 |
-
seasons = ['Kharif (
|
| 25 |
|
| 26 |
# Generate synthetic data
|
| 27 |
data = {
|
| 28 |
-
'Temperature (°C)': np.random.uniform(10,
|
| 29 |
-
'Rainfall (mm)': np.random.uniform(
|
| 30 |
-
'Humidity (%)': np.random.uniform(
|
| 31 |
-
'Soil pH': np.random.uniform(
|
| 32 |
'Soil Type': np.random.choice(soil_types, num_samples),
|
| 33 |
'Nitrogen (N) Level': np.random.uniform(0, 150, num_samples),
|
| 34 |
'Phosphorus (P) Level': np.random.uniform(0, 100, num_samples),
|
|
@@ -45,52 +45,56 @@ def generate_synthetic_dataset(num_samples=5000):
|
|
| 45 |
crop = row['Crop']
|
| 46 |
|
| 47 |
# Temperature adjustments
|
| 48 |
-
if
|
| 49 |
-
df.at[idx, 'Temperature (°C)'] = np.random.uniform(25,
|
| 50 |
-
df.at[idx, 'Humidity (%)'] = np.random.uniform(
|
| 51 |
-
elif crop in ['Wheat', '
|
| 52 |
-
df.at[idx, 'Temperature (°C)'] = np.random.uniform(
|
| 53 |
-
elif crop in ['
|
| 54 |
-
df.at[idx, 'Temperature (°C)'] = np.random.uniform(20,
|
|
|
|
| 55 |
|
| 56 |
# Soil type adjustments
|
| 57 |
-
if crop in ['
|
| 58 |
-
df.at[idx, 'Soil Type'] = '
|
| 59 |
-
elif crop in ['
|
| 60 |
-
df.at[idx, 'Soil Type'] =
|
|
|
|
|
|
|
| 61 |
|
| 62 |
# Season adjustments
|
| 63 |
-
if crop in ['Rice
|
| 64 |
-
df.at[idx, 'Season'] = 'Kharif (
|
| 65 |
-
elif crop in ['Wheat', '
|
| 66 |
-
df.at[idx, 'Season'] = 'Rabi (
|
| 67 |
-
elif crop in ['
|
| 68 |
-
df.at[idx, 'Season'] = '
|
| 69 |
|
| 70 |
-
# Add profit estimates (in
|
| 71 |
profit_ranges = {
|
| 72 |
-
'Rice': (
|
| 73 |
-
'
|
| 74 |
-
'
|
| 75 |
-
'
|
| 76 |
-
'
|
| 77 |
-
'
|
| 78 |
-
'
|
| 79 |
-
'
|
| 80 |
-
'
|
| 81 |
-
'
|
| 82 |
-
'
|
| 83 |
-
'
|
| 84 |
-
'
|
| 85 |
-
'
|
| 86 |
-
'
|
| 87 |
-
'
|
| 88 |
-
'
|
| 89 |
-
'
|
| 90 |
-
'
|
|
|
|
| 91 |
}
|
| 92 |
|
| 93 |
-
df['Profit (
|
| 94 |
|
| 95 |
return df
|
| 96 |
|
|
@@ -98,7 +102,7 @@ def generate_synthetic_dataset(num_samples=5000):
|
|
| 98 |
df = generate_synthetic_dataset(10000)
|
| 99 |
|
| 100 |
# Prepare data for ML model
|
| 101 |
-
X = df.drop(['Crop', 'Profit (
|
| 102 |
X = pd.get_dummies(X) # Convert categorical variables to dummy variables
|
| 103 |
y = df['Crop']
|
| 104 |
|
|
@@ -111,47 +115,53 @@ model.fit(X_train, y_train)
|
|
| 111 |
|
| 112 |
# Crop precautions information
|
| 113 |
precautions_db = {
|
| 114 |
-
'Rice': [
|
| 115 |
-
"
|
| 116 |
-
"
|
| 117 |
-
"
|
| 118 |
-
"
|
| 119 |
],
|
| 120 |
-
'
|
| 121 |
-
"Ensure
|
| 122 |
-
"
|
| 123 |
-
"
|
| 124 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
],
|
| 126 |
-
'
|
| 127 |
-
"
|
| 128 |
-
"
|
| 129 |
-
"
|
| 130 |
-
"
|
| 131 |
],
|
| 132 |
-
'
|
| 133 |
-
"
|
| 134 |
-
"Apply
|
| 135 |
-
"Control
|
| 136 |
-
"Harvest
|
| 137 |
],
|
| 138 |
-
'
|
| 139 |
-
"
|
| 140 |
-
"
|
| 141 |
-
"
|
| 142 |
-
"
|
| 143 |
],
|
| 144 |
-
'
|
| 145 |
-
"
|
| 146 |
-
"
|
| 147 |
-
"
|
| 148 |
-
"
|
| 149 |
],
|
| 150 |
-
'
|
| 151 |
-
"
|
| 152 |
-
"
|
| 153 |
-
"
|
| 154 |
-
"Harvest
|
| 155 |
],
|
| 156 |
# Default precautions for other crops
|
| 157 |
'Default': [
|
|
@@ -170,16 +180,16 @@ def get_precautions(crop, temperature, rainfall, humidity, soil_type):
|
|
| 170 |
if temperature > 35:
|
| 171 |
precautions.append("Provide mulch to reduce soil temperature")
|
| 172 |
precautions.append("Increase irrigation frequency during hot days")
|
| 173 |
-
if rainfall
|
| 174 |
-
precautions.append("
|
| 175 |
-
if humidity >
|
| 176 |
precautions.append("Watch for fungal diseases and apply preventive sprays")
|
| 177 |
|
| 178 |
# Add soil-specific precautions
|
| 179 |
-
if soil_type == '
|
| 180 |
-
precautions.append("
|
| 181 |
-
elif soil_type == '
|
| 182 |
-
precautions.append("Apply
|
| 183 |
|
| 184 |
return precautions[:5] # Return top 5 precautions
|
| 185 |
|
|
@@ -198,11 +208,11 @@ def predict_crop(temperature, rainfall, humidity, soil_ph, soil_type, nitrogen,
|
|
| 198 |
}
|
| 199 |
|
| 200 |
# Add soil type columns (one-hot encoding)
|
| 201 |
-
for st in ['
|
| 202 |
input_data[f'Soil Type_{st}'] = [1 if soil_type == st else 0]
|
| 203 |
|
| 204 |
# Add season columns (one-hot encoding)
|
| 205 |
-
for s in ['Kharif (
|
| 206 |
input_data[f'Season_{s}'] = [1 if season == s else 0]
|
| 207 |
|
| 208 |
input_df = pd.DataFrame(input_data)
|
|
@@ -214,7 +224,7 @@ def predict_crop(temperature, rainfall, humidity, soil_ph, soil_type, nitrogen,
|
|
| 214 |
crop = model.predict(input_df)[0]
|
| 215 |
|
| 216 |
# Get profit range
|
| 217 |
-
profit = df[df['Crop'] == crop]['Profit (
|
| 218 |
|
| 219 |
# Get precautions
|
| 220 |
precautions = get_precautions(crop, temperature, rainfall, humidity, soil_type)
|
|
@@ -227,7 +237,7 @@ def predict_crop(temperature, rainfall, humidity, soil_ph, soil_type, nitrogen,
|
|
| 227 |
# Prepare output
|
| 228 |
output = {
|
| 229 |
"Recommended Crop": crop,
|
| 230 |
-
"Expected Profit (
|
| 231 |
"Top Precautions": precautions,
|
| 232 |
"Alternative Crops": similar_crops,
|
| 233 |
"Best Season": season
|
|
@@ -364,7 +374,7 @@ custom_css = """
|
|
| 364 |
# Function to format outputs
|
| 365 |
def format_outputs(output):
|
| 366 |
crop_md = f"**Recommended Crop:** {output['Recommended Crop']}"
|
| 367 |
-
profit_md = f"**Expected Profit (
|
| 368 |
season_md = f"**Best Season:** {output['Best Season']}"
|
| 369 |
alt_md = f"**Alternative Crops:** {', '.join(output['Alternative Crops'])}"
|
| 370 |
|
|
@@ -381,98 +391,98 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 381 |
with gr.Column(elem_classes="agrismart-container"):
|
| 382 |
with gr.Row(elem_classes="agrismart-header"):
|
| 383 |
gr.Markdown("""
|
| 384 |
-
# 🌱
|
| 385 |
-
###
|
| 386 |
""")
|
| 387 |
|
| 388 |
with gr.Row():
|
| 389 |
with gr.Column(elem_classes="agrismart-input"):
|
| 390 |
-
gr.Markdown("### 🌦️
|
| 391 |
|
| 392 |
with gr.Row():
|
| 393 |
-
temperature = gr.Slider(10,
|
| 394 |
-
info="
|
| 395 |
elem_classes="agrismart-slider")
|
| 396 |
-
rainfall = gr.Slider(
|
| 397 |
-
info="
|
| 398 |
elem_classes="agrismart-slider")
|
| 399 |
|
| 400 |
with gr.Row():
|
| 401 |
-
humidity = gr.Slider(
|
| 402 |
-
info="
|
| 403 |
elem_classes="agrismart-slider")
|
| 404 |
-
soil_ph = gr.Slider(
|
| 405 |
-
info="
|
| 406 |
elem_classes="agrismart-slider")
|
| 407 |
|
| 408 |
with gr.Row():
|
| 409 |
soil_type = gr.Dropdown(
|
| 410 |
-
["
|
| 411 |
-
label="5.
|
| 412 |
-
info="
|
| 413 |
elem_classes="agrismart-dropdown"
|
| 414 |
)
|
| 415 |
season = gr.Dropdown(
|
| 416 |
-
["Kharif (
|
| 417 |
-
label="6.
|
| 418 |
elem_classes="agrismart-dropdown"
|
| 419 |
)
|
| 420 |
|
| 421 |
with gr.Row():
|
| 422 |
-
nitrogen = gr.Slider(0, 150, label="7.
|
| 423 |
-
info="
|
| 424 |
elem_classes="agrismart-slider")
|
| 425 |
-
phosphorus = gr.Slider(0, 100, label="8.
|
| 426 |
-
info="
|
| 427 |
elem_classes="agrismart-slider")
|
| 428 |
-
potassium = gr.Slider(0, 200, label="9.
|
| 429 |
-
info="
|
| 430 |
elem_classes="agrismart-slider")
|
| 431 |
|
| 432 |
-
submit_btn = gr.Button("
|
| 433 |
|
| 434 |
with gr.Column(elem_classes="agrismart-output"):
|
| 435 |
-
gr.Markdown("### 📊
|
| 436 |
|
| 437 |
with gr.Column(elem_classes="agrismart-result-card"):
|
| 438 |
-
crop = gr.Markdown("**
|
| 439 |
-
profit = gr.Markdown("**
|
| 440 |
-
season_out = gr.Markdown("**
|
| 441 |
-
alternatives = gr.Markdown("**
|
| 442 |
|
| 443 |
-
gr.Markdown("### 🛡️
|
| 444 |
precautions = gr.HTML("""
|
| 445 |
<ul class="agrismart-precautions">
|
| 446 |
-
<li>
|
| 447 |
</ul>
|
| 448 |
""")
|
| 449 |
|
| 450 |
-
# Example images
|
| 451 |
-
gr.Markdown("### 🌾
|
| 452 |
gr.HTML("""
|
| 453 |
<div style="display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;">
|
| 454 |
<div style="text-align: center;">
|
| 455 |
<div style="background: #e3f2fd; padding: 10px; border-radius: 10px; width: 100px;">
|
| 456 |
<div style="font-size: 40px;">🌾</div>
|
| 457 |
-
<div>
|
| 458 |
</div>
|
| 459 |
</div>
|
| 460 |
<div style="text-align: center;">
|
| 461 |
<div style="background: #e8f5e9; padding: 10px; border-radius: 10px; width: 100px;">
|
| 462 |
-
<div style="font-size: 40px;">
|
| 463 |
-
<div>
|
| 464 |
</div>
|
| 465 |
</div>
|
| 466 |
<div style="text-align: center;">
|
| 467 |
<div style="background: #fff3e0; padding: 10px; border-radius: 10px; width: 100px;">
|
| 468 |
-
<div style="font-size: 40px;">
|
| 469 |
-
<div>
|
| 470 |
</div>
|
| 471 |
</div>
|
| 472 |
<div style="text-align: center;">
|
| 473 |
<div style="background: #f3e5f5; padding: 10px; border-radius: 10px; width: 100px;">
|
| 474 |
-
<div style="font-size: 40px;">
|
| 475 |
-
<div>
|
| 476 |
</div>
|
| 477 |
</div>
|
| 478 |
</div>
|
|
|
|
| 5 |
import gradio as gr
|
| 6 |
import random
|
| 7 |
|
| 8 |
+
# Generate synthetic dataset for Bangladesh crops
|
| 9 |
def generate_synthetic_dataset(num_samples=5000):
|
| 10 |
np.random.seed(42)
|
| 11 |
|
| 12 |
+
# Common crops in Bangladesh
|
| 13 |
crops = [
|
| 14 |
+
'Rice (Aman)', 'Rice (Boro)', 'Rice (Aus)', 'Jute', 'Wheat',
|
| 15 |
+
'Maize', 'Potato', 'Sugarcane', 'Pulses (Mungbean)', 'Pulses (Lentil)',
|
| 16 |
+
'Mustard', 'Sesame', 'Sunflower', 'Tea', 'Mango',
|
| 17 |
+
'Banana', 'Jackfruit', 'Litchi', 'Pineapple', 'Vegetables'
|
| 18 |
]
|
| 19 |
|
| 20 |
+
# Soil types common in Bangladesh
|
| 21 |
+
soil_types = ['Alluvial', 'Loamy', 'Clayey', 'Peaty', 'Sandy']
|
| 22 |
|
| 23 |
+
# Seasons in Bangladesh agriculture
|
| 24 |
+
seasons = ['Kharif-1 (Mar-Jun)', 'Kharif-2 (Jul-Oct)', 'Rabi (Nov-Feb)', 'Whole Year']
|
| 25 |
|
| 26 |
# Generate synthetic data
|
| 27 |
data = {
|
| 28 |
+
'Temperature (°C)': np.random.uniform(10, 40, num_samples), # Bangladesh has more moderate temperatures
|
| 29 |
+
'Rainfall (mm)': np.random.uniform(100, 400, num_samples), # Higher rainfall range
|
| 30 |
+
'Humidity (%)': np.random.uniform(60, 100, num_samples), # Generally high humidity
|
| 31 |
+
'Soil pH': np.random.uniform(5.0, 8.5, num_samples), # Slightly acidic to neutral
|
| 32 |
'Soil Type': np.random.choice(soil_types, num_samples),
|
| 33 |
'Nitrogen (N) Level': np.random.uniform(0, 150, num_samples),
|
| 34 |
'Phosphorus (P) Level': np.random.uniform(0, 100, num_samples),
|
|
|
|
| 45 |
crop = row['Crop']
|
| 46 |
|
| 47 |
# Temperature adjustments
|
| 48 |
+
if 'Rice' in crop:
|
| 49 |
+
df.at[idx, 'Temperature (°C)'] = np.random.uniform(25, 35)
|
| 50 |
+
df.at[idx, 'Humidity (%)'] = np.random.uniform(70, 100)
|
| 51 |
+
elif crop in ['Wheat', 'Mustard', 'Potato']:
|
| 52 |
+
df.at[idx, 'Temperature (°C)'] = np.random.uniform(15, 25)
|
| 53 |
+
elif crop in ['Jute', 'Tea']:
|
| 54 |
+
df.at[idx, 'Temperature (°C)'] = np.random.uniform(20, 30)
|
| 55 |
+
df.at[idx, 'Rainfall (mm)'] = np.random.uniform(200, 400)
|
| 56 |
|
| 57 |
# Soil type adjustments
|
| 58 |
+
if crop in ['Jute']:
|
| 59 |
+
df.at[idx, 'Soil Type'] = 'Alluvial'
|
| 60 |
+
elif crop in ['Tea']:
|
| 61 |
+
df.at[idx, 'Soil Type'] = 'Loamy'
|
| 62 |
+
elif crop in ['Rice (Boro)']:
|
| 63 |
+
df.at[idx, 'Soil Type'] = random.choice(['Alluvial', 'Clayey'])
|
| 64 |
|
| 65 |
# Season adjustments
|
| 66 |
+
if crop in ['Rice (Aman)', 'Jute']:
|
| 67 |
+
df.at[idx, 'Season'] = 'Kharif-2 (Jul-Oct)'
|
| 68 |
+
elif crop in ['Rice (Boro)', 'Wheat', 'Mustard', 'Potato']:
|
| 69 |
+
df.at[idx, 'Season'] = 'Rabi (Nov-Feb)'
|
| 70 |
+
elif crop in ['Rice (Aus)']:
|
| 71 |
+
df.at[idx, 'Season'] = 'Kharif-1 (Mar-Jun)'
|
| 72 |
|
| 73 |
+
# Add profit estimates (in BDT per acre)
|
| 74 |
profit_ranges = {
|
| 75 |
+
'Rice (Aman)': (30000, 60000),
|
| 76 |
+
'Rice (Boro)': (35000, 70000),
|
| 77 |
+
'Rice (Aus)': (25000, 50000),
|
| 78 |
+
'Jute': (40000, 80000),
|
| 79 |
+
'Wheat': (25000, 50000),
|
| 80 |
+
'Maize': (30000, 60000),
|
| 81 |
+
'Potato': (50000, 100000),
|
| 82 |
+
'Sugarcane': (60000, 120000),
|
| 83 |
+
'Pulses (Mungbean)': (20000, 45000),
|
| 84 |
+
'Pulses (Lentil)': (22000, 48000),
|
| 85 |
+
'Mustard': (25000, 55000),
|
| 86 |
+
'Sesame': (18000, 40000),
|
| 87 |
+
'Sunflower': (20000, 45000),
|
| 88 |
+
'Tea': (80000, 150000),
|
| 89 |
+
'Mango': (100000, 250000),
|
| 90 |
+
'Banana': (80000, 180000),
|
| 91 |
+
'Jackfruit': (70000, 150000),
|
| 92 |
+
'Litchi': (90000, 200000),
|
| 93 |
+
'Pineapple': (60000, 120000),
|
| 94 |
+
'Vegetables': (50000, 150000)
|
| 95 |
}
|
| 96 |
|
| 97 |
+
df['Profit (BDT/acre)'] = df['Crop'].apply(lambda x: random.randint(*profit_ranges[x]))
|
| 98 |
|
| 99 |
return df
|
| 100 |
|
|
|
|
| 102 |
df = generate_synthetic_dataset(10000)
|
| 103 |
|
| 104 |
# Prepare data for ML model
|
| 105 |
+
X = df.drop(['Crop', 'Profit (BDT/acre)'], axis=1)
|
| 106 |
X = pd.get_dummies(X) # Convert categorical variables to dummy variables
|
| 107 |
y = df['Crop']
|
| 108 |
|
|
|
|
| 115 |
|
| 116 |
# Crop precautions information
|
| 117 |
precautions_db = {
|
| 118 |
+
'Rice (Aman)': [
|
| 119 |
+
"Transplant 25-30 day old seedlings",
|
| 120 |
+
"Maintain 2-3 cm standing water during initial stage",
|
| 121 |
+
"Apply 60-80 kg N, 15-20 kg P, and 30-40 kg K per hectare",
|
| 122 |
+
"Control stem borer with proper insecticides"
|
| 123 |
],
|
| 124 |
+
'Rice (Boro)': [
|
| 125 |
+
"Ensure irrigation availability as it's dry season rice",
|
| 126 |
+
"Use cold-tolerant varieties in northern regions",
|
| 127 |
+
"Apply split doses of nitrogen fertilizer",
|
| 128 |
+
"Control rats and birds during ripening stage"
|
| 129 |
+
],
|
| 130 |
+
'Jute': [
|
| 131 |
+
"Sow in well-prepared land with proper moisture",
|
| 132 |
+
"Retting should be done in clean water for quality fiber",
|
| 133 |
+
"Apply 40-60 kg N, 20-30 kg P, and 20-30 kg K per hectare",
|
| 134 |
+
"Control jute hairy caterpillar with proper measures"
|
| 135 |
],
|
| 136 |
+
'Wheat': [
|
| 137 |
+
"Sow in rows with 20 cm spacing",
|
| 138 |
+
"Apply irrigation at crown root initiation and flowering stages",
|
| 139 |
+
"Use disease-resistant varieties to combat rust",
|
| 140 |
+
"Harvest when moisture content is 20-25%"
|
| 141 |
],
|
| 142 |
+
'Maize': [
|
| 143 |
+
"Sow in rows with 60 cm row to row distance",
|
| 144 |
+
"Apply 150-180 kg N, 35-40 kg P, and 60-70 kg K per hectare",
|
| 145 |
+
"Control fall armyworm with integrated pest management",
|
| 146 |
+
"Harvest when kernels have 20-25% moisture"
|
| 147 |
],
|
| 148 |
+
'Potato': [
|
| 149 |
+
"Use disease-free seed tubers",
|
| 150 |
+
"Apply irrigation at critical growth stages",
|
| 151 |
+
"Control late blight with fungicides",
|
| 152 |
+
"Harvest when vines dry up"
|
| 153 |
],
|
| 154 |
+
'Tea': [
|
| 155 |
+
"Prune bushes regularly for new flush",
|
| 156 |
+
"Apply balanced fertilizer with zinc and magnesium",
|
| 157 |
+
"Control red spider mite with acaricides",
|
| 158 |
+
"Pluck two leaves and a bud for quality"
|
| 159 |
],
|
| 160 |
+
'Mango': [
|
| 161 |
+
"Prune for proper canopy management",
|
| 162 |
+
"Control mango hopper during flowering",
|
| 163 |
+
"Apply irrigation during fruit development",
|
| 164 |
+
"Harvest when shoulders develop"
|
| 165 |
],
|
| 166 |
# Default precautions for other crops
|
| 167 |
'Default': [
|
|
|
|
| 180 |
if temperature > 35:
|
| 181 |
precautions.append("Provide mulch to reduce soil temperature")
|
| 182 |
precautions.append("Increase irrigation frequency during hot days")
|
| 183 |
+
if rainfall > 300:
|
| 184 |
+
precautions.append("Ensure proper drainage to prevent waterlogging")
|
| 185 |
+
if humidity > 85:
|
| 186 |
precautions.append("Watch for fungal diseases and apply preventive sprays")
|
| 187 |
|
| 188 |
# Add soil-specific precautions
|
| 189 |
+
if soil_type == 'Alluvial':
|
| 190 |
+
precautions.append("Apply organic matter to maintain soil fertility")
|
| 191 |
+
elif soil_type == 'Peaty':
|
| 192 |
+
precautions.append("Apply lime to reduce acidity if needed")
|
| 193 |
|
| 194 |
return precautions[:5] # Return top 5 precautions
|
| 195 |
|
|
|
|
| 208 |
}
|
| 209 |
|
| 210 |
# Add soil type columns (one-hot encoding)
|
| 211 |
+
for st in ['Alluvial', 'Loamy', 'Clayey', 'Peaty', 'Sandy']:
|
| 212 |
input_data[f'Soil Type_{st}'] = [1 if soil_type == st else 0]
|
| 213 |
|
| 214 |
# Add season columns (one-hot encoding)
|
| 215 |
+
for s in ['Kharif-1 (Mar-Jun)', 'Kharif-2 (Jul-Oct)', 'Rabi (Nov-Feb)', 'Whole Year']:
|
| 216 |
input_data[f'Season_{s}'] = [1 if season == s else 0]
|
| 217 |
|
| 218 |
input_df = pd.DataFrame(input_data)
|
|
|
|
| 224 |
crop = model.predict(input_df)[0]
|
| 225 |
|
| 226 |
# Get profit range
|
| 227 |
+
profit = df[df['Crop'] == crop]['Profit (BDT/acre)'].mean()
|
| 228 |
|
| 229 |
# Get precautions
|
| 230 |
precautions = get_precautions(crop, temperature, rainfall, humidity, soil_type)
|
|
|
|
| 237 |
# Prepare output
|
| 238 |
output = {
|
| 239 |
"Recommended Crop": crop,
|
| 240 |
+
"Expected Profit (BDT per acre)": f"৳{int(profit):,}",
|
| 241 |
"Top Precautions": precautions,
|
| 242 |
"Alternative Crops": similar_crops,
|
| 243 |
"Best Season": season
|
|
|
|
| 374 |
# Function to format outputs
|
| 375 |
def format_outputs(output):
|
| 376 |
crop_md = f"**Recommended Crop:** {output['Recommended Crop']}"
|
| 377 |
+
profit_md = f"**Expected Profit (BDT per acre):** {output['Expected Profit (BDT per acre)']}"
|
| 378 |
season_md = f"**Best Season:** {output['Best Season']}"
|
| 379 |
alt_md = f"**Alternative Crops:** {', '.join(output['Alternative Crops'])}"
|
| 380 |
|
|
|
|
| 391 |
with gr.Column(elem_classes="agrismart-container"):
|
| 392 |
with gr.Row(elem_classes="agrismart-header"):
|
| 393 |
gr.Markdown("""
|
| 394 |
+
# 🌱 বাংলাদেশের জন্য ফসল সুপারিশকারী
|
| 395 |
+
### আপনার জমির অবস্থা অনুযায়ী উপযুক্ত ফসলের পরামর্শ পান
|
| 396 |
""")
|
| 397 |
|
| 398 |
with gr.Row():
|
| 399 |
with gr.Column(elem_classes="agrismart-input"):
|
| 400 |
+
gr.Markdown("### 🌦️ আপনার জমির তথ্য দিন", elem_classes="agrismart-label")
|
| 401 |
|
| 402 |
with gr.Row():
|
| 403 |
+
temperature = gr.Slider(10, 40, label="1. তাপমাত্রা (°C)",
|
| 404 |
+
info="ছায়াযুক্ত স্থানে বায়ুর তাপমাত্রা মাপুন",
|
| 405 |
elem_classes="agrismart-slider")
|
| 406 |
+
rainfall = gr.Slider(100, 400, label="2. বৃষ্টিপাত (mm)",
|
| 407 |
+
info="আপনার এলাকার বার্ষিক বৃষ্টিপাতের পরিমাণ",
|
| 408 |
elem_classes="agrismart-slider")
|
| 409 |
|
| 410 |
with gr.Row():
|
| 411 |
+
humidity = gr.Slider(60, 100, label="3. আর্দ্রতা (%)",
|
| 412 |
+
info="বাতাসে আর্দ্রতার পরিমাণ",
|
| 413 |
elem_classes="agrismart-slider")
|
| 414 |
+
soil_ph = gr.Slider(5, 8.5, label="4. মাটির pH মান",
|
| 415 |
+
info="৭ হলো নিরপেক্ষ, ৭ এর নিচে অম্লীয়, ৭ এর উপরে ক্ষারীয়",
|
| 416 |
elem_classes="agrismart-slider")
|
| 417 |
|
| 418 |
with gr.Row():
|
| 419 |
soil_type = gr.Dropdown(
|
| 420 |
+
["Alluvial", "Loamy", "Clayey", "Peaty", "Sandy"],
|
| 421 |
+
label="5. মাটির ধরন",
|
| 422 |
+
info="বাংলাদেশের সাধারণ মাটির ধরন",
|
| 423 |
elem_classes="agrismart-dropdown"
|
| 424 |
)
|
| 425 |
season = gr.Dropdown(
|
| 426 |
+
["Kharif-1 (Mar-Jun)", "Kharif-2 (Jul-Oct)", "Rabi (Nov-Feb)", "Whole Year"],
|
| 427 |
+
label="6. মৌসুম",
|
| 428 |
elem_classes="agrismart-dropdown"
|
| 429 |
)
|
| 430 |
|
| 431 |
with gr.Row():
|
| 432 |
+
nitrogen = gr.Slider(0, 150, label="7. মাটিতে নাইট্রোজেনের পরিমাণ (N)",
|
| 433 |
+
info="গাছের পাতার বৃদ্ধির জন্য প্রয়োজনীয় (kg/ha)",
|
| 434 |
elem_classes="agrismart-slider")
|
| 435 |
+
phosphorus = gr.Slider(0, 100, label="8. মাটিতে ফসফরাসের পরিমাণ (P)",
|
| 436 |
+
info="শিকড়ের উন্নতির জন্য গুরুত্বপূর্ণ (kg/ha)",
|
| 437 |
elem_classes="agrismart-slider")
|
| 438 |
+
potassium = gr.Slider(0, 200, label="9. মাটিতে পটাশিয়ামের পরিমাণ (K)",
|
| 439 |
+
info="ফলের গুণগত মানের জন্য সহায়ক (kg/ha)",
|
| 440 |
elem_classes="agrismart-slider")
|
| 441 |
|
| 442 |
+
submit_btn = gr.Button("ফসলের সুপারিশ পান", elem_classes="agrismart-button")
|
| 443 |
|
| 444 |
with gr.Column(elem_classes="agrismart-output"):
|
| 445 |
+
gr.Markdown("### 📊 সুপারিশকৃত ফসলের বিবরণ", elem_classes="agrismart-label")
|
| 446 |
|
| 447 |
with gr.Column(elem_classes="agrismart-result-card"):
|
| 448 |
+
crop = gr.Markdown("**সুপারিশকৃত ফসল:** ", elem_classes="agrismart-result-value")
|
| 449 |
+
profit = gr.Markdown("**আনুমানিক লাভ (প্রতি একরে):** ", elem_classes="agrismart-result-value")
|
| 450 |
+
season_out = gr.Markdown("**উপযুক্ত মৌসুম:** ", elem_classes="agrismart-result-value")
|
| 451 |
+
alternatives = gr.Markdown("**বিকল্প ফসল:** ", elem_classes="agrismart-result-value")
|
| 452 |
|
| 453 |
+
gr.Markdown("### 🛡️ প্রয়োজনীয় সতর্কতা", elem_classes="agrismart-result-title")
|
| 454 |
precautions = gr.HTML("""
|
| 455 |
<ul class="agrismart-precautions">
|
| 456 |
+
<li>আপনার জমির তথ্য প্রদান করে বাটনে ক্লিক করুন</li>
|
| 457 |
</ul>
|
| 458 |
""")
|
| 459 |
|
| 460 |
+
# Example images of common Bangladeshi crops
|
| 461 |
+
gr.Markdown("### 🌾 বাংলাদেশের প্রধান ফসল")
|
| 462 |
gr.HTML("""
|
| 463 |
<div style="display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;">
|
| 464 |
<div style="text-align: center;">
|
| 465 |
<div style="background: #e3f2fd; padding: 10px; border-radius: 10px; width: 100px;">
|
| 466 |
<div style="font-size: 40px;">🌾</div>
|
| 467 |
+
<div>ধান</div>
|
| 468 |
</div>
|
| 469 |
</div>
|
| 470 |
<div style="text-align: center;">
|
| 471 |
<div style="background: #e8f5e9; padding: 10px; border-radius: 10px; width: 100px;">
|
| 472 |
+
<div style="font-size: 40px;">🧶</div>
|
| 473 |
+
<div>পাট</div>
|
| 474 |
</div>
|
| 475 |
</div>
|
| 476 |
<div style="text-align: center;">
|
| 477 |
<div style="background: #fff3e0; padding: 10px; border-radius: 10px; width: 100px;">
|
| 478 |
+
<div style="font-size: 40px;">🥔</div>
|
| 479 |
+
<div>আলু</div>
|
| 480 |
</div>
|
| 481 |
</div>
|
| 482 |
<div style="text-align: center;">
|
| 483 |
<div style="background: #f3e5f5; padding: 10px; border-radius: 10px; width: 100px;">
|
| 484 |
+
<div style="font-size: 40px;">🍌</div>
|
| 485 |
+
<div>কলা</div>
|
| 486 |
</div>
|
| 487 |
</div>
|
| 488 |
</div>
|