AgriEdge / README.md
timflash's picture
7 files uploaded
16c8745 verified

🌾 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

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

git clone https://github.com/your-username/smartfarm.git
cd smartfarm

2. Install Python Dependencies

pip install -r requirements.txt

3. Set Up Ollama

Make sure you have Ollama installed and running.

Download the LLaMA 3 model:

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:

{
  "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:

data/docs/

The system will automatically build a searchable vector index.


▢️ Usage

πŸ“Ÿ Command-Line Mode

python main.py

You’ll be prompted to enter queries like:

> 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:

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