A smart financial advisor for farmers in India, powered by Google's Gemini model and a RAG (Retrieval-Augmented Generation) pipeline. This API provides tailored financial advice on agricultural loans and government schemes based on a farmer's specific goals and location.
- Smart Financial Advice: Leverages Google's Gemini-1.5-Flash model to generate clear, concise, and relevant financial proposals.
- Location-Aware: Uses reverse geocoding to identify the farmer's state, enabling state-specific scheme recommendations.
- Pre-built Knowledge Base: Comes with a pre-built Chroma vector database, allowing the API to work out-of-the-box.
- Ready for Deployment: Includes a
Dockerfilefor easy containerization and deployment on cloud platforms like Google Cloud Run. - Interactive API: Built with FastAPI, providing automatic, interactive API documentation (via Swagger UI).
- Backend: Python, FastAPI
- AI/ML: Google Generative AI (Gemini), LangChain, Sentence Transformers
- Database: ChromaDB (Vector Store)
- Geolocation: Geopy
- Deployment: Docker
The repository is organized as follows:
.
├── chroma_db/ # Pre-built vector database
├── .gitignore # Specifies files for Git to ignore
├── Dockerfile # Instructions for building the Docker container
├── main.py # FastAPI application entrypoint and RAG logic
├── readme.md # This documentation file
└── requirements.txt # Python project dependencies
- Endpoint:
POST /financial_advisory/ - Description: Accepts a farmer's goal and location, then returns a detailed financial proposal generated by a RAG pipeline with Google's Gemini model.
- Request Body:
{ "goal": "I need a loan of around 5 lakhs to buy a new tractor.", "latitude": 30.9010, "longitude": 75.8573 } - Success Response:
{ "advisory": "Based on your goal to purchase a tractor in Punjab, the best option is the Kisan Credit Card (KCC) scheme..." }
The API is configured with Cross-Origin Resource Sharing (CORS) to allow requests from specific frontend applications. The following origins are permitted to access the API:
http://localhost:5173(for local frontend development)https://krishisetu-a6f6f.web.app(for the deployed production frontend)
Follow these steps to set up and run the project locally.
- Python 3.9+
- A Google API Key with the "Generative Language API" enabled.
git clone https://github.com/your-username/financial_advisor.git
cd financial_advisor- Create and activate a virtual environment:
# For macOS/Linux python3 -m venv venv source venv/bin/activate # For Windows python -m venv venv venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Create an environment file:
Create a file named
.envin the project root and add your Google API key:GOOGLE_API_KEY="your_google_api_key_here"
Start the FastAPI server with Uvicorn:
uvicorn main:app --reloadThe API will be live at http://127.0.0.1:8000.
Once the server is running, open your browser and navigate to http://127.0.0.1:8000/docs. You will see the interactive FastAPI documentation where you can test the /financial_advisory endpoint directly.