A Streamlit application that allows users to upload files, include them in prompts, and interact with the Google Gemini API to chat with their documents. The app supports placeholder processing in prompts and maintains uploaded files across sessions. It makes use of Gemini's 1m token context windows and its ability to work with complex file types, natively, without having to parse them to text.
- Features
- Prerequisites
- Installation
- Getting a Google Gemini API Key
- Setting Up the Environment Variables
- Running the App
- Usage
- Files in the Repository
- Customization
- Troubleshooting
- License
- File Upload and Management: Upload multiple files (e.g., PDFs) and manage them with checkboxes to include or exclude them from prompts.
- Persistent File Storage: Uploaded files are stored and fetched from the Google Gemini API, persisting across sessions.
- Customizable Prompts: Use an external JSON file (
prompt_notebooklm.json
) to specify the model, temperature, max tokens, and prompt messages. - Placeholder Processing: Support for placeholders in prompts, such as including file contents and current datetime.
- Interactive Chat Interface: A user-friendly chat interface built with Streamlit, maintaining conversation history.
- Python 3.7 or higher
- Pipenv or
pip
for dependency management - A Google Gemini API key from Google AI Studio
-
Clone the Repository
git clone https://github.com/chrisboden/geminotes.git cd geminotes
-
Create a Virtual Environment and Install Dependencies
You can use
pip
for dependency management.pip install -r requirements.txt
-
Sign Up for Google Cloud Platform (GCP)
If you don't already have a GCP account, sign up at https://cloud.google.com/.
-
Enable the Google Gemini API
- Navigate to the Google Cloud Console.
- Select or create a new project.
- Enable the Google Gemini API for your project.
-
Obtain an API Key
- Get your api key from Google AI Studio
-
Open the
.env
FileOpen the
.env
file in the root directory of the project. -
Add Your API Key
Replace
YOUR_GOOGLE_API_KEY
with your actual Google Gemini API key.GOOGLE_API_KEY=YOUR_GOOGLE_API_KEY
Run the Streamlit app using the following command:
streamlit run app.py
This will start the app on http://localhost:8501/
. Open this URL in your web browser to access the app.
-
Uploading Files
- In the sidebar, drag and drop your files into the file uploader.
- The files will be uploaded to the Google Gemini API immediately.
- Previously uploaded files are fetched and displayed when the app loads.
-
Selecting Files
- After uploading, select the files you want to include in the prompt using the checkboxes.
- By default, all newly uploaded files are selected.
-
Interacting with the Chatbot
- Type your question into the chat input at the bottom of the main content area.
- The assistant will respond based on the content of the selected files and the prompt configuration.
-
Clearing Chat History
- Use the Clear Chat History button in the sidebar to reset the conversation.
app.py
: The main Streamlit application script.prompt.json
: A JSON file containing the prompt configuration, model settings, and messages.prompt_utils.py
: A utility module for processing placeholders in the prompt, such as file inclusions and datetime..env_copy
: A template for the environment variables file. Rename to.env
and add your gemini api keyrequirements.txt
: A list of Python dependencies required to run the app.README.md
: Documentation and instructions for the app.me/example_aboutme.md
: An example file that can be included in prompts using placeholders.
You can do your prompt engineering in the system instructions in the prompt.json file. It includes the ability to 'include' or pull in content from other files to build out your prompt, eg custom instructions, about me, etc
- Edit
prompt.json
to adjust the model parameters and system prompts. - Placeholders:
- Include files in the prompt using
<$path/to/file$>
. - Insert the current datetime using
<$datetime:%Y-%m-%d$>
.
- Include files in the prompt using
- Place files you want to include via placeholders in the appropriate directories.
- Ensure the file paths in the placeholders are correct relative to the project's root directory.
- Model Name: You can change the
"model"
field inprompt.json
to use a different Gemini model. - Temperature: Optional: djust the
"temperature"
field to control the randomness of the model's output. - Max Tokens: Optional: et the
"max_tokens"
field to control the maximum length of the generated response.
- API Key Errors: Ensure your Google Gemini API key is correctly set in the
.env
file. - File Upload Issues: Verify that your files are supported by the Google Gemini API and are within size limits.
- Placeholder Errors: Check that file paths in placeholders are correct and that files exist.
- Module Not Found: Install all dependencies using
pip install -r requirements.txt
. - App Crashes or Exceptions: Review the error messages in the console for details and ensure all configurations are correct.