import gradio as gr # ----------------------------- # Q1 – Soil pH evaluation # ----------------------------- def Q1_ph_check(ph): if ph < 5.5: return "Soil is acidic" elif ph <= 7: return "Soil pH is optimal" else: return "Soil may be alkaline" # ----------------------------- # Q5 – Lime recommendation # ----------------------------- def Q5_lime_requirement(ph): if ph < 5.5: return "Apply agricultural lime" return "No lime required" # ----------------------------- # Q12 – Organic Carbon Health # ----------------------------- def Q12_organic_carbon(oc): if oc < 1: return "Low organic matter" elif oc < 3: return "Moderate organic matter" else: return "Healthy organic matter" # ----------------------------- # Q21 – Nitrogen rule # ----------------------------- def Q21_nitrogen(crop): crop_n = { "Cabbage": 200, "Jam Tomatoes": 180, "Green Peppers": 160, "Green Chillies": 150, "Marigolds": 90 } return crop_n.get(crop, 120) # ----------------------------- # Q29 – Phosphorus rule # ----------------------------- def Q29_phosphorus(soil_p, crop): crop_targets = { "Cabbage": 44, "Jam Tomatoes": 40, "Green Peppers": 38, "Green Chillies": 38, "Marigolds": 35 } target_p = crop_targets.get(crop, 40) if soil_p < target_p: return target_p - soil_p elif soil_p >= target_p and soil_p < 120: return 40 else: return 0 # ----------------------------- # Q30 – Potassium rule # ----------------------------- def Q30_potassium(soil_k, crop): crop_targets = { "Cabbage": 200, "Jam Tomatoes": 220, "Green Peppers": 210, "Green Chillies": 210, "Marigolds": 150 } target_k = crop_targets.get(crop, 200) if soil_k < target_k: return target_k - soil_k return 0 # ----------------------------- # Main Agronomy Engine # ----------------------------- def agronomy_engine(crop, ph, soil_p, soil_k, organic_carbon): ph_status = Q1_ph_check(ph) lime = Q5_lime_requirement(ph) oc_status = Q12_organic_carbon(organic_carbon) nitrogen = Q21_nitrogen(crop) phosphorus = Q29_phosphorus(soil_p, crop) potassium = Q30_potassium(soil_k, crop) report = f""" DARJYO Soil Intelligence Report Crop: {crop} Soil Health ------------ pH Status: {ph_status} Organic Carbon: {oc_status} Fertilizer Recommendations --------------------------- Nitrogen: {nitrogen} kg/ha Phosphorus: {phosphorus} kg/ha Potassium: {potassium} kg/ha Lime Recommendation ------------------- {lime} """ return report demo = gr.Interface( fn=agronomy_engine, inputs=[ gr.Dropdown( ["Cabbage", "Jam Tomatoes", "Green Peppers", "Green Chillies", "Marigolds"], label="Crop" ), gr.Number(label="Soil pH"), gr.Number(label="Soil Phosphorus (mg/L)"), gr.Number(label="Soil Potassium (mg/L)"), gr.Number(label="Organic Carbon (%)") ], outputs=gr.Textbox(label="DARJYO Advisory Report"), title="DARJYO Q-Series Engine", description="Crop Intelligence Soil nutrient advisory calculator for vegetable and horticulture crops." ) demo.launch()