AI-powered crop stress detection and intervention system using satellite data, weather forecasts, and soil analysis.
- ๐ฐ๏ธ Crop Health Analysis: NDVI/MLVI-based stress detection from Sentinel-2 satellite data
- โ๏ธ Weather Forecasting: Real-time weather predictions with OpenWeatherMap API
- ๐ฑ Soil Analysis: Moisture, nutrients, and pH monitoring
- ๐ค AI Assistant: Multilingual (Hindi/English) chat with voice input/output (โ WORKING NOW)
- ๐ก Smart Interventions: AI-powered farming recommendations
- ๐ Yield Prediction: Seasonal forecasting based on multiple factors
# Backend
npm install
# Frontend
cd frontend && npm install && cd ..# Copy example env file
cp .env.example .env
# For frontend (optional)
echo 'VITE_N8N_WEBHOOK_URL=https://n8n.pipfactor.com/webhook/apnaketh' > frontend/.env
echo 'VITE_GEMINI_API_KEY=your_key_here' >> frontend/.env# Terminal 1 - Backend
npm run dev
# Terminal 2 - Frontend (new terminal)
cd frontend && npm run dev- Open http://localhost:5173
- Click the green ๐ฑ button (bottom-right)
- Type: "What is NDVI?" or speak your question
- AI responds!
- Node.js 18+ and npm
- N8N Webhook for Gemini AI (optional, has fallback)
- API Keys (optional for full functionality):
- Google Gemini API
- Google Earth Engine (for satellite data)
- OpenWeatherMap API
Backend (.env):
# Backend Server
PORT=3001
NODE_ENV=development
# N8N Webhook (Primary AI endpoint)
N8N_WEBHOOK_URL=https://n8n.pipfactor.com/webhook/apnaketh
GEMINI_API_KEY=your_gemini_api_key_here
# Optional: For full satellite/weather integration
GOOGLE_EARTH_ENGINE_KEY=your_gee_key
OPENWEATHER_API_KEY=your_openweather_key
# Frontend URL
FRONTEND_URL=http://localhost:5173# Create frontend env file
touch frontend/.envAdd to frontend/.env:
VITE_N8N_WEBHOOK_URL=https://n8n.pipfactor.com/webhook/apnaketh
VITE_GEMINI_API_KEY=your_gemini_api_key_here# Terminal 1 - Backend API
npm run dev
# Terminal 2 - Frontend (in new terminal)
cd frontend
npm run dev# Build backend
npm run build
npm start
# Build frontend
cd frontend
npm run build
npm run preview- Frontend: http://localhost:5173
- Backend API: http://localhost:3001
- Health Check: http://localhost:3001/health
- API Services: http://localhost:3001/api/ai/services
POST /api/ai/chat
Content-Type: application/json
{
"query": "What is the health of my crop?",
"serviceType": "crop_analysis",
"context": {}
}POST /api/ai/crop/analyze
Content-Type: application/json
{
"fieldId": "field_123",
"coordinates": { "lat": 28.6139, "lng": 77.2090 },
"satelliteData": {}
}POST /api/ai/weather/forecast
Content-Type: application/json
{
"latitude": 28.6139,
"longitude": 77.2090,
"days": 7
}POST /api/ai/soil/analyze
Content-Type: application/json
{
"fieldId": "field_123",
"sensorData": {}
}POST /api/ai/interventions
Content-Type: application/json
{
"fieldId": "field_123",
"stressType": "water_stress",
"severity": "moderate"
}The AI assistant currently uses N8N as a middleware to Gemini. Configure your N8N workflow:
- Create a webhook trigger in N8N
- Add Gemini AI node with system prompt for agriculture
- Configure response to return JSON:
{ "text": "AI response here" }
Recommended System Prompt for Gemini:
You are an AI assistant for ApnaKeth, a smart agriculture platform for Indian farmers.
Respond in simple Hindi/English mix (Hinglish) that farmers can understand easily.
Provide practical advice about:
- Crop health and NDVI analysis
- Weather patterns and farming decisions
- Soil health and fertilizer recommendations
- Pest control and disease management
- Irrigation scheduling
Always be encouraging and helpful. Use emojis where appropriate.
Update src/controllers/ai.controller.ts โ analyzeCrop() method:
// TODO: Replace mock data with actual GEE API call
import ee from '@google/earthengine';
// Initialize Earth Engine
ee.initialize();
// Fetch Sentinel-2 data
const sentinel = ee.ImageCollection('COPERNICUS/S2')
.filterBounds(ee.Geometry.Point([longitude, latitude]))
.filterDate(startDate, endDate)
.sort('CLOUD_COVER');
// Calculate NDVI
const ndvi = sentinel.map(img =>
img.normalizedDifference(['B8', 'B4']).rename('NDVI')
);Update src/controllers/ai.controller.ts โ getWeatherForecast():
// TODO: Replace mock with actual OpenWeather API
const weatherUrl = `https://api.openweathermap.org/data/2.5/forecast?lat=${latitude}&lon=${longitude}&appid=${OPENWEATHER_API_KEY}`;
const response = await fetch(weatherUrl);
const weatherData = await response.json();For real-time soil data, integrate with IoT sensors:
- MQTT broker for sensor data
- WebSocket for real-time updates
- Database for historical trends
For advanced interventions, implement LangGraph agents:
import { StateGraph } from "@langchain/langgraph";
// Agent 1: Data Collection
// Agent 2: Analysis
// Agent 3: Recommendation GenerationAdd more Indian languages:
// Update speechToText.setLanguage() options:
- 'hi-IN' (Hindi)
- 'pa-IN' (Punjabi)
- 'mr-IN' (Marathi)
- 'bn-IN' (Bengali)
- 'ta-IN' (Tamil)- User authentication (farmer profiles)
- Field management (multiple fields per farmer)
- Historical data visualization
- Offline mode with PWA
- SMS alerts for critical issues
- Market price integration
- Crop disease image recognition
- Community forum
# Kill process on port 3001
lsof -ti:3001 | xargs kill -9
# Kill process on port 5173
lsof -ti:5173 | xargs kill -9- Ensure you're using Chrome/Edge/Safari
- Check microphone permissions
- Use HTTPS in production
- Verify webhook URL is correct
- Check N8N workflow is active
- Test with curl:
curl -X POST https://n8n.pipfactor.com/webhook/apnaketh \
-H "Content-Type: application/json" \
-d '{"query": "test", "sender": "test"}'This is a hackathon project by Team Hacksters for HackOrbital.
MIT License
- SIH ERP Clone (AI Assistant base architecture)
- N8N for workflow automation
- Google Gemini for AI capabilities
- Sentinel-2 for satellite imagery
Built with โค๏ธ for Indian Farmers by Team Hacksters ๐ฎ๐ณ๐พ
| Component | Status | File Location |
|---|---|---|
| AI Chat UI | โ Copied & Adapted | frontend/src/components/AIChat.tsx |
| Voice Input/Output | โ Working | frontend/src/utils/speechToText.ts |
| Orb Animation | โ Copied | frontend/src/components/Orb.tsx |
| AI Controller | โ Adapted for AgriScout | src/controllers/ai.controller.ts |
| N8N Integration | โ Ready (needs URL) | Throughout codebase |
| Gemini TTS | โ Implemented | AIChat.tsx (speakText) |
| UI Components | โ All copied | Button, Input, ScrollArea |
โ
Frontend Runs - cd frontend && npm run dev
โ
AI Chat Opens - Click green ๐ฑ button
โ
Beautiful UI - Glassmorphism, gradients, responsive
โ
Voice Input - Mic button records speech (Chrome/Safari)
โ
Multilingual Messages - Hindi/English mix
โ
Backend API - Mock data for testing
โ
Fallback System - Works even if N8N fails
โ N8N Webhook - Add URL to .env files
โ Gemini API Key - For voice responses
โ Real Satellite Data - Google Earth Engine (later)
โ Weather API - OpenWeatherMap (later)
But you can run and test everything else right now! ๐
Built for HackOrbital ๐ by Team Hacksters ๐ฎ๐ณ๐พ