Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ Note: Backend and frontend must be running simultaneously for proper functionali
## 🌟 Core Features

- 🌾 Crop Recommendation
- 🌿 Fertilizer Recommendation
- 📉 Yield Prediction
- 🔬 Disease Detection
- � **AI Chatbot** - Platform guidance & agriculture support
Expand Down Expand Up @@ -226,6 +227,7 @@ AGRITECH/
│ ├── 📁 css/ # Stylesheets
│ └── 📁 js/ # Client-side scripts
├── 📁 Crop Recommendation/ # 🌾 Crop recommendation module
├── 📁 Fertiliser Recommendation System/ # 🌿 Fertilizer recommendation ML module
├── 📁 Disease Prediction/ # 🔬 Disease detection module
├── 📁 Crop Yield Prediction/ # 📊 Yield forecasting module
├── 📁 Community/ # 💬 community/forum backend
Expand Down
61 changes: 41 additions & 20 deletions disease.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ const loading = document.getElementById("loading");
const resultsDiv = document.getElementById("results");

let selectedFile = null;
let uploadInProgress = false;
let fileSelectionToken = 0;

// File upload handling
uploadArea.addEventListener("click", () => fileInput.click());
Expand Down Expand Up @@ -308,7 +310,7 @@ fileInput.addEventListener("change", (e) => {

// Analysis function
analyzeBtn.addEventListener("click", async () => {
if (!selectedFile) return;
if (uploadInProgress || !selectedFile) return;

loading.style.display = "block";
resultsDiv.innerHTML = "";
Expand Down Expand Up @@ -470,40 +472,59 @@ function validateImage(file) {
return true;
}

function readPreviewDataUrl(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();

reader.onload = (event) => resolve(event.target.result);
reader.onerror = () => reject(new Error("Error loading image preview."));
reader.readAsDataURL(file);
});
}

// Enhanced file handling with validation
function handleFileSelect(file) {
async function handleFileSelect(file) {
const currentSelectionToken = ++fileSelectionToken;

try {
validateImage(file);
selectedFile = file;
uploadInProgress = true;
selectedFile = null;
analyzeBtn.disabled = true;

previewContainer.innerHTML = '<div class="spinner"></div>';

const reader = new FileReader();
reader.onload = (e) => {
previewContainer.innerHTML = `<img src="${e.target.result}" alt="Plant preview" class="preview-image">`;
analyzeBtn.disabled = false;
resultsDiv.innerHTML = "";
document.getElementById("downloadPdfBtn").style.display = "none";
const previewDataUrl = await readPreviewDataUrl(file);

document.getElementById("modelStatus").innerHTML =
"🔍 Image loaded - Ready for analysis";
document.getElementById("modelStatus").className =
"status-indicator status-warning";
};
if (currentSelectionToken !== fileSelectionToken) {
return;
}

selectedFile = file;
previewContainer.innerHTML = `<img src="${previewDataUrl}" alt="Plant preview" class="preview-image">`;
resultsDiv.innerHTML = "";
document.getElementById("downloadPdfBtn").style.display = "none";

reader.onerror = () => {
previewContainer.innerHTML =
'<div class="no-results">❌ Error loading image</div>';
selectedFile = null;
};
document.getElementById("modelStatus").innerHTML =
"🔍 Image loaded - Ready for analysis";
document.getElementById("modelStatus").className =
"status-indicator status-warning";

reader.readAsDataURL(file);
analyzeBtn.disabled = false;
} catch (error) {
if (currentSelectionToken !== fileSelectionToken) {
return;
}

alert(error.message);
previewContainer.innerHTML =
'<div class="no-results">📷 Upload an image to get started</div>';
selectedFile = null;
analyzeBtn.disabled = true;
} finally {
if (currentSelectionToken === fileSelectionToken) {
uploadInProgress = false;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions domain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ This directory defines shared domain contracts used across AgriTech.

## Current Schemas
- Crop
- FertilizerRecommendationInput
- FertilizerRecommendation
- GrowthStage
- SoilData
- PredictionResult
Expand Down
79 changes: 79 additions & 0 deletions domain/fertilizer.schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Fertilizer recommendation schema
*/

export const FertilizerRecommendationInputSchema = {
$id: "FertilizerRecommendationInput",
type: "object",
required: [
"temperature",
"humidity",
"moisture",
"soilType",
"cropType",
"nitrogen",
"phosphorous",
"potassium"
],
additionalProperties: false,
properties: {
temperature: {
type: "number",
description: "Ambient temperature in degrees Celsius"
},
humidity: {
type: "number",
description: "Relative humidity percentage"
},
moisture: {
type: "number",
description: "Soil moisture percentage"
},
soilType: {
type: "string",
description: "Categorical soil type"
},
cropType: {
type: "string",
description: "Categorical crop type"
},
nitrogen: {
type: "number",
description: "Nitrogen content"
},
phosphorous: {
type: "number",
description: "Phosphorous content"
},
potassium: {
type: "number",
description: "Potassium content"
}
}
};

export const FertilizerRecommendationSchema = {
$id: "FertilizerRecommendation",
type: "object",
required: ["fertilizerName", "confidence", "inputs"],
additionalProperties: false,
properties: {
fertilizerName: {
type: "string",
description: "Recommended fertilizer label"
},
confidence: {
type: "number",
description: "Prediction confidence score (0-1)"
},
inputs: FertilizerRecommendationInputSchema,
modelVersion: {
type: "string",
description: "Version of the fertilizer recommendation model"
},
createdAt: {
type: "string",
description: "ISO timestamp when the recommendation was generated"
}
}
};
5 changes: 5 additions & 0 deletions domain/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { CropSchema } from "./crop.schema.js";
import { FertilizerRecommendationInputSchema, FertilizerRecommendationSchema } from "./fertilizer.schema.js";
import { GrowthStageSchema } from "./growthStage.schema.js";
import { PredictionResultSchema } from "./prediction.schema.js";
import { SoilDataSchema } from "./soil.schema.js";

export {
CropSchema,
FertilizerRecommendationInputSchema,
FertilizerRecommendationSchema,
GrowthStageSchema,
PredictionResultSchema,
SoilDataSchema
};

export const DomainSchemas = {
Crop: CropSchema,
FertilizerRecommendationInput: FertilizerRecommendationInputSchema,
FertilizerRecommendation: FertilizerRecommendationSchema,
GrowthStage: GrowthStageSchema,
PredictionResult: PredictionResultSchema,
SoilData: SoilDataSchema
Expand Down
4 changes: 4 additions & 0 deletions domain/validate.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import {
CropSchema,
FertilizerRecommendationInputSchema,
FertilizerRecommendationSchema,
GrowthStageSchema,
PredictionResultSchema,
SoilDataSchema
} from "./index.js";

const schemaMap = {
Crop: CropSchema,
FertilizerRecommendationInput: FertilizerRecommendationInputSchema,
FertilizerRecommendation: FertilizerRecommendationSchema,
GrowthStage: GrowthStageSchema,
PredictionResult: PredictionResultSchema,
SoilData: SoilDataSchema
Expand Down
Loading