An AI-powered conversational assistant that helps you search, filter, and discover files inside Google Drive using natural language queries.
- Natural Language Search β Ask questions like "Find finance PDFs from last week" and get results instantly
- AI-Powered Query Generation β Gemini LLM converts your words into precise Google Drive API queries
- Conversational Memory β Follow up on previous searches with context ("show only the Excel files")
- Rich File Cards β See file names, types, dates, sizes, and clickable Drive links
- Modern Chat UI β Dark theme with glassmorphism, animations, and responsive design
- Search History β Track and re-run previous searches from the sidebar
- Smart Filtering β Supports MIME types, date ranges, file names, and content search
| Query | What It Does |
|---|---|
| "Find finance PDFs from last week" | Searches PDFs with "finance" in the name, modified last week |
| "Show all images related to logo" | Finds JPEG/PNG/GIF/SVG files with "logo" in the name |
| "Find documents containing invoice" | Full-text content search for "invoice" across all documents |
| "Show spreadsheets uploaded this month" | Google Sheets + Excel files modified this month |
| "Find files named project report" | Name-based search for "project report" |
βββββββββββββββββββ ββββββββββββββββββββββββββββ ββββββββββββββββ
β Streamlit UI ββββββββΆβ FastAPI Backend ββββββββΆβ Google Drive β
β (Frontend) βββββββββ ββββββββββββββββββββ βββββββββ API v3 β
β β β β LangChain Agent β β β β
β β’ Chat bubbles β β β ββββββββββββββββ β β β β’ files.listβ
β β’ File cards β β β β DriveSearch β β β β β’ q param β
β β’ Search hist. β β β β Tool β β β β β
β β’ Loading UI β β β ββββββββββββββββ β β ββββββββββββββββ
βββββββββββββββββββ β ββββββββββββββββββββ β
β β² β ββββββββββββββββ
β β ββββββββΆβ Gemini AI β
β Conversation βββββββββ (LLM) β
β Memory β ββββββββββββββββ
ββββββββββββββββββββββββββββ
Tech Stack:
- Frontend: Streamlit with custom CSS
- Backend: FastAPI with async endpoints
- AI Framework: LangChain with tool calling
- LLM: Gemini 2.0 Flash (via
langchain-google-genai) - Drive API: Google Drive API v3 with Service Account auth
- Python 3.11+
- Google Cloud Project with Drive API enabled
- Service Account with Drive read access
- Gemini API Key from Google AI Studio
git clone https://github.com/your-username/drive-discovery-assistant.git
cd drive-discovery-assistant
# Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/Mac
# or
venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt# Copy the example env file
cp .env.example .envEdit .env with your credentials:
GOOGLE_API_KEY=your_gemini_api_key_here
GOOGLE_SERVICE_ACCOUNT_FILE=path/to/service-account.json
GOOGLE_DRIVE_FOLDER_ID=your_folder_id_here # Optionalπ Step-by-step Google Cloud setup
-
Go to Google Cloud Console
-
Create a new project (or select an existing one)
-
Enable Google Drive API:
- Go to "APIs & Services" β "Enable APIs and Services"
- Search for "Google Drive API"
- Click "Enable"
-
Create a Service Account:
- Go to "APIs & Services" β "Credentials"
- Click "Create Credentials" β "Service Account"
- Give it a name (e.g., "drive-discovery")
- Click "Done"
-
Create a JSON key:
- Click on the service account you just created
- Go to "Keys" tab
- Click "Add Key" β "Create new key" β "JSON"
- Download the JSON file and save it in your project directory
-
Share your Drive folder:
- Open Google Drive
- Right-click the folder you want to search
- Click "Share"
- Add the service account email (e.g.,
drive-discovery@your-project.iam.gserviceaccount.com) - Give it "Viewer" access
-
Get the folder ID (optional):
- Open the folder in Google Drive
- Copy the ID from the URL:
https://drive.google.com/drive/folders/FOLDER_ID_HERE - Add it to
.envasGOOGLE_DRIVE_FOLDER_ID
Open two terminals from the project root:
Terminal 1 β Backend:
# Linux/Mac (with venv activated)
source venv/bin/activate
uvicorn backend.main:app --reload
# Windows (without activating venv)
.\venv\Scripts\uvicorn.exe backend.main:app --reload
# Windows (with venv activated)
venv\Scripts\activate
uvicorn backend.main:app --reloadTerminal 2 β Frontend:
# Linux/Mac (with venv activated)
source venv/bin/activate
streamlit run frontend/app.py
# Windows (without activating venv)
.\venv\Scripts\streamlit.exe run frontend/app.py
# Windows (with venv activated)
venv\Scripts\activate
streamlit run frontend/app.pyOpen your browser at http://localhost:8501 and start searching! π
conversational_AI_agent/
βββ backend/
β βββ __init__.py
β βββ main.py # FastAPI app with endpoints
β βββ config.py # Environment variable handling
β βββ models/
β β βββ schemas.py # Pydantic request/response models
β βββ services/
β β βββ drive_service.py # Google Drive API wrapper
β β βββ agent_service.py # LangChain agent orchestration
β βββ tools/
β β βββ drive_search_tool.py # Custom LangChain DriveSearchTool
β βββ prompts/
β β βββ system_prompts.py # AI system prompts
β βββ utils/
β βββ logger.py # Structured logging
β βββ mime_types.py # MIME type mappings
β βββ date_utils.py # Date utility functions
βββ frontend/
β βββ app.py # Streamlit main app
β βββ components/
β β βββ chat_ui.py # Chat interface components
β β βββ file_card.py # File result card component
β β βββ sidebar.py # Sidebar with search history
β βββ styles/
β β βββ custom.css # Custom CSS (dark theme)
β βββ utils/
β βββ api_client.py # FastAPI HTTP client
βββ .env.example
βββ .gitignore
βββ requirements.txt
βββ Procfile
βββ Dockerfile.backend
βββ Dockerfile.frontend
βββ docker-compose.yml
βββ render.yaml
βββ railway.toml
βββ README.md
Once the backend is running, visit:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
| Method | Path | Description |
|---|---|---|
GET |
/health |
Health check |
POST |
/api/chat |
Process a natural language query |
GET |
/api/history/{session_id} |
Get search history |
DELETE |
/api/session/{session_id} |
Clear session memory |
POST /api/chat
{
"query": "Find finance PDFs from last week",
"session_id": "abc-123"
}{
"message": "I found 3 finance PDFs from last week!",
"files": [
{
"id": "1BxiMVs...",
"name": "Q4 Finance Report.pdf",
"mime_type": "application/pdf",
"modified_time": "2026-05-10T14:30:00.000Z",
"web_view_link": "https://drive.google.com/file/d/1BxiMVs.../view",
"size": "2048576"
}
],
"query_used": "name contains 'finance' and mimeType='application/pdf' and modifiedTime > '2026-05-04T00:00:00Z' and trashed = false",
"session_id": "abc-123"
}- Push your code to GitHub
- Go to Railway and create a new project
- Connect your GitHub repo
- Deploy Backend: Create a service with start command:
uvicorn backend.main:app --host 0.0.0.0 --port $PORT - Deploy Frontend: Create another service with start command:
streamlit run frontend/app.py --server.port $PORT --server.address 0.0.0.0 --server.headless true - Set environment variables in Railway's dashboard
- Set
BACKEND_URLin the frontend service to your backend service URL
- Push your code to GitHub
- Go to Render and use the
render.yamlblueprint:render blueprint deploy
- Or manually create two web services (backend + frontend)
- Set environment variables in the Render dashboard
# Build and run both services
docker compose up --build
# Backend: http://localhost:8000
# Frontend: http://localhost:8501- Deploy the backend on Railway/Render
- Deploy the frontend on Streamlit Cloud
- Set
BACKEND_URLto your deployed backend URL in Streamlit Cloud secrets
| Variable | Required | Default | Description |
|---|---|---|---|
GOOGLE_API_KEY |
β | β | Gemini API key from Google AI Studio |
GOOGLE_SERVICE_ACCOUNT_FILE |
β | β | Path to service account JSON (or JSON string) |
GOOGLE_DRIVE_FOLDER_ID |
β | β | Restrict search to a specific folder |
GEMINI_MODEL |
β | gemini-2.0-flash |
Gemini model name |
BACKEND_URL |
β | http://localhost:8000 |
Backend API URL (for frontend) |
BACKEND_HOST |
β | 0.0.0.0 |
Backend bind host |
BACKEND_PORT |
β | 8000 |
Backend bind port |
LOG_LEVEL |
β | INFO |
Logging level |
- User sends a query via the Streamlit chat interface
- Frontend sends HTTP POST to FastAPI backend
/api/chat - FastAPI passes the query to the LangChain agent
- Gemini LLM interprets the natural language query
- LLM generates a Drive API
qparameter and callsDriveSearchTool - DriveSearchTool executes
files.listagainst Google Drive API v3 - Results flow back through the agent to FastAPI to Streamlit
- Streamlit renders file cards with metadata and Drive links
The LangChain agent maintains conversational memory per session, so follow-up queries like "show only the PDFs" work naturally.
| Issue | Solution |
|---|---|
| "Cannot connect to backend" | Make sure the backend is running (uvicorn backend.main:app --reload) |
| "Agent not initialized" | Check your .env file β GOOGLE_API_KEY and GOOGLE_SERVICE_ACCOUNT_FILE are required |
| "Invalid service account" | Verify your service account JSON file path is correct |
| "No files found" | Make sure you've shared the Drive folder with your service account email |
| "Rate limit errors" | The backend has built-in retry logic, but consider reducing query frequency |
MIT License β see LICENSE for details.
Built with β€οΈ using FastAPI, LangChain, Gemini, and Streamlit.