Skip to content

Aarshpatel12/Farmfinadvisor_

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Krishi Financial Advisor API 🚜

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.


✨ Features

  • 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 Dockerfile for easy containerization and deployment on cloud platforms like Google Cloud Run.
  • Interactive API: Built with FastAPI, providing automatic, interactive API documentation (via Swagger UI).

🛠️ Tech Stack

  • Backend: Python, FastAPI
  • AI/ML: Google Generative AI (Gemini), LangChain, Sentence Transformers
  • Database: ChromaDB (Vector Store)
  • Geolocation: Geopy
  • Deployment: Docker

📂 Project Structure

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

🔌 API Endpoints

Get Financial Advisory

  • 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..."
    }

🌐 CORS Configuration

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)

🚀 Getting Started

Follow these steps to set up and run the project locally.

Prerequisites

  • Python 3.9+
  • A Google API Key with the "Generative Language API" enabled.

1. Clone the Repository

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

2. Set Up Environment

  1. 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
  2. Install dependencies:
    pip install -r requirements.txt
  3. Create an environment file: Create a file named .env in the project root and add your Google API key:
    GOOGLE_API_KEY="your_google_api_key_here"

3. Run the API Server

Start the FastAPI server with Uvicorn:

uvicorn main:app --reload

The API will be live at http://127.0.0.1:8000.

4. Test the API

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published