A powerful Retrieval-Augmented Generation (RAG) system built with FastAPI and Google's Gemini AI. Upload your documents and ask questions - the AI will answer based on your content!
- What is this project?
- Prerequisites
- Installation
- Getting Your Gemini API Key
- Setting Up Environment Variables
- Running the Application
- How to Use
This is a RAG (Retrieval-Augmented Generation) chatbot that:
- Lets you upload PDF or text files
- Stores the content in a smart way (using embeddings)
- Answers your questions based on the uploaded documents
- Remembers your conversation history
Before you begin, make sure you have:
- Python 3.9 or higher installed on your computer
- A Google Account (to get the Gemini API key)
- Git (optional, for cloning the repo)
Option A: Using Git
git clone https://github.com/yeschirag/Build-with-AI-GDG
cd build-with-aiOption B: Download ZIP
- Click the green "Code" button on GitHub
- Select "Download ZIP"
- Extract the ZIP file to a folder on your computer
Navigate to the project folder:
cd path/to/your/project/folderOn Windows:
python -m venv venv
venv\Scripts\activateOn Mac/Linux:
python3 -m venv venv
source venv/bin/activateRun this command to install all dependencies:
pip install -r requirements.txtWait for all packages to install. This may take a few minutes.
Follow these simple steps to get your FREE Gemini API key from Google AI Studio:
Open your browser and go to: https://aistudio.google.com/
- Click "Sign in" (top right corner)
- Sign in with your Google Account
-
Once signed in, click on "Get API Key" in the left sidebar (or look for it on the main page)
-
Click "Create API Key"
-
If asked, select a Google Cloud project or create a new one (it's free!)
-
Your API key will be generated and displayed on the screen
-
IMPORTANT: Copy the API key and save it somewhere safe! It looks something like this:
AIzaSyB1234567890abcdefghijklmnop
- Keep your API key secret! Don't share it publicly or commit it to GitHub
- The free tier gives you plenty of requests to learn and experiment
- If you lose your key, you can always create a new one
You need to create a .env file to store your API key securely.
In your project folder, create a new file named .env (just .env, no other name before it)
On Windows:
- Open Notepad
- Save the file as
.envin your project folder - Make sure to select "All Files" in the "Save as type" dropdown
On Mac/Linux:
touch .envOpen the .env file and add this line:
GOOGLE_API_KEY=your_api_key_hereReplace your_api_key_here with your actual Gemini API key.
GOOGLE_API_KEY=AIzaSyB1234567890abcdefghijklmnopSave the .env file and close it.
| Variable Name | Description | Required |
|---|---|---|
GOOGLE_API_KEY |
Your Gemini API key from Google AI Studio | β Yes |
Run this command in your terminal:
uvicorn main:app --reloadYou should see output like this:
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [xxxxx]
INFO: Started server process [xxxxx]
INFO: Waiting for application startup.
INFO: Application startup complete.
- Open your web browser
- Go to: http://127.0.0.1:8000 or http://localhost:8000
- You should see the RAG System interface!
Press CTRL + C in the terminal
- Upload Documents: Click the upload button and select your PDF or text files
- Wait for Processing: The system will process and index your documents
- Ask Questions: Type your questions in the chat box
- Get AI Answers: The AI will respond based on your uploaded documents!
- Make sure your
.envfile is in the same folder asmain.py - Check that the variable name is exactly
GOOGLE_API_KEY - Restart the server after creating/editing the
.envfile
- Make sure you ran
pip install -r requirements.txt - Check that your virtual environment is activated
- Verify you copied the entire key
- Make sure there are no extra spaces
- Try generating a new key from Google AI Studio
build-with-ai/
βββ main.py # Backend server code
βββ index.html # Frontend interface
βββ requirements.txt # Python dependencies
βββ .env # Your environment variables (create this!)
βββ README.md # This file
If you run into any issues:
- Double-check all the steps above
- Make sure all files are in the correct location
- Verify your API key is correct
If you have any questions or face any errors, feel free to reach out:
Email: chirag.k24@iiits.in
Happy Learning! π