Spaces:
Running
Running
isitraghav
commited on
Commit
·
b8a45c7
1
Parent(s):
fe3fd50
awdawd
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import pandas as pd
|
2 |
from sklearn.preprocessing import LabelEncoder
|
3 |
import gradio as gr
|
|
|
4 |
|
5 |
# Load data
|
6 |
def load_data(file_path):
|
@@ -65,9 +66,9 @@ def get_fertilizer_recommendation(row, land_size_m2, fallow_years, thresholds, a
|
|
65 |
total_amount = base_amount_per_m2 * land_size_m2 * (1 + 0.1 * fallow_years)
|
66 |
fertilizer_amounts[nutrient_name] = round(total_amount, 2)
|
67 |
if deficiencies:
|
68 |
-
return 'Fertilizer needed for
|
69 |
else:
|
70 |
-
return 'No deficiency, Manure Recommended', {}
|
71 |
|
72 |
# Gradio application
|
73 |
def gradio_application():
|
@@ -81,11 +82,11 @@ def gradio_application():
|
|
81 |
def fertilizer_recommendation(soil_type_input, crop_type_input, land_size_m2, fallow_years):
|
82 |
filtered_data = data[(data['Soil_type'] == soil_type_input) & (data['Crop_type'] == crop_type_input)]
|
83 |
if filtered_data.empty:
|
84 |
-
return
|
85 |
else:
|
86 |
row = filtered_data.iloc[0]
|
87 |
-
recommendation
|
88 |
-
return
|
89 |
|
90 |
demo = gr.Interface(
|
91 |
fn=fertilizer_recommendation,
|
@@ -95,7 +96,7 @@ def gradio_application():
|
|
95 |
gr.Number(label="Land Size (m2)"),
|
96 |
gr.Number(label="Fallow Years")
|
97 |
],
|
98 |
-
outputs="
|
99 |
title="Fertilizer Recommendation App",
|
100 |
description="Enter the soil type, crop type, land size, and fallow years to get a fertilizer recommendation."
|
101 |
)
|
|
|
1 |
import pandas as pd
|
2 |
from sklearn.preprocessing import LabelEncoder
|
3 |
import gradio as gr
|
4 |
+
import json
|
5 |
|
6 |
# Load data
|
7 |
def load_data(file_path):
|
|
|
66 |
total_amount = base_amount_per_m2 * land_size_m2 * (1 + 0.1 * fallow_years)
|
67 |
fertilizer_amounts[nutrient_name] = round(total_amount, 2)
|
68 |
if deficiencies:
|
69 |
+
return {'recommendation': f'Fertilizer needed for {", ".join(deficiencies)}', 'fertilizer_amounts': fertilizer_amounts}
|
70 |
else:
|
71 |
+
return {'recommendation': 'No deficiency, Manure Recommended', 'fertilizer_amounts': {}}
|
72 |
|
73 |
# Gradio application
|
74 |
def gradio_application():
|
|
|
82 |
def fertilizer_recommendation(soil_type_input, crop_type_input, land_size_m2, fallow_years):
|
83 |
filtered_data = data[(data['Soil_type'] == soil_type_input) & (data['Crop_type'] == crop_type_input)]
|
84 |
if filtered_data.empty:
|
85 |
+
return json.dumps({'error': 'No data available for the given soil type and crop type.'})
|
86 |
else:
|
87 |
row = filtered_data.iloc[0]
|
88 |
+
recommendation = get_fertilizer_recommendation(row, land_size_m2, fallow_years, thresholds, application_rates)
|
89 |
+
return json.dumps(recommendation)
|
90 |
|
91 |
demo = gr.Interface(
|
92 |
fn=fertilizer_recommendation,
|
|
|
96 |
gr.Number(label="Land Size (m2)"),
|
97 |
gr.Number(label="Fallow Years")
|
98 |
],
|
99 |
+
outputs="json",
|
100 |
title="Fertilizer Recommendation App",
|
101 |
description="Enter the soil type, crop type, land size, and fallow years to get a fertilizer recommendation."
|
102 |
)
|