Skip to content

Niikkhii/mini-ai

Repository files navigation

Google Drive Search AI Assistant

A production-ready full-stack AI application that provides a conversational interface to search files in a Google Drive folder using natural language queries.

Architecture

  • Frontend: Streamlit web application
  • Backend: FastAPI REST API
  • AI Framework: LangChain with Gemini LLM
  • Cloud Services: Google Drive API with Service Account authentication

Features

  • Natural language file search in Google Drive
  • Support for various search types:
    • Exact file name search
    • Partial file name search
    • MIME type filtering
    • Full-text content search
    • Modified date search
  • Conversational AI interface powered by Gemini
  • RESTful API for easy integration

Project Structure

project/
├── backend/
│   ├── main.py              # FastAPI application
│   ├── agent.py             # LangChain agent with Gemini
│   ├── drive_service.py     # Google Drive API service
│   ├── tools.py             # Search tools for the agent
│   ├── prompts.py           # System prompts
│   ├── requirements.txt     # Python dependencies
│   └── .env                 # Environment variables
├── frontend/
│   ├── app.py               # Streamlit application
│   └── requirements.txt     # Python dependencies
├── credentials/
│   └── service_account.json # Google Service Account key
└── README.md

Prerequisites

  • Python 3.8+
  • Google Cloud Project with Drive API enabled
  • Service Account with Drive API access
  • Gemini API key

Installation

1. Clone or Download the Project

cd /Users/nikhilcharantimath/Desktop/mini_ai

2. Set up Google Cloud Project

  1. Go to Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable the Google Drive API
  4. Create a Service Account:
    • Go to IAM & Admin > Service Accounts
    • Create a new service account
    • Grant it the "Editor" role (or create a custom role with Drive read access)
    • Create a JSON key and download it
  5. Share your Google Drive folder with the service account email

3. Configure Environment Variables

  1. Copy the downloaded JSON key to credentials/service_account.json
  2. Edit backend/.env:
    • Set GOOGLE_DRIVE_FOLDER_ID to your folder ID
    • Set GEMINI_API_KEY to your Gemini API key
    • Adjust HOST and PORT if needed

4. Install Backend Dependencies

cd backend
pip install -r requirements.txt

5. Install Frontend Dependencies

cd ../frontend
pip install -r requirements.txt

Running the Application

Start the Backend

cd backend
python main.py

The API will be available at http://localhost:8000

Start the Frontend

In a new terminal:

cd frontend
streamlit run app.py

The web interface will be available at http://localhost:8501

API Usage

Search Endpoint

POST /search
Content-Type: application/json

{
  "query": "find all PDF files modified today"
}

Response:

{
  "response": "Found 3 PDF files:\n- report.pdf (Modified: 2024-01-15)\n- document.pdf (Modified: 2024-01-15)\n..."
}

Search Query Examples

  • "find file named 'budget.xlsx'"
  • "find files containing 'meeting' in the name"
  • "find all PDF files"
  • "find Word documents modified today"
  • "find files with 'important' in the content"
  • "find recent spreadsheets"

Development

Backend Testing

cd backend
python -m pytest  # Add tests as needed

Frontend Development

The Streamlit app auto-reloads on code changes.

Security Notes

  • Never commit the credentials/service_account.json file
  • Keep your .env file secure
  • Use environment-specific service accounts
  • Regularly rotate service account keys

Troubleshooting

Common Issues

  1. "Invalid credentials": Check your service account JSON and folder sharing
  2. "API has not been used": Ensure Drive API is enabled in Google Cloud
  3. "Folder not found": Verify the GOOGLE_DRIVE_FOLDER_ID in .env
  4. "Gemini API error": Check your API key and quota

Logs

Check the terminal output for detailed error messages.

License

This project is for educational and demonstration purposes.

About

This project demonstrates a simplified version of how LLM-based systems work. Users can upload multiple PDFs to a drive, where the drive acts as a database. The system allows users to perform basic queries such as summarizing content, listing documents, and retrieving document names from the drive.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages