{"id":29894126,"url":"https://github.com/thepredictivedev/smart-agriculture-system-using-llms","last_synced_at":"2025-08-23T06:04:17.095Z","repository":{"id":307263300,"uuid":"1028889211","full_name":"ThePredictiveDev/Smart-Agriculture-System-Using-LLMs","owner":"ThePredictiveDev","description":"A comprehensive AI-powered agricultural analytics platform that provides real-time insights, predictions, and recommendations for smart farming using Large Language Models (LLMs).","archived":false,"fork":false,"pushed_at":"2025-07-30T08:53:53.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-30T10:46:12.126Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ThePredictiveDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-30T07:59:26.000Z","updated_at":"2025-07-30T08:55:14.000Z","dependencies_parsed_at":"2025-07-30T10:46:15.180Z","dependency_job_id":"d59228cf-40fe-447f-8adf-803a1664a039","html_url":"https://github.com/ThePredictiveDev/Smart-Agriculture-System-Using-LLMs","commit_stats":null,"previous_names":["thepredictivedev/smart-agriculture-system-using-llms"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/ThePredictiveDev/Smart-Agriculture-System-Using-LLMs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThePredictiveDev%2FSmart-Agriculture-System-Using-LLMs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThePredictiveDev%2FSmart-Agriculture-System-Using-LLMs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThePredictiveDev%2FSmart-Agriculture-System-Using-LLMs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThePredictiveDev%2FSmart-Agriculture-System-Using-LLMs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ThePredictiveDev","download_url":"https://codeload.github.com/ThePredictiveDev/Smart-Agriculture-System-Using-LLMs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThePredictiveDev%2FSmart-Agriculture-System-Using-LLMs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271745660,"owners_count":24813515,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-01T04:44:48.299Z","updated_at":"2025-08-23T06:04:17.061Z","avatar_url":"https://github.com/ThePredictiveDev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🌾 Smart Agriculture System Using LLMs\n\nA comprehensive AI-powered agricultural analytics platform that provides real-time insights, predictions, and recommendations for smart farming using Large Language Models (LLMs).\n\n## 🚀 Features\n\n### Core Analytics\n- **Real-time Sensor Data Analysis**: Processes temperature, humidity, soil moisture, and NPK values\n- **Weather Integration**: Live weather data from wttr.in for Mandi, Himachal Pradesh\n- **AI-Powered Predictions**: LLM-based recommendations for crop management\n- **Interactive Dashboard**: Modern, responsive UI with real-time visualizations\n\n### Prediction Capabilities\n- **Soil Analysis**: Soil type classification, fertilization status, and fertilizer recommendations\n- **Crop Management**: Optimal crop recommendations, harvest timing, and selling strategies\n- **Threat Detection**: Real-time pest and disease threat assessment\n- **Irrigation Guidance**: Smart irrigation recommendations based on soil moisture and weather\n\n### Interactive Features\n- **Keyboard Shortcuts**: Press keys (k, l, t, y, m, n, s, d) to simulate different sensor scenarios\n- **Multiple Query Modes**: All predictions, soil-specific, crop-specific, or custom prediction sets\n- **Enhanced Visualizations**: Trend charts, status badges, and AI recommendation displays\n- **Weather Forecasting**: 3-day weather forecast with visual indicators\n\n## 🛠️ Technology Stack\n\n- **Backend**: Python 3.11+\n- **AI/ML**: Groq API (DeepSeek R1 Distill Llama 70B)\n- **Web Framework**: Gradio\n- **Weather Data**: wttr.in API\n- **Caching**: requests-cache\n- **Data Processing**: JSON Schema validation\n\n## 📋 Prerequisites\n\n- Python 3.11 or higher\n- Groq API token\n- Internet connection for weather data and LLM API calls\n\n## 🔧 Installation\n\n1. **Clone the repository**\n   ```bash\n   git clone \u003crepository-url\u003e\n   cd Smart-Agriculture-System-Using-LLMS\n   ```\n\n2. **Install dependencies**\n   ```bash\n   pip install gradio requests requests-cache jsonschema\n   ```\n\n3. **Set up environment variables**\n   ```bash\n   # Set your Groq API token\n   export GROQ_API_TOKEN=\"your_groq_api_token_here\"\n   \n   # Optional: Set custom Groq API URL (defaults to https://api.groq.com/openai/v1/chat/completions)\n   export GROQ_API_URL=\"https://api.groq.com/openai/v1/chat/completions\"\n   ```\n\n## 🚀 Usage\n\n### Running the Application\n\n1. **Start the application**\n   ```bash\n   python dp_smart_agri.py\n   ```\n\n2. **Access the interface**\n   - The application will launch a local web server\n   - Open your browser to the provided URL\n   - For public access, the app will also generate a shareable link\n\n### Using the Interface\n\n#### Basic Operation\n1. **Select Query Mode**: Choose from available prediction modes\n2. **Configure Parameters**: Set specific predictions or advanced prompts if needed\n3. **Click \"Run\"**: Execute the analysis with current sensor and weather data\n\n#### Interactive Features\n- **Keyboard Shortcuts**: Press any of these keys to simulate different sensor scenarios:\n  - `k`, `l`: Different soil moisture levels (55%, 65%)\n  - `t`, `y`: Moderate NPK values with varying moisture\n  - `m`, `n`: Low NPK values with high moisture\n  - `s`, `d`: High NPK values with moderate moisture\n\n- **Manual Input**: Use the discrete input field at the bottom for custom sensor scenarios\n\n#### Dashboard Tabs\n- **Smart Dashboard**: Enhanced visualizations with charts, status badges, and AI recommendations\n- **Raw Data**: Detailed sensor data, weather information, and prediction results\n\n## 📊 Prediction Categories\n\n### Soil-Related Predictions\n- Soil type classification (Loamy, Clayey, Red)\n- Fertilization status (Over, Under, Optimal)\n- Fertilizer recommendations (N:P:K ratios)\n\n### Crop-Related Predictions\n- Crop recommendations based on conditions\n- Optimal harvest timing\n- Best selling periods\n\n### Threat Assessment\n- Possible pest identification\n- Real-time threat detection\n- Weather-related risks\n\n### Irrigation Management\n- Irrigation frequency recommendations\n- Water management strategies\n- Moisture-based guidance\n\n## 🔍 Data Sources\n\n### Sensor Data\n- **Temperature**: Field temperature in °C\n- **Humidity**: Ambient humidity percentage\n- **Soil Moisture**: Soil moisture content percentage\n- **NPK Values**: Nitrogen, Phosphorus, Potassium levels in ppm\n\n### Weather Data\n- **Current Conditions**: Temperature, humidity, wind speed, weather description\n- **Forecast**: 3-day weather predictions\n- **Location**: Mandi, Himachal Pradesh, India\n\n## 🎯 Use Cases\n\n### For Farmers\n- **Crop Planning**: Get AI recommendations for optimal crop selection\n- **Resource Management**: Optimize fertilizer and irrigation usage\n- **Risk Mitigation**: Early detection of potential threats\n- **Market Timing**: Optimal harvest and selling recommendations\n\n### For Agricultural Consultants\n- **Data Analysis**: Comprehensive soil and weather analysis\n- **Recommendation Engine**: AI-powered agricultural advice\n- **Monitoring**: Real-time field condition tracking\n\n### For Researchers\n- **Data Collection**: Structured agricultural data gathering\n- **Pattern Analysis**: Weather and soil correlation studies\n- **Model Validation**: LLM performance in agricultural contexts\n\n## 🔧 Configuration\n\n### Environment Variables\n```bash\nGROQ_API_TOKEN=your_token_here\nGROQ_API_URL=https://api.groq.com/openai/v1/chat/completions\n```\n\n### Model Configuration\n- **Default Model**: DeepSeek R1 Distill Llama 70B\n- **Temperature**: 0.7 (configurable)\n- **Top-p**: 0.5 (configurable)\n- **Max Retries**: 3 attempts with 3-second delays\n\n### Caching\n- **HTTP Cache**: 15-minute cache for weather data\n- **Cache Location**: `http_cache.sqlite`\n\n## 📈 Performance Features\n\n### Optimization\n- **Request Caching**: Reduces API calls and improves response times\n- **Error Handling**: Robust error recovery with fallback mechanisms\n- **Async Processing**: Non-blocking LLM API calls\n- **Memory Management**: Efficient data handling and cleanup\n\n### Monitoring\n- **Event Logging**: Key events logged to `key_events.log`\n- **Error Tracking**: Comprehensive error handling and reporting\n- **Performance Metrics**: Response time monitoring\n\n## 🛡️ Security \u0026 Privacy\n\n- **API Token Security**: Environment variable-based configuration\n- **Data Privacy**: No persistent storage of sensitive agricultural data\n- **Input Validation**: JSON schema validation for all LLM responses\n- **Error Sanitization**: Safe error message handling\n\n## 🔄 API Integration\n\n### Groq API\n- **Endpoint**: `https://api.groq.com/openai/v1/chat/completions`\n- **Authentication**: Bearer token\n- **Rate Limiting**: Built-in retry mechanism\n- **Response Format**: OpenAI-compatible JSON\n\n### Weather API\n- **Provider**: wttr.in\n- **Location**: Mandi, Himachal Pradesh\n- **Format**: JSON\n- **Update Frequency**: 15-minute cache\n\n## 🐛 Troubleshooting\n\n### Common Issues\n\n1. **API Token Error**\n   ```\n   Solution: Verify GROQ_API_TOKEN environment variable is set correctly\n   ```\n\n2. **Weather Data Unavailable**\n   ```\n   Solution: Check internet connection and wttr.in service status\n   ```\n\n3. **LLM Response Errors**\n   ```\n   Solution: Check API quota and model availability\n   ```\n\n4. **Port Conflicts**\n   ```\n   Solution: Gradio will automatically find an available port\n   ```\n\n### Debug Mode\nEnable detailed logging by checking the `key_events.log` file for system events and errors.\n\n## 📝 Development\n\n### Project Structure\n```\nSmart-Agriculture-System-Using-LLMS/\n├── dp_smart_agri.py          # Main application file\n├── http_cache.sqlite         # HTTP cache database\n├── key_events.log           # Event logging\n└── README.md               # This file\n```\n\n### Code Organization\n- **Configuration**: Environment variables and constants\n- **Data Processing**: Sensor and weather data handling\n- **AI Integration**: LLM API calls and response processing\n- **UI Components**: Gradio interface and visualizations\n- **Utilities**: Helper functions and formatters\n\n### Contributing\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Test thoroughly\n5. Submit a pull request\n\n## 📄 License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\n## 🤝 Support\n\nFor support and questions:\n- Create an issue in the repository\n- Check the troubleshooting section\n- Review the event logs for debugging information\n\n## 🔮 Future Enhancements\n\n- **Multi-location Support**: Expand beyond Mandi, Himachal Pradesh\n- **Historical Data**: Add data persistence and trend analysis\n- **Mobile App**: Native mobile application\n- **IoT Integration**: Direct sensor data integration\n- **Advanced Analytics**: Machine learning model integration\n- **Multi-language Support**: Localization for different regions\n\n---\n\n**Built with ❤️ for Smart Agriculture** ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthepredictivedev%2Fsmart-agriculture-system-using-llms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthepredictivedev%2Fsmart-agriculture-system-using-llms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthepredictivedev%2Fsmart-agriculture-system-using-llms/lists"}