Skip to content

mohammed97ashraf/LLM_Agri_Bot

Repository files navigation

Krishi Sahayak

AI Agriculture Assistant for Indian Farmers

Python Flask Groq License Deploy uv

Live Demo → llm-agri-bot.onrender.com

An AI-powered agriculture chatbot that helps Indian farmers with crop advice, pest control, soil health, weather, and government schemes — using text, voice, and image analysis.


Krishi Sahayak — Web Interface


Features

Feature Description
Text Chat Ask any agriculture question and get expert answers
Image Diagnosis Upload a crop photo → AI identifies diseases, pests & deficiencies
Voice Input Speak in English, Hindi, or Hinglish via Groq Whisper
Voice Output Bot reads answers aloud using Groq Orpheus TTS
Conversation Memory Remembers your chat context (Redis, with in-memory fallback)
Prompt Caching 50% cost savings — cached prefixes across requests
Dark/Light Theme Glassmorphism UI with one-click theme toggle
Multilingual Responds in English, Hindi, or Hinglish

Krishi Sahayak — Voice Chat on Mobile


Tech Stack

Backend Python 3.11+, Flask, Groq SDK
Frontend HTML5, CSS3 (Glassmorphism), jQuery
LLM openai/gpt-oss-120b (text), meta-llama/llama-4-scout-17b-16e-instruct (vision)
Speech Groq Whisper whisper-large-v3-turbo (STT), Groq Orpheus canopylabs/orpheus-v1-english (TTS)
Memory Redis (with automatic in-memory fallback)
Deploy Render, Docker, Gunicorn

Quick Start

Prerequisites

1. Clone & Install

git clone https://github.com/mohammed97ashraf/LLM_Agri_Bot.git
cd LLM_Agri_Bot
uv sync

2. Configure

cp .env.example LLM_Agri_Bot/.env

Edit LLM_Agri_Bot/.env and add your Groq API key:

GROQ_API_KEY=gsk_your_key_here

3. Run

uv run python LLM_Agri_Bot/run.py

Open http://127.0.0.1:5000


Environment Variables

Copy .env.example to LLM_Agri_Bot/.env and configure:

Variable Required Default Description
GROQ_API_KEY Yes Your Groq API key (get one)
LLM_MODEL No openai/gpt-oss-120b Text LLM model
LLM_VISION_MODEL No meta-llama/llama-4-scout-17b-16e-instruct Vision LLM model
LLM_TEMPERATURE No 0.3 Model temperature (0–2)
LLM_MAX_TOKENS No 2048 Max response tokens
STT_MODEL No whisper-large-v3-turbo Speech-to-text model
TTS_MODEL No canopylabs/orpheus-v1-english Text-to-speech model
TTS_VOICE No autumn TTS voice name
REDIS_HOST No localhost Redis host (optional — falls back to memory)
REDIS_PORT No 6379 Redis port
REDIS_SSL No false Enable Redis SSL
FLASK_SECRET_KEY Yes* dev-secret-key Flask session secret (*required in production)
FLASK_DEBUG No true Enable debug mode

Project Structure

LLM_Agri_Bot/
├── app/
│   ├── __init__.py             # App factory (create_app)
│   ├── config.py               # Environment-based configuration
│   ├── routes/
│   │   ├── main.py             # Index page, robots.txt, sitemap, llms.txt
│   │   └── chat.py             # Chat API (text, voice, image)
│   ├── services/
│   │   ├── llm_service.py      # Groq LLM + vision + prompt caching
│   │   ├── memory_service.py   # Redis + in-memory fallback
│   │   ├── stt_service.py      # Groq Whisper STT
│   │   ├── tts_service.py      # Groq Orpheus TTS
│   │   └── prompt_manager.py   # XML + CoT system prompt
│   ├── static/
│   │   ├── css/style.css       # Glassmorphism UI (dark/light)
│   │   ├── js/chat.js          # Chat logic, image upload, voice
│   │   └── images/             # Favicon
│   └── templates/
│       └── index.html          # Main template (SEO + JSON-LD)
├── Sample_image/               # Screenshots for README
├── llms.txt                    # AI crawler disclosure
├── .env.example                # Environment template
├── gunicorn.conf.py            # Production Gunicorn config
├── Dockerfile                  # Docker deployment
├── render.yaml                 # Render blueprint
├── run.py                      # Dev entry point
├── pyproject.toml              # uv / project config
└── requirements.txt            # pip fallback

Deployment

Render (Recommended)

  1. Push your code to GitHub
  2. Go to render.comNewWeb Service
  3. Connect your GitHub repo
  4. Render auto-detects render.yaml and Dockerfile
  5. Add your GROQ_API_KEY (and other env vars) in the Render dashboard
  6. Click Deploy

Docker

docker build -t krishi-sahayak .
docker run -p 10000:10000 --env-file LLM_Agri_Bot/.env krishi-sahayak

API Reference

Method Endpoint Description
GET / Chat interface
POST /chat Send text, image, or audio — returns AI response
POST /chat/clear Clear conversation history
GET /health Health check (Redis status)
GET /robots.txt Search engine crawl rules
GET /sitemap.xml XML sitemap
GET /llms.txt AI crawler disclosure
GET /.well-known/llms.txt AI crawler disclosure (well-known path)

How It Works

User sends message (text / image / voice)
        │
        ▼
┌─────────────────────────────────────────┐
│  Flask Backend                          │
│  ├── Text? → Groq LLM (gpt-oss-120b)  │
│  ├── Image? → Llama 4 Scout (vision)   │
│  └── Voice? → Whisper STT → LLM → TTS  │
│                                         │
│  Memory: Redis (or in-memory fallback)  │
│  Cache:  Groq automatic prompt caching  │
└─────────────────────────────────────────┘
        │
        ▼
Response with text + optional voice audio

Contributing

Contributions welcome! See CONTRIBUTING.md.

git checkout -b feature/your-feature
uv sync
# make changes
git commit -m "Add your feature"
git push origin feature/your-feature

License

MIT License — see LICENSE


Built with care for Indian farmers

By Mohammed Ashraf · GitHub · LinkedIn

About

This Chatbot helps farmers make informed decisions by leveraging the power of LLM Model from OpenAI.

Topics

Resources

License

Code of conduct

Contributing

Stars

43 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors