{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19", "_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5", "execution": { "iopub.execute_input": "2026-09-02T10:03:29.342587Z", "iopub.status.busy": "2026-09-02T10:03:29.341720Z", "iopub.status.idle": "2026-09-02T10:04:26.264651Z", "shell.execute_reply": "2026-09-02T10:04:26.263762Z", "shell.execute_reply.started": "2026-09-02T10:03:29.342555Z" }, "trusted": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m12.1/12.1 MB\u001b[0m \u001b[31m89.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m:01\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m775.8/775.8 kB\u001b[0m \u001b[31m43.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m43.1/43.1 MB\u001b[0m \u001b[31m40.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m00:01\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m559.1/559.1 kB\u001b[0m \u001b[31m32.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m389.2/389.2 kB\u001b[0m \u001b[31m20.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m516.0/516.0 kB\u001b[0m \u001b[31m30.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.3/3.3 MB\u001b[0m \u001b[31m82.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m544.8/544.8 kB\u001b[0m \u001b[31m9.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0mta \u001b[36m0:00:01\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m67.0/67.0 kB\u001b[0m \u001b[31m2.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m506.8/506.8 kB\u001b[0m \u001b[31m12.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m73.8/73.8 kB\u001b[0m \u001b[31m4.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m10.2/10.2 MB\u001b[0m \u001b[31m91.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m0:01\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.5/1.5 MB\u001b[0m \u001b[31m67.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.3/3.3 MB\u001b[0m \u001b[31m84.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.6/3.6 MB\u001b[0m \u001b[31m95.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m216.9/216.9 kB\u001b[0m \u001b[31m14.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m88.7/88.7 MB\u001b[0m \u001b[31m21.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m00:01\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m119.7/119.7 kB\u001b[0m \u001b[31m7.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.3/3.3 MB\u001b[0m \u001b[31m86.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.4/3.4 MB\u001b[0m \u001b[31m91.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m225.0/225.0 kB\u001b[0m \u001b[31m15.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25h✅ Dependencies installed\n" ] } ], "source": [ "!pip install -q transformers peft bitsandbytes datasets accelerate -U\n", "!pip install -q trl==0.22.2\n", "!pip install -q unsloth[kaggle] --upgrade\n", "print(\"✅ Dependencies installed\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2026-09-02T10:04:42.174302Z", "iopub.status.busy": "2026-09-02T10:04:42.173940Z", "iopub.status.idle": "2026-09-02T10:04:43.210561Z", "shell.execute_reply": "2026-09-02T10:04:43.210003Z", "shell.execute_reply.started": "2026-09-02T10:04:42.174270Z" }, "trusted": true }, "outputs": [], "source": [ "from huggingface_hub import login\n", "\n", "# Paste your actual token string inside the quotes\n", "login(token=\"\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2026-09-02T10:06:51.583913Z", "iopub.status.busy": "2026-09-02T10:06:51.582929Z", "iopub.status.idle": "2026-09-02T10:06:51.613020Z", "shell.execute_reply": "2026-09-02T10:06:51.612201Z", "shell.execute_reply.started": "2026-09-02T10:06:51.583873Z" }, "trusted": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "✅ Successfully generated 203 training examples in 'agriculture_training_data.json'!\n" ] } ], "source": [ "import json\n", "import random\n", "\n", "# Complete knowledge base covering all plant disease and pest classes\n", "agri_knowledge_base = [\n", " {\n", " \"class_name\": \"Apple___Apple_scab\",\n", " \"symptoms\": \"olive-green to black velvety spots on leaves, puckered foliage, and dark corky lesions on fruit\",\n", " \"treatment\": \"Spray Captan (2 g/L) or Mancozeb (2.5 g/L) starting from the green-tip bud stage through petal fall.\",\n", " \"organic\": \"Apply sulfur dust (3 g/L) or spray diluted neem oil emulsion early morning.\",\n", " \"prevention\": \"Prune dense canopies to maximize sunlight and rake/burn fallen leaves in autumn.\"\n", " },\n", " {\n", " \"class_name\": \"Apple___Black_rot\",\n", " \"symptoms\": \"purple flecks on leaves expanding into frog-eye spots, black mummified fruit on branches, and sunken bark cankers\",\n", " \"treatment\": \"Prune out diseased twigs 15 cm below infected tissue and spray Thiophanate-methyl or copper oxychloride.\",\n", " \"organic\": \"Prune infected limbs during dry weather and apply liquid copper spray before spring bud break.\",\n", " \"prevention\": \"Remove dead wood and mummified apples from the orchard floor immediately.\"\n", " },\n", " {\n", " \"class_name\": \"Apple___Cedar_apple_rust\",\n", " \"symptoms\": \"bright yellow-orange circular spots on upper leaf surfaces with tiny black dots, followed by tube-like projections underneath\",\n", " \"treatment\": \"Apply Myclobutanil or Trifloxystrobin every 7 to 10 days from pink bud stage through bloom.\",\n", " \"organic\": \"Spray sulfur fungicides at pink stage and physically prune nearby alternate host cedar trees.\",\n", " \"prevention\": \"Remove eastern red cedar/juniper trees within a 500-meter radius of the apple orchard.\"\n", " },\n", " {\n", " \"class_name\": \"Cherry_(including_sour)___Powdery_mildew\",\n", " \"symptoms\": \"white powdery fungal patches on new leaf flushes, curling leaf margins, and stunted terminal shoot growth\",\n", " \"treatment\": \"Apply Hexaconazole (1 ml/L) or Tebuconazole (1 ml/L) at petal fall and repeat after 14 days.\",\n", " \"organic\": \"Spray potassium bicarbonate (3 g/L) mixed with horticultural oil or 3% neem oil.\",\n", " \"prevention\": \"Maintain wide tree spacing, minimize overhead sprinkler irrigation, and avoid excess nitrogen.\"\n", " },\n", " {\n", " \"class_name\": \"Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot\",\n", " \"symptoms\": \"small, rectangular, tan-to-gray lesions restricted by leaf veins, coalescing into extensive blighted strips\",\n", " \"treatment\": \"Spray Pyraclostrobin + Epoxiconazole or Azoxystrobin (1 ml/L) when lesions reach the ear leaf during tasseling.\",\n", " \"organic\": \"Apply biological Trichoderma viride formulations to soil and foliar bio-fungicides.\",\n", " \"prevention\": \"Practice 2-year crop rotation with non-host crops and adopt tillage to bury infected corn residue.\"\n", " },\n", " {\n", " \"class_name\": \"Corn_(maize)___Common_rust_\",\n", " \"symptoms\": \"small, reddish-brown to dark brown pustules on both upper and lower leaf surfaces that rupture to release powdery spores\",\n", " \"treatment\": \"Apply Mancozeb (2.5 g/L) or Propiconazole (1 ml/L) if rust appears prior to the silking stage.\",\n", " \"organic\": \"Dust with fine wettable sulfur early in the morning when dew is present.\",\n", " \"prevention\": \"Plant resistant hybrid seed varieties and sow early in the season to evade peak spore loads.\"\n", " },\n", " {\n", " \"class_name\": \"Corn_(maize)___Northern_Leaf_Blight\",\n", " \"symptoms\": \"long, elliptical, grayish-green or tan cigar-shaped lesions on leaves, typically starting on lower canopy leaves\",\n", " \"treatment\": \"Spray Azoxystrobin or Propiconazole (1 ml/L) at first symptom onset during humid weather.\",\n", " \"organic\": \"Remove lower blighted leaves manually and apply Bacillus subtilis bio-spray.\",\n", " \"prevention\": \"Rotate with legumes or oilseeds and deep plow crop residues right after harvest.\"\n", " },\n", " {\n", " \"class_name\": \"Grape___Black_rot\",\n", " \"symptoms\": \"small brown circular leaf lesions with dark margins and black pycnidia, berries turning into hard, shriveled black mummies\",\n", " \"treatment\": \"Spray Mancozeb (2 g/L) or Difenoconazole (0.5 ml/L) before bloom and repeat every 10-14 days.\",\n", " \"organic\": \"Apply copper hydroxide (Bordeaux mixture 1%) during early vine growth.\",\n", " \"prevention\": \"Remove all mummified fruit clusters during winter pruning and thin vine canopy for rapid air drying.\"\n", " },\n", " {\n", " \"class_name\": \"Grape___Esca_(Black_Measles)\",\n", " \"symptoms\": \"tiger-stripe leaf discoloration with yellow and brown bands between veins, dark spots on grape skin, and vine apoplexy\",\n", " \"treatment\": \"No chemical cure exists for infected trunk wood; prune back infected cordons into healthy wood and seal cuts with wound paste.\",\n", " \"organic\": \"Apply Trichoderma-based bio-protectants to large pruning wounds immediately.\",\n", " \"prevention\": \"Sterilize pruning shears with 70% alcohol between vines and delay winter pruning until dry weather.\"\n", " },\n", " {\n", " \"class_name\": \"Grape___Leaf_blight_(Isariopsis_Leaf_Spot)\",\n", " \"symptoms\": \"irregular brown spots with faint yellow halos on leaves, turning dark with velvety fungal growth on the underside\",\n", " \"treatment\": \"Spray Chlorothalonil (2 g/L) or Carbendazim (1 g/L) at first symptom detection.\",\n", " \"organic\": \"Spray 1% Bordeaux mixture or copper oxychloride solution.\",\n", " \"prevention\": \"Maintain proper shoot positioning on trellises and clean up fallen vineyard foliage.\"\n", " },\n", " {\n", " \"class_name\": \"Orange___Haunglongbing_(Citrus_greening)\",\n", " \"symptoms\": \"asymmetric blotchy yellow mottle on leaves, yellow shoots, stunted trees, and small, bitter, lopsided green fruit\",\n", " \"treatment\": \"No cure for the systemic bacterium; eradicate infected trees immediately and control the Asian Citrus Psyllid vector with Imidacloprid (0.5 ml/L).\",\n", " \"organic\": \"Use yellow sticky cards, spray high-grade horticultural mineral oil, and release Tamarixia radiata parasitoid wasps.\",\n", " \"prevention\": \"Plant only certified disease-free nursery saplings and aggressively control psyllid vectors.\"\n", " },\n", " {\n", " \"class_name\": \"Peach___Bacterial_spot\",\n", " \"symptoms\": \"angular, water-soaked, purple-black lesions on leaves that drop out giving a shot-hole look, plus cratered fruit\",\n", " \"treatment\": \"Apply copper bactericide sprays at leaf fall and low-rate copper or Oxytetracycline during the growing season.\",\n", " \"organic\": \"Apply dilute copper sulfate before bud swelling and avoid broad-spectrum chemical sprays.\",\n", " \"prevention\": \"Avoid planting in light sandy soils without windbreaks and avoid overhead irrigation.\"\n", " },\n", " {\n", " \"class_name\": \"Pepper,_bell___Bacterial_spot\",\n", " \"symptoms\": \"small, dark, greasy water-soaked spots on leaf undersides, premature yellowing, defoliation, and rough raised spots on peppers\",\n", " \"treatment\": \"Spray Copper Hydroxide (2 g/L) combined with Mancozeb (2 g/L) weekly under warm, wet conditions.\",\n", " \"organic\": \"Soak seeds in hot water (50°C for 25 mins) before sowing and apply Streptomyces-based bio-agents.\",\n", " \"prevention\": \"Use certified pathogen-free seeds, practice 3-year solanaceous crop rotation, and avoid handling wet plants.\"\n", " },\n", " {\n", " \"class_name\": \"Potato___Early_blight\",\n", " \"symptoms\": \"brown-to-black spots with characteristic concentric rings (target-board pattern) starting on older lower foliage\",\n", " \"treatment\": \"Spray Mancozeb (2.5 g/L) or Chlorothalonil (2 g/L) at initial spot appearance, repeating every 7-10 days.\",\n", " \"organic\": \"Apply liquid copper spray or a 5% neem seed kernel extract (NSKE) foliar spray.\",\n", " \"prevention\": \"Maintain balanced plant nutrition (avoid nitrogen deficiency) and water the furrow, not the foliage.\"\n", " },\n", " {\n", " \"class_name\": \"Potato___Late_blight\",\n", " \"symptoms\": \"large, irregular water-soaked pale-to-dark green lesions on leaves/stems, rapidly turning brown-black with white mildew underneath\",\n", " \"treatment\": \"Apply systemic Metalaxyl-M + Mancozeb (2.5 g/L) or Cymoxanil immediately; destroy severely diseased plants.\",\n", " \"organic\": \"Spray 1% Bordeaux mixture preventatively before continuous rainy spells.\",\n", " \"prevention\": \"Use certified blight-free seed tubers, hill up soil ridges to cover tubers, and cull volunteer potato plants.\"\n", " },\n", " {\n", " \"class_name\": \"Squash___Powdery_mildew\",\n", " \"symptoms\": \"talcum-powder-like white fungal colonies on upper and lower surfaces of older leaves, causing yellowing and premature leaf crisping\",\n", " \"treatment\": \"Spray Azoxystrobin (1 ml/L) or Myclobutanil (0.5 ml/L) upon observing the first white spots.\",\n", " \"organic\": \"Spray a 1:9 milk-to-water solution or potassium bicarbonate (3 g/L) plus neem oil weekly.\",\n", " \"prevention\": \"Plant resistant squash varieties, space hills 1-1.5 meters apart, and plant in full sun.\"\n", " },\n", " {\n", " \"class_name\": \"Strawberry___Leaf_scorch\",\n", " \"symptoms\": \"numerous small, irregular purple-to-brown blotches on leaves that enlarge and dry up, making leaves look burnt\",\n", " \"treatment\": \"Apply Captan (2 g/L) or Pyraclostrobin-based fungicides at early spring renovation.\",\n", " \"organic\": \"Spray copper-based bio-fungicides and remove scorch-damaged crowns.\",\n", " \"prevention\": \"Set plants in well-drained raised beds, use drip irrigation, and remove old leaf debris post-harvest.\"\n", " },\n", " {\n", " \"class_name\": \"Tomato___Bacterial_spot\",\n", " \"symptoms\": \"tiny water-soaked black spots surrounded by yellow halos on leaves, causing leaf drop and sunscald on exposed fruit\",\n", " \"treatment\": \"Spray copper oxychloride (2.5 g/L) tank-mixed with Mancozeb (2 g/L) every 7-10 days.\",\n", " \"organic\": \"Spray copper sulfate pentahydrate and use Bacillus amyloliquefaciens biopesticide.\",\n", " \"prevention\": \"Treat seed with 1.3% sodium hypochlorite before planting and sanitize all tomato stakes and cages.\"\n", " },\n", " {\n", " \"class_name\": \"Tomato___Early_blight\",\n", " \"symptoms\": \"dark brown circular spots with distinct concentric target rings on bottom leaves, progressing upward with yellow halos\",\n", " \"treatment\": \"Apply Mancozeb (2.5 g/L) or Azoxystrobin + Difenoconazole (1 ml/L) every 10 days.\",\n", " \"organic\": \"Mulch beds with straw, prune the lowest 30 cm of foliage, and apply copper fungicide spray.\",\n", " \"prevention\": \"Follow a strict 3-year non-solanaceous crop rotation and stake plants off the ground.\"\n", " },\n", " {\n", " \"class_name\": \"Tomato___Late_blight\",\n", " \"symptoms\": \"large, dark, greasy-looking water-soaked lesions on foliage, white fungal fuzz on leaf undersides, and brown rot on green tomatoes\",\n", " \"treatment\": \"Spray Dimethomorph (1 g/L) or Metalaxyl + Mancozeb (2.5 g/L) at the earliest sign of disease.\",\n", " \"organic\": \"Spray copper hydroxide preventatively before cool, humid weather sets in.\",\n", " \"prevention\": \"Do not plant tomatoes next to potatoes, ensure adequate air flow, and immediately bag and destroy blighted vines.\"\n", " },\n", " {\n", " \"class_name\": \"Tomato___Leaf_Mold\",\n", " \"symptoms\": \"pale green to light yellow patches on upper leaf surfaces matching olive-green to brown velvety mold on leaf undersides\",\n", " \"treatment\": \"Apply Difenoconazole (0.5 ml/L) or Chlorothalonil (2 g/L) targeting both sides of the leaves.\",\n", " \"organic\": \"Spray copper octanoate or dilute neem oil; increase ventilation in polyhouse environments.\",\n", " \"prevention\": \"Keep greenhouse relative humidity below 85% and prune suckers to improve internal air movement.\"\n", " },\n", " {\n", " \"class_name\": \"Tomato___Septoria_leaf_spot\",\n", " \"symptoms\": \"numerous small circular spots with gray-white centers and dark brown margins studded with tiny black fruiting specs\",\n", " \"treatment\": \"Spray Chlorothalonil (2 g/L) or Mancozeb (2.5 g/L) as soon as symptoms appear on lower leaves.\",\n", " \"organic\": \"Strip off infected bottom leaves and spray liquid copper fungicide.\",\n", " \"prevention\": \"Use clean plastic mulch over soil, avoid wetting the foliage, and destroy tomato plant residue at season's end.\"\n", " },\n", " {\n", " \"class_name\": \"Tomato___Spider_mites Two-spotted_spider_mite\",\n", " \"symptoms\": \"fine yellow stippling/flecking across leaves, webbing on leaf undersides and branch forks, leaves drying to bronze\",\n", " \"treatment\": \"Spray Abamectin (0.5 ml/L), Spiromesifen (1 ml/L), or Propargite (2 ml/L) ensuring complete under-leaf coverage.\",\n", " \"organic\": \"Spray high-pressure water streams to dislodge mites, followed by 2% horticultural soap or pure neem oil spray.\",\n", " \"prevention\": \"Maintain field moisture to avoid dusty drought conditions that foster mite explosions and preserve predatory mites.\"\n", " },\n", " {\n", " \"class_name\": \"Tomato___Target_Spot\",\n", " \"symptoms\": \"small brown pinpoint lesions expanding into necrotic spots with faint concentric rings and yellow halos on leaves and fruit\",\n", " \"treatment\": \"Apply Azoxystrobin (1 ml/L) or Boscalid (1 g/L) when lower leaves begin showing symptoms.\",\n", " \"organic\": \"Prune foliage to open canopy, mulch rows, and apply bio-fungicide Bacillus subtilis.\",\n", " \"prevention\": \"Maintain adequate plant spacing, avoid excessive nitrogen which creates dense foliage, and sanitize stakes.\"\n", " },\n", " {\n", " \"class_name\": \"Tomato___Tomato_Yellow_Leaf_Curl_Virus\",\n", " \"symptoms\": \"severe upward curling and cupping of leaf margins, yellowing (chlorosis) between veins, stunted bushy growth, and fruit drop\",\n", " \"treatment\": \"No chemical virucide exists. Control the whitefly insect vector immediately using Acetamiprid (0.4 g/L) or Thiamethoxam (0.3 g/L).\",\n", " \"organic\": \"Install yellow sticky traps (30 per acre), cover nurseries with 50-mesh insect nets, and spray 3% neem oil.\",\n", " \"prevention\": \"Plant TYLCV-resistant tomato hybrids and remove/bag virus-infected plants immediately to prevent whitefly transmission.\"\n", " },\n", " {\n", " \"class_name\": \"Tomato___Tomato_mosaic_virus\",\n", " \"symptoms\": \"mottled dark and light green mosaic pattern on leaves, leaf distortion (shoestring effect), stunted vines, and internal fruit browning\",\n", " \"treatment\": \"No chemical cure. Remove and burn infected plants immediately; wash hands and tools with 10% trisodium phosphate (TSP) or skim milk.\",\n", " \"organic\": \"Disinfect all tools, cull infected plants, and avoid handling tobacco products near crops.\",\n", " \"prevention\": \"Use virus-tested seeds, clean nursery trays, and plant mosaic-resistant varieties (Tm-2/Tm-2^2 gene).\"\n", " },\n", " {\n", " \"class_name\": \"Cauliflower___Black_Rot\",\n", " \"symptoms\": \"V-shaped yellow chlorotic lesions starting at leaf margins with blackened leaf veins and darkened internal vascular ring\",\n", " \"treatment\": \"Spray Copper Oxychloride (2.5 g/L) combined with Streptocycline (0.1 g/L) at first symptom onset.\",\n", " \"organic\": \"Hot water seed treatment at 50°C for 30 minutes, followed by spraying plant extract of Trichoderma.\",\n", " \"prevention\": \"Practice 3-year rotation away from cruciferous crops, ensure well-drained soil, and control flea beetles.\"\n", " },\n", " {\n", " \"class_name\": \"Cauliflower___Insect_Hole_Pest\",\n", " \"symptoms\": \"perforated leaves with ragged holes, chewed curd heads, visible dark frass/droppings caused by Diamondback moth or Cabbage looper\",\n", " \"treatment\": \"Spray Emamectin Benzoate (0.5 g/L), Spinosad (0.3 ml/L), or Chlorantraniliprole (0.3 ml/L) during evening hours.\",\n", " \"organic\": \"Apply Bacillus thuringiensis (Bt var. kurstaki @ 2 g/L) or spray 5% Neem Seed Kernel Extract (NSKE).\",\n", " \"prevention\": \"Install pheromone traps (8-10 per acre), use mustard as a trap crop around cauliflower borders, and hand-pick larvae.\"\n", " },\n", " {\n", " \"class_name\": \"Healthy_Crop_Maintenance\",\n", " \"symptoms\": \"vibrant green foliage, sturdy stems, active blossom set, and absence of fungal spots, lesions, or insect feeding marks\",\n", " \"treatment\": \"Continue regular agronomic care: provide balanced NPK fertilization, maintain uniform soil moisture, and scout weekly.\",\n", " \"organic\": \"Apply well-decomposed farmyard manure (FYM) or vermicompost along with bi-weekly Jeevamrutha drenches.\",\n", " \"prevention\": \"Maintain clean field borders, practice crop rotation, install bird perches, and avoid over-fertilization.\"\n", " }\n", "]\n", "\n", "system_instruction = \"You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\"\n", "\n", "training_examples = []\n", "\n", "# Generate 7 distinct conversational angles for every single class entry (29 classes * 7 = 203 high-quality examples)\n", "for entry in agri_knowledge_base:\n", " clean_name = entry[\"class_name\"].replace(\"___\", \" - \").replace(\"_\", \" \")\n", " \n", " # 1. Direct Computer Vision Diagnostic Trigger\n", " training_examples.append({\n", " \"instruction\": system_instruction,\n", " \"input\": f\"AgriVani scan detected {clean_name}. Symptoms visible: {entry['symptoms']}. What should I do right now?\",\n", " \"output\": f\"**Immediate Action Plan for {clean_name}:**\\n\\n- **Treatment:** {entry['treatment']}\\n- **Long-term Protection:** {entry['prevention']}\"\n", " })\n", " \n", " # 2. Organic / Chemical-Free Method Query\n", " training_examples.append({\n", " \"instruction\": system_instruction,\n", " \"input\": f\"My crop is affected by {clean_name}. I only do organic farming. How can I control it naturally?\",\n", " \"output\": f\"**Organic Management for {clean_name}:**\\n\\n- **Natural Solution:** {entry['organic']}\\n- **Cultural Practice:** {entry['prevention']}\"\n", " })\n", " \n", " # 3. Preventive Strategy Query\n", " training_examples.append({\n", " \"instruction\": system_instruction,\n", " \"input\": f\"How do I prevent {clean_name} from damaging my field this season?\",\n", " \"output\": f\"**Prevention Guidelines for {clean_name}:**\\n\\n- **Key Preventive Steps:** {entry['prevention']}\\n- **Early Warning Signs:** Watch out for {entry['symptoms']}.\"\n", " })\n", " \n", " # 4. Field Scouting & Symptom Identification\n", " training_examples.append({\n", " \"instruction\": system_instruction,\n", " \"input\": f\"What are the symptoms of {clean_name}? How do I identify it in the field?\",\n", " \"output\": f\"**Symptom Identification for {clean_name}:**\\n\\nLook for **{entry['symptoms']}**. If you observe these symptoms, act immediately: {entry['treatment']}\"\n", " })\n", " \n", " # 5. Hinglish Farmer Query Style\n", " training_examples.append({\n", " \"instruction\": system_instruction,\n", " \"input\": f\"Khet me {clean_name} lag gaya hai, patto me {entry['symptoms']} dikh raha hai. Upay bataiye.\",\n", " \"output\": f\"**{clean_name} ka ilaaj:**\\n\\n- **Turant Upay (Immediate Treatment):** {entry['treatment']}\\n- **Organic Upay:** {entry['organic']}\\n- **Roka-thaam (Prevention):** {entry['prevention']}\"\n", " })\n", " \n", " # 6. Emergency Recovery / Yield Protection\n", " training_examples.append({\n", " \"instruction\": system_instruction,\n", " \"input\": f\"Emergency: {clean_name} is spreading fast in my crop. How to stop it from ruining the entire harvest?\",\n", " \"output\": f\"**Emergency Intervention for {clean_name}:**\\n\\n1. **Stop the Spread:** {entry['treatment']}\\n2. **Field Hygiene:** {entry['prevention']}\\n3. **Eco Alternative:** {entry['organic']}\"\n", " })\n", " \n", " # 7. Low-Cost / Smallholder Farmer Scenario\n", " training_examples.append({\n", " \"instruction\": system_instruction,\n", " \"input\": f\"I am a smallholder farmer with a low budget. What is the most cost-effective way to handle {clean_name}?\",\n", " \"output\": f\"**Cost-Effective Management for {clean_name}:**\\n\\n- **Low-Cost Method:** {entry['organic']}\\n- **Chemical Alternative if Severe:** {entry['treatment']}\\n- **Zero-Cost Cultural Control:** {entry['prevention']}\"\n", " })\n", "\n", "# Shuffle the final dataset\n", "random.seed(42)\n", "random.shuffle(training_examples)\n", "\n", "# Save both standard and expanded files\n", "with open('agriculture_training_data.json', 'w', encoding='utf-8') as f:\n", " json.dump(training_examples, f, indent=2, ensure_ascii=False)\n", "\n", "with open('agrivani_expanded_dataset.json', 'w', encoding='utf-8') as f:\n", " json.dump(training_examples, f, indent=2, ensure_ascii=False)\n", "\n", "print(f\"✅ Successfully generated {len(training_examples)} training examples in 'agriculture_training_data.json'!\")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2026-09-02T10:07:02.403452Z", "iopub.status.busy": "2026-09-02T10:07:02.402805Z", "iopub.status.idle": "2026-09-02T10:07:02.415483Z", "shell.execute_reply": "2026-09-02T10:07:02.414789Z", "shell.execute_reply.started": "2026-09-02T10:07:02.403422Z" }, "trusted": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "✅ Generated 174 new agri-domain examples\n" ] } ], "source": [ "# Requires agri_knowledge_base already defined (from your original dataset script)\n", "\n", "new_templates = []\n", "\n", "for entry in agri_knowledge_base:\n", " clean_name = entry[\"class_name\"].replace(\"___\", \" - \").replace(\"_\", \" \")\n", "\n", " # 1. Yield/economic angle\n", " new_templates.append({\n", " \"instruction\": system_instruction,\n", " \"input\": f\"Will {clean_name} reduce my crop yield significantly? Should I be worried?\",\n", " \"output\": f\"Yes, if left untreated, {clean_name} can significantly reduce yield and fruit/leaf quality. Acting early makes a big difference:\\n\\n- **Immediate step:** {entry['treatment']}\\n- **To protect future harvests:** {entry['prevention']}\"\n", " })\n", "\n", " # 2. Contagion/spread concern\n", " new_templates.append({\n", " \"instruction\": system_instruction,\n", " \"input\": f\"Can {clean_name} spread to my neighbor's field or other crops nearby?\",\n", " \"output\": f\"This depends on the specific pathogen, but many diseases like this can spread via wind, rain splash, insects, or contaminated tools. It's worth informing nearby farmers.\\n\\n- **To limit spread:** {entry['prevention']}\\n- **If already spreading:** {entry['treatment']}\"\n", " })\n", "\n", " # 3. Timing / seasonal question\n", " new_templates.append({\n", " \"instruction\": system_instruction,\n", " \"input\": f\"When is {clean_name} most likely to occur, and should I be checking for it right now?\",\n", " \"output\": f\"Watch for **{entry['symptoms']}** — catching it early makes treatment far more effective.\\n\\n- **If you see these signs:** {entry['treatment']}\\n- **To reduce future risk:** {entry['prevention']}\"\n", " })\n", "\n", " # 4. Short, casual Hinglish phrasing (different from earlier \"Khet me X lag gaya\" template)\n", " new_templates.append({\n", " \"instruction\": system_instruction,\n", " \"input\": f\"{clean_name} ke baare mein thoda samjhaiye, kya karna chahiye?\",\n", " \"output\": f\"**{clean_name}** ke lakshan hain: {entry['symptoms']}\\n\\n**Kya karein:** {entry['treatment']}\\n\\n**Aage bachne ke liye:** {entry['prevention']}\"\n", " })\n", "\n", " # 5. Comparison of chemical vs organic decision\n", " new_templates.append({\n", " \"instruction\": system_instruction,\n", " \"input\": f\"For {clean_name}, should I go with chemical treatment or organic — what's the difference?\",\n", " \"output\": f\"Both work, with trade-offs:\\n\\n- **Chemical (faster, more reliable in severe cases):** {entry['treatment']}\\n- **Organic (safer, better for long-term soil/plant health):** {entry['organic']}\\n\\nFor severe infections, many farmers start with the chemical option and shift to organic maintenance once under control.\"\n", " })\n", "\n", " # 6. Confirmation/second-opinion style question\n", " new_templates.append({\n", " \"instruction\": system_instruction,\n", " \"input\": f\"I think my crop has {clean_name} but I'm not 100% sure. What should I look for to confirm?\",\n", " \"output\": f\"To confirm, check for: **{entry['symptoms']}**\\n\\nIf you see these signs clearly, you can proceed with treatment: {entry['treatment']}. If symptoms don't match exactly, it may be worth getting a second opinion from a local agricultural officer before treating.\"\n", " })\n", "\n", "random.shuffle(new_templates)\n", "print(f\"✅ Generated {len(new_templates)} new agri-domain examples\")\n", "\n", "with open('agrivani_expanded_agri_data.json', 'w', encoding='utf-8') as f:\n", " json.dump(new_templates, f, indent=2, ensure_ascii=False)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2026-09-02T10:07:08.483005Z", "iopub.status.busy": "2026-09-02T10:07:08.482678Z", "iopub.status.idle": "2026-09-02T10:07:08.502495Z", "shell.execute_reply": "2026-09-02T10:07:08.501880Z", "shell.execute_reply.started": "2026-09-02T10:07:08.482921Z" }, "trusted": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Base conversational examples: 56\n", "✅ Final conversational dataset: 90 examples\n" ] } ], "source": [ "import json\n", "import random\n", "\n", "system_instruction = \"You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\"\n", "\n", "conversational_data = []\n", "\n", "# 1. Greetings (English + Hinglish)\n", "greetings = [\n", " (\"Hi\", \"Hello! I'm AgriVani, your farming assistant. How can I help you with your crops today?\"),\n", " (\"Hello\", \"Hi there! Tell me about your farm or crop issue, and I'll do my best to help.\"),\n", " (\"Namaste AgriVani\", \"Namaste! Main aapki fasal ki samasyaon mein madad karne ke liye yahan hoon. Bataiye kya poochna hai?\"),\n", " (\"Good morning\", \"Good morning! Hope your fields are doing well today. What can I help you with?\"),\n", " (\"Good evening, kaise ho?\", \"Namaste! Main theek hoon, aap bataiye — khet mein kuch samasya hai kya?\"),\n", " (\"Kya haal hai AgriVani?\", \"Sab badhiya! Aapke fasal ke baare mein kuch poochna hai kya?\"),\n", " (\"Hey\", \"Hey! What's going on with your crops today?\"),\n", " (\"Namaskar\", \"Namaskar! Kaise madad kar sakta hoon aapki?\"),\n", "]\n", "for q, a in greetings:\n", " conversational_data.append({\"instruction\": system_instruction, \"input\": q, \"output\": a})\n", "\n", "# 2. Capability / identity questions\n", "capability = [\n", " (\"What can you help me with?\", \"I can help diagnose crop diseases and pest problems, suggest treatments (both chemical and organic), give prevention tips, and answer general farming questions. Just tell me what's going on with your crop.\"),\n", " (\"Who are you?\", \"I'm AgriVani, an AI assistant built to help farmers identify and treat crop diseases and pests, and offer practical farming advice.\"),\n", " (\"Tum kya kar sakte ho?\", \"Main aapki fasal ki bimariyon aur keeton ki pehchaan karne mein, unka ilaj batane mein, aur roka-thaam ke tarike batane mein madad kar sakta hoon.\"),\n", " (\"Are you a real farmer?\", \"I'm not a farmer myself, but I've been trained on agricultural knowledge to help answer your farming questions as clearly as I can. For complex or unusual cases, I'd also recommend consulting your local agricultural extension officer.\"),\n", " (\"Can you tell me the weather?\", \"I don't have access to live weather data, but I can help you plan crop care around general weather patterns — like which diseases are more likely during monsoon or dry spells.\"),\n", " (\"Do you know about all crops?\", \"I have knowledge about common crops like apple, corn, grape, tomato, potato, and several others, especially their diseases and pests. If you tell me your crop, I'll do my best to help.\"),\n", "]\n", "for q, a in capability:\n", " conversational_data.append({\"instruction\": system_instruction, \"input\": q, \"output\": a})\n", "\n", "# 3. Gratitude / farewell\n", "gratitude = [\n", " (\"Thank you\", \"You're most welcome! Feel free to come back anytime you have a question about your crops.\"),\n", " (\"Thanks a lot AgriVani\", \"Happy to help! Good luck with your harvest.\"),\n", " (\"Dhanyavaad\", \"Aapka swagat hai! Jab bhi zaroorat ho, poochiye.\"),\n", " (\"Bahut madad mili, shukriya\", \"Khushi hui madad karke! Fasal achhi ho, yehi dua hai.\"),\n", " (\"Ok bye\", \"Take care, and all the best with your farming!\"),\n", " (\"Theek hai, phir milte hain\", \"Zaroor! Khushaal fasal ki shubhkamnayein.\"),\n", " (\"That was helpful, thanks\", \"Glad I could help! Let me know if anything else comes up.\"),\n", "]\n", "for q, a in gratitude:\n", " conversational_data.append({\"instruction\": system_instruction, \"input\": q, \"output\": a})\n", "\n", "# 4. Empathy for stress/frustration (important — farmers under real pressure)\n", "empathy = [\n", " (\"Mera pura fasal barbad ho gaya, kya karu?\", \"Yeh sunke bahut afsos hua. Pehle mujhe bataiye — kaunsi fasal hai aur patto/tano par kaisa nazar aa raha hai? Isse main sahi salaah de sakunga.\"),\n", " (\"I'm losing money because of this disease, please help fast\", \"I understand this is urgent and stressful. Tell me the crop and what you're seeing on the leaves or fruit, and I'll give you the fastest effective treatment option right away.\"),\n", " (\"This is the third year my crop has failed\", \"That's really tough to go through three years in a row. Let's figure out what's happening this time — what crop, and what symptoms are you seeing? We can also talk about prevention for next season.\"),\n", " (\"Mujhe kuch samajh nahi aa raha, sab kharab ho raha hai\", \"Ghabraiye mat, hum saath mein pata lagate hain. Mujhe thoda detail mein bataiye — kaunsi fasal hai, patto ka rang kaisa hai, aur kab se yeh dikh raha hai?\"),\n", " (\"I don't have much money to buy expensive pesticides\", \"That's completely understandable — many effective treatments don't need to be expensive. Tell me your crop and problem, and I'll prioritize low-cost or organic options for you.\"),\n", " (\"My father always managed the farm, I'm new to this\", \"Welcome to farming — it's a lot to take in at first, but you'll learn quickly. What's going on with your crop right now? I'll explain things step by step.\"),\n", "]\n", "for q, a in empathy:\n", " conversational_data.append({\"instruction\": system_instruction, \"input\": q, \"output\": a})\n", "\n", "# 5. Vague input needing clarification\n", "clarification = [\n", " (\"Mera paudha theek nahi hai\", \"Samajh gaya, lekin thoda aur bataiye — kaunsi fasal hai (jaise tamatar, aloo, seb), aur patto ya phal par kya dikh raha hai? Rang badal gaya hai, dhabbe hain, ya kuch aur?\"),\n", " (\"Something is wrong with my crop\", \"I'd like to help — could you tell me which crop it is, and describe what you're seeing? For example, spots on leaves, wilting, holes, or discoloration all point to different problems.\"),\n", " (\"Leaves are looking bad\", \"Got it — which crop are we talking about, and can you describe the leaves a bit more? Are there spots, a powdery coating, yellowing, curling, or holes?\"),\n", " (\"Kya karu meri fasal ke liye?\", \"Zaroor madad karunga — pehle yeh bataiye ki kaunsi fasal hai aur uspe kya samasya dikh rahi hai?\"),\n", " (\"Help me with pests\", \"Sure — which crop is affected, and what kind of damage are you seeing? Holes in leaves, chewed edges, or insects you can actually see on the plant?\"),\n", "]\n", "for q, a in clarification:\n", " conversational_data.append({\"instruction\": system_instruction, \"input\": q, \"output\": a})\n", "\n", "# 6. Off-topic redirect (politely stay in domain, but don't refuse rudely)\n", "off_topic = [\n", " (\"What's the capital of India?\", \"That's outside what I specialize in — I'm here to help with crop diseases, pests, and farming advice. Is there something about your crops I can help with?\"),\n", " (\"Tell me a joke\", \"I'll stick to farming advice for now, but I appreciate the fun request! If you've got a crop question, I'm all ears.\"),\n", " (\"What's the stock market doing today?\", \"I don't track market data, but if you're wondering about crop pricing decisions related to disease-damaged yield, I might be able to help think that through.\"),\n", " (\"Can you write me a poem?\", \"That's not really my specialty — I'm focused on helping with your farming questions. What's going on with your crops?\"),\n", "]\n", "for q, a in off_topic:\n", " conversational_data.append({\"instruction\": system_instruction, \"input\": q, \"output\": a})\n", "\n", "# 7. Feedback / correction handling\n", "feedback = [\n", " (\"That advice didn't work for me\", \"I'm sorry to hear that. Can you tell me what you tried and what happened? That'll help me suggest a better next step.\"),\n", " (\"Aapne jo bataya woh kaam nahi kiya\", \"Maaf kijiye, mujhe bataiye aapne kya try kiya tha aur result kya raha — main better solution dhoondne mein madad karunga.\"),\n", " (\"You're wrong about this\", \"Thanks for pointing that out — agriculture can vary a lot by region and conditions. Can you tell me more about what you're seeing so I can give better advice?\"),\n", " (\"That was really helpful advice\", \"I'm glad it helped! Let me know how it goes, and feel free to ask if anything changes.\"),\n", "]\n", "for q, a in feedback:\n", " conversational_data.append({\"instruction\": system_instruction, \"input\": q, \"output\": a})\n", "\n", "# 8. General farming context questions (not disease-specific)\n", "general_farming = [\n", " (\"Best time to plant tomatoes in North India?\", \"In North India, tomatoes are typically planted in two seasons: October-November (winter crop) and June-July (monsoon crop). Choose based on your region's climate and irrigation availability.\"),\n", " (\"How much water does wheat need?\", \"Wheat generally needs 4-6 irrigations depending on soil and climate — critical stages are crown root initiation, tillering, flowering, and grain filling. Avoid waterlogging.\"),\n", " (\"Kaunsi fasal kam paani mein achhi hoti hai?\", \"Bajra, jowar, moong, aur til jaisi fasalein kam paani mein bhi achhi ugti hain — yeh sookhe ilaakon ke liye behtar vikalp hain.\"),\n", " (\"What is crop rotation and why does it matter?\", \"Crop rotation means growing different types of crops in the same field across seasons. It helps break pest and disease cycles, improves soil fertility, and reduces the buildup of soil-borne pathogens.\"),\n", " (\"How do I test my soil?\", \"You can get a soil testing kit from your local agricultural extension office, or send a sample to a government soil testing lab. It'll tell you pH, nutrient levels (N-P-K), and organic matter content.\"),\n", " (\"Organic vs chemical fertilizer, which is better?\", \"Both have their place. Organic fertilizers (compost, vermicompost, FYM) improve long-term soil health and are budget-friendly if you produce your own. Chemical fertilizers act faster but need careful dosing to avoid soil degradation over time. Many farmers use a combination.\"),\n", "]\n", "for q, a in general_farming:\n", " conversational_data.append({\"instruction\": system_instruction, \"input\": q, \"output\": a})\n", "\n", "# 9. Follow-up conversational patterns\n", "followups = [\n", " (\"Ok, and how long will it take to see results?\", \"Most fungicide/bactericide treatments show visible improvement within 7-10 days if applied correctly and weather cooperates. Organic treatments may take slightly longer — usually 10-14 days.\"),\n", " (\"Is this safe for my animals?\", \"Most recommended treatments are safe once dried on the plant, but keep animals away during and right after spraying, and always follow the label's re-entry interval if using chemical products.\"),\n", " (\"Can I mix this with other pesticides?\", \"It's best not to mix products unless the label specifically confirms compatibility — mixing incompatible chemicals can reduce effectiveness or harm the crop. When in doubt, apply them a few days apart.\"),\n", " (\"How often should I spray?\", \"This depends on the specific product and disease severity, but a common approach is every 7-10 days during active disease pressure, then reducing frequency as symptoms improve.\"),\n", " (\"Will this affect my yield this season?\", \"Early treatment usually limits yield loss significantly. The sooner you act, the better your chances of protecting most of this season's harvest.\"),\n", "]\n", "for q, a in followups:\n", " conversational_data.append({\"instruction\": system_instruction, \"input\": q, \"output\": a})\n", "\n", "# 10. Extra Hinglish variety round (greetings/capability blended for volume + realism)\n", "extra_hinglish = [\n", " (\"Aap mujhe seb ke baare mein bata sakte ho?\", \"Bilkul! Seb (apple) mein aksar Apple Scab, Black Rot, ya Cedar Apple Rust jaisi bimariyan hoti hain. Aapko kya dikh raha hai apne ped mein?\"),\n", " (\"Mera makka (corn) kharab ho raha hai\", \"Samajh gaya — makke mein Common Rust, Northern Leaf Blight, ya Gray Leaf Spot jaisi samasyayein aam hain. Patto par kaisa nishaan dikh raha hai?\"),\n", " (\"Angoor ke bagiche mein samasya hai\", \"Angoor mein Black Rot, Esca, ya Leaf Blight ho sakta hai. Kya aap bata sakte hain patto ya phal par kya dikh raha hai?\"),\n", " (\"Santre ke ped peele pad rahe hain\", \"Yeh Citrus Greening (Huanglongbing) ka lakshan ho sakta hai — yeh ek gambhir bimari hai jiska koi ilaj nahi hai, lekin ussey failne se roka ja sakta hai. Kya patte assymetric roop se peele hain?\"),\n", " (\"Aaloo mein kuch dikh raha hai patto par\", \"Samajh gaya — aaloo mein Early Blight ya Late Blight ho sakta hai. Kya dhabbe gol hain concentric rings ke saath, ya paani-bhare hue dikh rahe hain?\"),\n", "]\n", "for q, a in extra_hinglish:\n", " conversational_data.append({\"instruction\": system_instruction, \"input\": q, \"output\": a})\n", "\n", "print(f\"Base conversational examples: {len(conversational_data)}\")\n", "\n", "# --- Augmentation pass: light rephrasing to expand coverage past 120+ ---\n", "openers_en = [\"\", \"Quick question — \", \"Just wondering, \", \"Can you tell me, \"]\n", "closers_en = [\"\", \" Please guide me.\", \" Thanks in advance.\", \" Let me know.\"]\n", "\n", "augmented = []\n", "for item in conversational_data:\n", " if random.random() < 0.55: # augment ~55% of entries to add volume without over-duplicating\n", " opener = random.choice(openers_en)\n", " closer = random.choice(closers_en)\n", " new_input = f\"{opener}{item['input'][0].lower() + item['input'][1:] if opener else item['input']}{closer}\"\n", " augmented.append({\"instruction\": system_instruction, \"input\": new_input, \"output\": item[\"output\"]})\n", "\n", "conversational_data.extend(augmented)\n", "random.shuffle(conversational_data)\n", "print(f\"✅ Final conversational dataset: {len(conversational_data)} examples\")\n", "\n", "with open('agrivani_conversational_data.json', 'w', encoding='utf-8') as f:\n", " json.dump(conversational_data, f, indent=2, ensure_ascii=False)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2026-09-02T10:07:15.980250Z", "iopub.status.busy": "2026-09-02T10:07:15.979877Z", "iopub.status.idle": "2026-09-02T10:07:15.996007Z", "shell.execute_reply": "2026-09-02T10:07:15.995081Z", "shell.execute_reply.started": "2026-09-02T10:07:15.980225Z" }, "trusted": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "✅ Final combined dataset: 467 examples\n", " - Original agri: 203\n", " - Expanded agri: 174\n", " - Conversational: 90\n" ] } ], "source": [ "import json, random\n", "\n", "with open('agriculture_training_data.json') as f:\n", " original_agri = json.load(f)\n", "with open('agrivani_expanded_agri_data.json') as f:\n", " expanded_agri = json.load(f)\n", "with open('agrivani_conversational_data.json') as f:\n", " conversational = json.load(f)\n", "\n", "combined = original_agri + expanded_agri + conversational\n", "random.shuffle(combined)\n", "\n", "with open('agrivani_final_training_data.json', 'w', encoding='utf-8') as f:\n", " json.dump(combined, f, indent=2, ensure_ascii=False)\n", "\n", "print(f\"✅ Final combined dataset: {len(combined)} examples\")\n", "print(f\" - Original agri: {len(original_agri)}\")\n", "print(f\" - Expanded agri: {len(expanded_agri)}\")\n", "print(f\" - Conversational: {len(conversational)}\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2026-09-02T10:07:21.970191Z", "iopub.status.busy": "2026-09-02T10:07:21.969326Z", "iopub.status.idle": "2026-09-02T10:07:26.657831Z", "shell.execute_reply": "2026-09-02T10:07:26.657116Z", "shell.execute_reply.started": "2026-09-02T10:07:21.970160Z" }, "trusted": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Visible GPU count: 1\n" ] } ], "source": [ "import os\n", "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"0\"\n", "\n", "import torch\n", "print(f\"Visible GPU count: {torch.cuda.device_count()}\") # should now print 1" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2026-09-02T10:07:40.647484Z", "iopub.status.busy": "2026-09-02T10:07:40.647098Z", "iopub.status.idle": "2026-09-02T11:08:10.159318Z", "shell.execute_reply": "2026-09-02T11:08:10.158640Z", "shell.execute_reply.started": "2026-09-02T10:07:40.647460Z" }, "trusted": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Skipping import of cpp extensions due to incompatible torch version. Please upgrade to torch >= 2.11.0 (found 2.10.0+cu128).\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "--- GEMMA 2B-IT QLORA FINE-TUNING START ---\n", "Dataset size: 467 examples\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5bb555d8443d46b08c6cc492d49149c4", "version_major": 2, "version_minor": 0 }, "text/plain": [ "config.json: 0%| | 0.00/627 [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "f452a3868a2f49b39636f99e0cac0776", "version_major": 2, "version_minor": 0 }, "text/plain": [ "tokenizer_config.json: 0.00B [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "4c007a2694e048b9a6bc8edf96b26615", "version_major": 2, "version_minor": 0 }, "text/plain": [ "tokenizer.json: 0%| | 0.00/17.5M [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "ad886b2a105d41478e15f289b94b876e", "version_major": 2, "version_minor": 0 }, "text/plain": [ "special_tokens_map.json: 0%| | 0.00/636 [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "86a7b8e889cf4eafae9d491147b1288f", "version_major": 2, "version_minor": 0 }, "text/plain": [ "model.safetensors.index.json: 0.00B [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "6447d94d9c044fd7abe296402ace17f2", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading (incomplete total...): 0.00B [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "e0c3672d04d247fca83be63230e28f71", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Fetching 2 files: 0%| | 0/2 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "e86556e4526d4e0a9fd73ee5f3be4825", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Loading weights: 0%| | 0/164 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "399b7bd8e1de4bccb055658a0756bdff", "version_major": 2, "version_minor": 0 }, "text/plain": [ "generation_config.json: 0%| | 0.00/137 [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "trainable params: 19,611,648 || all params: 2,525,784,064 || trainable%: 0.7765\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "775938ef53684bfab0009f4afa9b657b", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Adding EOS to train dataset: 0%| | 0/467 [00:00, ? examples/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "0628b017e9764f47988665b38c8474d6", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Tokenizing train dataset: 0%| | 0/467 [00:00, ? examples/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "58ff45d3d7ee46918db7510881283be5", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Truncating train dataset: 0%| | 0/467 [00:00, ? examples/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "The tokenizer has new PAD/BOS/EOS tokens that differ from the model config and generation config. The model config and generation config were aligned accordingly, being updated with the tokenizer's values. Updated tokens: {'pad_token_id': 1}.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Starting training...\n" ] }, { "data": { "text/html": [ "\n", "
| Step | \n", "Training Loss | \n", "
|---|---|
| 5 | \n", "4.553101 | \n", "
| 10 | \n", "4.322716 | \n", "
| 15 | \n", "4.555563 | \n", "
| 20 | \n", "4.363247 | \n", "
| 25 | \n", "4.431360 | \n", "
| 30 | \n", "4.363453 | \n", "
| 35 | \n", "4.369994 | \n", "
| 40 | \n", "4.460134 | \n", "
| 45 | \n", "4.410031 | \n", "
| 50 | \n", "4.423763 | \n", "
| 55 | \n", "4.532228 | \n", "
| 60 | \n", "4.500361 | \n", "
| 65 | \n", "4.430378 | \n", "
| 70 | \n", "4.460595 | \n", "
| 75 | \n", "4.560879 | \n", "
| 80 | \n", "4.505497 | \n", "
| 85 | \n", "4.414101 | \n", "
| 90 | \n", "4.439880 | \n", "
| 95 | \n", "4.400496 | \n", "
| 100 | \n", "4.333587 | \n", "
| 105 | \n", "4.334829 | \n", "
| 110 | \n", "4.445845 | \n", "
| 115 | \n", "4.457384 | \n", "
| 120 | \n", "4.374336 | \n", "
| 125 | \n", "4.478313 | \n", "
| 130 | \n", "4.326891 | \n", "
| 135 | \n", "4.243887 | \n", "
| 140 | \n", "4.373573 | \n", "
| 145 | \n", "4.594180 | \n", "
| 150 | \n", "4.458669 | \n", "
| 155 | \n", "4.558271 | \n", "
| 160 | \n", "4.499374 | \n", "
| 165 | \n", "4.453758 | \n", "
| 170 | \n", "4.421059 | \n", "
| 175 | \n", "4.480963 | \n", "
| 180 | \n", "4.445738 | \n", "
| 185 | \n", "4.351519 | \n", "
| 190 | \n", "4.453698 | \n", "
| 195 | \n", "4.342197 | \n", "
| 200 | \n", "4.525570 | \n", "
| 205 | \n", "4.511033 | \n", "
| 210 | \n", "4.426330 | \n", "
| 215 | \n", "4.482001 | \n", "
| 220 | \n", "4.293271 | \n", "
| 225 | \n", "4.513672 | \n", "
| 230 | \n", "4.417222 | \n", "
| 235 | \n", "4.451628 | \n", "
| 240 | \n", "4.382831 | \n", "
| 245 | \n", "4.423153 | \n", "
| 250 | \n", "4.394794 | \n", "
| 255 | \n", "4.397120 | \n", "
| 260 | \n", "4.380727 | \n", "
| 265 | \n", "4.468753 | \n", "
| 270 | \n", "4.439137 | \n", "
| 275 | \n", "4.341325 | \n", "
| 280 | \n", "4.573659 | \n", "
| 285 | \n", "4.464004 | \n", "
| 290 | \n", "4.499251 | \n", "
| 295 | \n", "4.485838 | \n", "
"
],
"text/plain": [
"
"
],
"text/plain": [
"/kaggle/working/agrivani_gemma_2b_merged.zip"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import shutil\n",
"from IPython.display import FileLink\n",
"\n",
"# Compress the folder into a zip file\n",
"shutil.make_archive(\"agrivani_gemma_2b_merged\", 'zip', \"agrivani_gemma_2b_merged\")\n",
"\n",
"# Generate a direct download link\n",
"display(FileLink(\"agrivani_gemma_2b_merged.zip\"))"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"execution": {
"iopub.execute_input": "2026-09-02T12:10:57.371448Z",
"iopub.status.busy": "2026-09-02T12:10:57.370880Z",
"iopub.status.idle": "2026-09-02T12:11:42.087764Z",
"shell.execute_reply": "2026-09-02T12:11:42.086923Z",
"shell.execute_reply.started": "2026-09-02T12:10:57.371419Z"
},
"trusted": true
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6b581ec7a9cd46c182b44d7af07bc911",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Loading weights: 0%| | 0/164 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\n",
"\n",
"Input: My tomato plants have necrotic yellow rings that are turning reddish-brown. What is this and how do I treat it?\n",
"\n",
"Output: Hi there! I understand that you're facing some issues with your tomato plants. The necrotic yellow rings turning reddish-brown are likely caused by a combination of factors, including insufficient water, nutrient deficiencies, pests, and diseases.\n",
"\n",
"**Here's what you can do to address this:**\n",
"\n",
"**1. Assess the situation:**\n",
"\n",
"* **Observe the plants:** Check the size, shape, and location of the yellow rings.\n",
"* **Check the soil moisture:** Ensure the soil is well-hydrated, especially during hot weather.\n",
"* **Inspect the plant leaves:** Look for signs of pests or diseases.\n",
"\n",
"**2. Determine the cause:**\n",
"\n",
"* If the rings are small and isolated, it might be a case of nutrient deficiency.\n",
"* If the rings are larger and have a distinct border, it could be a sign of a pest infestation.\n",
"* If the rings are surrounded by green leaves, it might be a sign of fungal disease.\n",
"\n",
"**3. Implement a treatment plan:**\n",
"\n",
"* **For nutrient deficiency:**\n",
" * Apply a balanced fertilizer according to package instructions.\n",
" * Ensure proper drainage and avoid overwatering.\n",
"* **For pests:**\n",
" * Use organic pest control methods like insectic\n",
"\n",
"================================================================================\n",
"\n",
"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\n",
"\n",
"Input: I pulled up my potato plants and the roots have strange swelling-like malformations and tiny golden spots. What pest is doing this?\n",
"\n",
"Output: Dear farmer, the symptoms you described are caused by a fungal disease called Potato Spindle Tuber (PST). This disease is common in potato crops and can cause severe yield losses.\n",
"\n",
"**Here's what you can do to manage Potato Spindle Tuber:**\n",
"\n",
"**1. Remove and destroy infected plants:**\n",
"- Pull out the affected plants and burn them to prevent the spread of the disease to other plants.\n",
"- Avoid leaving the plant debris on the ground, as it can attract more pests and diseases.\n",
"\n",
"**2. Apply fungicides:**\n",
"- Use a fungicide specifically recommended for potato crops.\n",
"- Apply the fungicide according to the instructions on the label.\n",
"- Repeat the application every few days until the disease is controlled.\n",
"\n",
"**3. Use organic methods:**\n",
"- You can also manage Potato Spindle Tuber by using organic methods such as crop rotation, intercropping, and using beneficial insects.\n",
"- Crop rotation helps to break the life cycle of the disease.\n",
"- Intercropping with non-host plants can help to deter the potato beetle, a vector that transmits the disease.\n",
"- Beneficial insects can help to control the potato beetle and other pests that may be feeding on the potato plants.\n",
"\n",
"**4.\n",
"\n",
"================================================================================\n",
"\n",
"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\n",
"\n",
"Input: I want to avoid using chemical pesticides. How do I use traditional remedies like fermented buttermilk or jeevamrut?\n",
"\n",
"Output: Sure, here's a step-by-step guide on how to use traditional remedies like fermented buttermilk and jeevamrut for pest control:\n",
"\n",
"**Step 1: Preparation**\n",
"\n",
"* Wash and dry the affected area thoroughly.\n",
"* Remove any weeds or debris that might be harboring pests.\n",
"* Mix the traditional remedies according to the instructions provided by the elders or traditional practitioners.\n",
"\n",
"**Step 2: Application**\n",
"\n",
"* Apply the mixture to the affected area using a spray or directly to the leaves and stems.\n",
"* Ensure that the mixture is evenly distributed and does not leave any gaps.\n",
"* For Jeevamrut, dilute it with water and apply it as a spray or directly to the affected area.\n",
"\n",
"**Step 3: Observation**\n",
"\n",
"* Observe the area for signs of pest activity.\n",
"* Check the affected area daily for any signs of pests or diseases.\n",
"* If you notice any signs of pests, repeat the application of the remedies.\n",
"\n",
"**Step 4: Maintenance**\n",
"\n",
"* Continue applying the remedies regularly, as needed.\n",
"* Avoid overusing the remedies, as this can harm the environment and the crops.\n",
"* Use organic methods whenever possible.\n",
"\n",
"**Additional Tips:**\n",
"\n",
"*\n",
"\n",
"================================================================================\n",
"\n",
"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\n",
"\n",
"Input: How can I explain the benefits of digital farm tracking and data recording to an elder farmer who prefers traditional methods?\n",
"\n",
"Output:\n",
"\n",
"Dear Elder Farmer,\n",
"\n",
"I understand that you may be hesitant to embrace new technology, but I assure you that digital farm tracking and data recording are tools that can help you improve your farm's yield and profitability.\n",
"\n",
"**Here's how these tools can benefit you:**\n",
"\n",
"* **Increased efficiency:** You can track your crops' progress in real-time, allowing you to make informed decisions about planting, watering, and harvesting.\n",
"* **Reduced waste:** By identifying areas where you can save water and energy, you can optimize your resource usage.\n",
"* **Improved crop quality:** You can monitor the health of your crops and identify potential problems early on, leading to better yields.\n",
"* **Enhanced market access:** Digital records can help you connect directly with buyers, eliminating the need for middlemen and reducing your costs.\n",
"* **Financial management:** You can track your income and expenses, identify areas for improvement, and make informed financial decisions.\n",
"\n",
"**Here's how you can get started:**\n",
"\n",
"* **Start by investing in a basic smartphone or tablet.**\n",
"* **Download a digital farm tracking app or software.**\n",
"* **Create a profile and input your farm details.**\n",
"* **Use GPS to track the location of\n",
"\n",
"================================================================================\n",
"\n",
"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\n",
"\n",
"Input: It has been very humid lately. What cultural practices should I implement to prevent fungal diseases from spreading in my field?\n",
"\n",
"Output:\n",
"\n",
"Hey there, fellow farmer!\n",
"\n",
"The humid weather can definitely create a breeding ground for fungal diseases, so it's important to take some proactive steps to keep your crops healthy. Here are some cultural practices you can implement to prevent fungal diseases:\n",
"\n",
"**1. Early Detection:**\n",
"\n",
"* Regularly inspect your fields for signs of fungal diseases, such as wilting, yellowing, or browning leaves, stems, or fruits.\n",
"* Early detection is crucial for effective management.\n",
"\n",
"**2. Crop Rotation:**\n",
"\n",
"* Rotate your crops every 3-4 years. This helps break the disease cycle and reduces the build-up of fungal pathogens in the soil.\n",
"* Avoid planting the same crop in the same place for consecutive seasons.\n",
"\n",
"**3. Proper Spacing:**\n",
"\n",
"* Maintain adequate spacing between plants. This reduces the amount of moisture available for fungal growth and allows for proper air circulation.\n",
"* Avoid overcrowding, especially in humid conditions.\n",
"\n",
"**4. Mulching:**\n",
"\n",
"* Apply a 3-4 inch layer of organic mulch around your plants. Mulch helps retain moisture, suppress weeds, and suppress fungal spores from spreading.\n",
"* Different types of mulch have different benefits, so choose what best suits your soil and crop\n",
"\n",
"================================================================================\n",
"\n"
]
}
],
"source": [
"import torch\n",
"import gc\n",
"from transformers import AutoModelForCausalLM, AutoTokenizer\n",
"\n",
"# Clear any lingering allocations\n",
"torch.cuda.empty_cache()\n",
"gc.collect()\n",
"\n",
"# Load the merged model and tokenizer directly from disk\n",
"model_path = \"agrivani_gemma_2b_merged\"\n",
"tokenizer = AutoTokenizer.from_pretrained(model_path)\n",
"model = AutoModelForCausalLM.from_pretrained(\n",
" model_path,\n",
" device_map=\"cuda\",\n",
" torch_dtype=torch.float16\n",
")\n",
"\n",
"test_prompts = [\n",
" \"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\\n\\nInput: My tomato plants have necrotic yellow rings that are turning reddish-brown. What is this and how do I treat it?\\n\\nOutput:\",\n",
" \n",
" \"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\\n\\nInput: I pulled up my potato plants and the roots have strange swelling-like malformations and tiny golden spots. What pest is doing this?\\n\\nOutput:\",\n",
" \n",
" \"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\\n\\nInput: I want to avoid using chemical pesticides. How do I use traditional remedies like fermented buttermilk or jeevamrut?\\n\\nOutput:\",\n",
" \n",
" \"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\\n\\nInput: How can I explain the benefits of digital farm tracking and data recording to an elder farmer who prefers traditional methods?\\n\\nOutput:\",\n",
" \n",
" \"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\\n\\nInput: It has been very humid lately. What cultural practices should I implement to prevent fungal diseases from spreading in my field?\\n\\nOutput:\"\n",
"]\n",
"\n",
"for p in test_prompts:\n",
" inputs = tokenizer(p, return_tensors=\"pt\").to(\"cuda\")\n",
" out = model.generate(**inputs, max_new_tokens=250, do_sample=False)\n",
" print(tokenizer.decode(out[0], skip_special_tokens=True))\n",
" print(\"\\n\" + \"=\"*80 + \"\\n\")"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"execution": {
"iopub.execute_input": "2026-09-02T12:15:27.937903Z",
"iopub.status.busy": "2026-09-02T12:15:27.937256Z",
"iopub.status.idle": "2026-09-02T12:16:17.820891Z",
"shell.execute_reply": "2026-09-02T12:16:17.819836Z",
"shell.execute_reply.started": "2026-09-02T12:15:27.937872Z"
},
"trusted": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\n",
"\n",
"Input: Aloo ke patton par kaale aur bhoore dhabbe pad rahe hain aur kinare sukh rahe hain. Ye kaunsi bimari hai aur iska turant ilaj kya hai?\n",
"\n",
"Output:\n",
"\n",
"Hey there! It seems like your potato crop is facing some challenges. The lack of water and the dry soil might be affecting its growth. Here's some actionable advice to help you get your crop back on track:\n",
"\n",
"**1. Assess the situation:**\n",
"\n",
"* **Soil analysis:** Before taking any drastic measures, get your soil tested to understand its nutrient content and pH level. This will help you determine the best course of action.\n",
"* **Water management:** Check the soil moisture level and water your plants deeply when needed. Avoid overwatering, as this can lead to fungal diseases.\n",
"* **Mulching:** Apply a layer of mulch around your plants to retain moisture and suppress weeds.\n",
"\n",
"**2. Organic pest control:**\n",
"\n",
"* **Encourage natural predators:** Keep a garden of companion plants that attract beneficial insects and birds, which can help control pests naturally.\n",
"* **Use organic pesticides:** Opt for organic pesticides like neem oil, insecticidal soap, or compost tea to control pests without harming the environment or your health.\n",
"\n",
"**3. Timely intervention:**\n",
"\n",
"* **Monitor the soil moisture:** Regularly check the soil moisture level and water your plants when it gets dry.\n",
"* **Rotate your crops:** Avoid planting the same\n",
"\n",
"================================================================================\n",
"\n",
"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\n",
"\n",
"Input: टमाटर के फलों में छेद हो रहे हैं और अंदर कीड़े दिखाई दे रहे हैं। इसे जैविक तरीके से कैसे नियंत्रित करें?\n",
"\n",
"Output:\n",
"\n",
"Dear farmer,\n",
"\n",
"I understand that your tomatoes are suffering from holes in the fruit and the presence of small insects inside. Controlling such issues organically is possible.\n",
"\n",
"**Here's how you can help:**\n",
"\n",
"**1. Identify the cause:**\n",
"\n",
"* **Pests:** Check for aphids, whiteflies, or other pests that could be feeding on the tomatoes.\n",
"* **Diseases:** Observe for signs of diseases like blight, fungal infections, or bacterial diseases.\n",
"* **Environmental factors:** Ensure proper watering, adequate sunlight, and good air circulation around the plants.\n",
"\n",
"**2. Natural pest control methods:**\n",
"\n",
"* **Encourage natural predators:** Introduce beneficial insects like ladybugs, lacewings, or parasitic wasps to control pests.\n",
"* **Use organic insecticides:** Opt for natural solutions like neem oil, insecticidal soap, or homemade insecticidal concoctions.\n",
"* **Handpick pests:** Remove and destroy any visible pests from the affected areas.\n",
"\n",
"**3. Organic fertilizer application:**\n",
"\n",
"* **Use compost or manure:** Add compost or manure to the soil to improve its fertility and suppress pests.\n",
"* **Apply beneficial microbes:** Introduce beneficial microbes like Trichoderma or mycorrhizal fungi to improve soil health and plant nutrition.\n",
"\n",
"\n",
"\n",
"================================================================================\n",
"\n",
"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\n",
"\n",
"Input: Neem ke tel ka chhidkaw kaise banayein aur ek acre khet ke liye kitna dose lagta hai?\n",
"\n",
"Output:\n",
"\n",
"Dear farmer,\n",
"\n",
"Neem leaves are a natural fertilizer that can be used to improve the health and yield of your crops. However, it's important to use them judiciously to avoid harming the environment.\n",
"\n",
"**Here's how to use Neem leaves:**\n",
"\n",
"* Collect fresh neem leaves from healthy trees.\n",
"* Wash and dry the leaves thoroughly.\n",
"* Chop the leaves into small pieces.\n",
"* Sprinkle the chopped leaves on your fields at the base of the plants.\n",
"* Avoid applyingNeem leaves directly on the leaves of the plants.\n",
"* Water the plants thoroughly after applying Neem leaves.\n",
"\n",
"**Recommended Neem leaf dose:**\n",
"\n",
"* For an acre of land, you can use up to 1000 kg of Neem leaves.\n",
"\n",
"**Additional tips:**\n",
"\n",
"* Neem leaves are most effective when used during the early stages of crop growth.\n",
"* Avoid applying Neem leaves during hot weather.\n",
"* Neem leaves are safe for most crops, but it's always best to test them on a small area of land before applying them to a large area.\n",
"\n",
"By following these simple steps, you can use Neem leaves to improve the health and yield of your crops.\n",
"\n",
"================================================================================\n",
"\n",
"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\n",
"\n",
"Input: लगातार बारिश के बाद मिर्च के पौधों की पत्तियां पीली होकर गिर रही हैं। फफूंद से बचाव के लिए क्या उपाय करें?\n",
"\n",
"Output:\n",
"\n",
"Dear farmer,\n",
"\n",
"The frequent rainfall has caused the leaves of your chili plants to turn yellow and fall off. To save your plants, you can take the following steps:\n",
"\n",
"1. **Mulch around the base of the plants.** Mulch helps to retain moisture and suppress weeds, which can compete for nutrients and water.\n",
"2. **Provide adequate irrigation.** Water the plants deeply once a week, ensuring that the soil is completely saturated.\n",
"3. **Fertilize regularly.** Apply a balanced fertilizer according to the package instructions.\n",
"4. **Avoid overwatering.** Overwatering can lead to root rot and other diseases.\n",
"5. **Prune the affected leaves.** If the leaves are severely damaged, you can remove them to encourage new growth.\n",
"6. **Use organic pest control methods.** Avoid using chemical pesticides, which can harm the environment and your health.\n",
"\n",
"By following these steps, you can help to save your chili plants from the effects of the frequent rainfall.\n",
"\n",
"================================================================================\n",
"\n",
"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\n",
"\n",
"Input: Namaste AgriVani! Kharif season ke liye mitti ki taiyari kaise karein aur desi khad ka upyog kaise badhayein?\n",
"\n",
"Output: Namaste! Kharif mein khushbusi ki raftaar hai, aur ek baar mein har har aur ek ek aur ek ek aur ek ek ki khushbusi ki raftaar kar sakte hain. Ek baar mein har ek aur ek ek ki khushbusi ki raftaar karne mein har ek aur ek aur ek ek ki khushbusi ki raftaar karne mein har ek aur ek ki khushbusi ki raftaar karne mein har ek aur ek ki khushbusi ki raftaar karne mein har ek aur ek ki khushbusi ki raftaar karne mein har ek aur ek ki khushbusi ki raftaar karne mein har ek aur ek ki khushbusi ki raftaar karne mein har ek aur ek ki khushbusi ki raftaar karne mein har ek aur ek ki khushbusi ki raftaar karne mein har ek aur ek ki khushbusi ki raftaar karne mein har ek aur ek ki khushbusi ki raftaar karne mein har ek aur ek ki khushbusi ki raftaar karne mein har ek aur\n",
"\n",
"================================================================================\n",
"\n"
]
}
],
"source": [
"test_prompts_multilingual = [\n",
" # 1. Hinglish: Crop disease diagnosis (Potato Late Blight)\n",
" \"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\\n\\nInput: Aloo ke patton par kaale aur bhoore dhabbe pad rahe hain aur kinare sukh rahe hain. Ye kaunsi bimari hai aur iska turant ilaj kya hai?\\n\\nOutput:\",\n",
"\n",
" # 2. Devanagari Hindi: Pest infestation (Tomato Fruit Borer)\n",
" \"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\\n\\nInput: टमाटर के फलों में छेद हो रहे हैं और अंदर कीड़े दिखाई दे रहे हैं। इसे जैविक तरीके से कैसे नियंत्रित करें?\\n\\nOutput:\",\n",
"\n",
" # 3. Hinglish: Organic pesticide preparation (Neem oil spray)\n",
" \"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\\n\\nInput: Neem ke tel ka chhidkaw kaise banayein aur ek acre khet ke liye kitna dose lagta hai?\\n\\nOutput:\",\n",
"\n",
" # 4. Devanagari Hindi: Weather & fungal prevention (Excess moisture)\n",
" \"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\\n\\nInput: लगातार बारिश के बाद मिर्च के पौधों की पत्तियां पीली होकर गिर रही हैं। फफूंद से बचाव के लिए क्या उपाय करें?\\n\\nOutput:\",\n",
"\n",
" # 5. Hinglish: Conversational advisory (Soil fertility & sowing advice)\n",
" \"Instruction: You are AgriVani, an expert agricultural advisor for Indian farmers. Provide clear, actionable, and empathetic farming advice in simple language.\\n\\nInput: Namaste AgriVani! Kharif season ke liye mitti ki taiyari kaise karein aur desi khad ka upyog kaise badhayein?\\n\\nOutput:\"\n",
"]\n",
"\n",
"for p in test_prompts_multilingual:\n",
" inputs = tokenizer(p, return_tensors=\"pt\").to(\"cuda\")\n",
" out = model.generate(**inputs, max_new_tokens=250, do_sample=False)\n",
" print(tokenizer.decode(out[0], skip_special_tokens=True))\n",
" print(\"\\n\" + \"=\"*80 + \"\\n\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"trusted": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kaggle": {
"accelerator": "none",
"dataSources": [],
"dockerImageVersionId": 28755,
"isGpuEnabled": false,
"isInternetEnabled": false,
"language": "python",
"sourceType": "notebook"
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.13"
}
},
"nbformat": 4,
"nbformat_minor": 4
}