File size: 3,653 Bytes
16c8745 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# πΎ AgriEdge: Smart Farm Assistant
An AI-powered assistant that uses real-time sensor data and textbook-based agricultural knowledge to provide insights, analysis, and actionable suggestions for small to medium-scale farms. Comes with both command-line and web interfaces.
---
## π Features
- π‘ Analyzes **real-time farm sensor data** (soil, water, environment)
- π Retrieves context from **agricultural PDF documents**
- π€ Uses **retrieval-augmented generation (RAG)** for grounded reasoning
- π§ Powered by **Ollama + LLaMA 3**
- π Generates **natural language summaries and actionable insights**
- π Runs **fully local** β no cloud, no data sharing
- π Supports **Streamlit-based dashboard** for non-technical users
---
## π Project Structure
```bash
smartfarm/
βββ main.py # Command-line interface
βββ app.py # Streamlit web app
βββ llm/
β βββ ollama_llm.py # Query handler using LLM + sensor data + RAG
β βββ rag_pipeline.py # PDF retrieval pipeline using FAISS
βββ logger.py # Logging setup
βββ prompt.txt # Prompt template for LLM
βββ data/
β βββ farm_data_log.json # JSON file logging sensor readings
β βββ docs/ # Agricultural PDFs for knowledge retrieval
β βββ faiss_index/ # Auto-generated FAISS vector index
```
---
## π οΈ Installation & Setup
### 1. Clone the Repository
```bash
git clone https://github.com/your-username/smartfarm.git
cd smartfarm
```
### 2. Install Python Dependencies
```bash
pip install -r requirements.txt
```
### 3. Set Up Ollama
Make sure you have Ollama installed and running.
Download the LLaMA 3 model:
```bash
ollama run llama3
```
Make sure Ollama is running in the background before using the assistant.
### 4. Add Sensor Data
Append new entries to `data/farm_data_log.json`. Example format:
```json
{
"timestamp": "2025-07-22T21:00:00+01:00",
"soil": {"moisture": "High", "pH": 6.8, "temperature": 24.9},
"water": {"pH": 7.2, "turbidity": "8 NTU", "temperature": 23.3},
"environment": {"humidity": "85%", "temperature": 26.0, "rainfall": "Moderate"}
}
```
### 5. Add Agricultural Documents (Optional)
Place your farming-related PDFs inside:
```bash
data/docs/
```
The system will automatically build a searchable vector index.
---
## βΆοΈ Usage
### π Command-Line Mode
```bash
python main.py
```
Youβll be prompted to enter queries like:
```markdown
> Is the soil suitable for planting now?
> Has the turbidity improved compared to earlier?
```
Type `exit` to quit.
### π Streamlit Web Interface
Launch the UI with:
```bash
streamlit run app.py
```
What you can do:
- View the most recent sensor snapshot
- Ask farm-related questions like:
- "What is the current soil condition?"
- "Is it safe to irrigate now?"
- "Has rainfall increased compared to earlier?"
---
## π‘ Notes
- The system analyzes only the most recent sensor reading but uses the previous 2 for historical comparison (internally).
- No internet connection is required once the vector store and model are set up.
- Logs are written automatically to `logs/`.
---
## π§ͺ Example Questions
- "Is the soil moisture improving?"
- "What is the overall environmental condition right now?"
- "Is the water quality good for irrigation?"
---
## π License
MIT License
|