Apr 29, 2024
Guide on How to Use Google Gemini Pro – Can I Run It Locally?
A simple and useful guide on how to use Google Gemini AI models, including the the most advanced Gemini 1.5 Pro.
What is Gemini AI?
Gemini is AI model developed by Google corporation. Gemini was created by various teams at Google, including those at Google Research. It's designed to be multimodal, meaning it can work with and blend different kinds of information like text, code, audio, images, and video. This allows it to understand and handle various types of data smoothly.
It's available in three versions (subject to change):
Gemini 1.0 Ultra: This initial version set new standards in various benchmarks, including text processing and coding.
Gemini Nano: Tailored for mobile devices, it comes in two versions: Nano-1 (1.8 billion parameters) and Nano-2 (3.25 billion parameters). It will is available to Android developers through Android AICore.
Gemini 1.5 Pro: The latest medium-sized model by Google AI that handles tasks involving text, images, videos, audio, and code. It features a long-context window that can process up to 1 million tokens, a significant leap from the 32,000 tokens of Gemini 1.0. This model was released to Google Cloud customers on AI Studio and Vertex AI in December 2023.
Gemini 1.5 Pro is particularly notable for its enhanced ability to handle large amounts of data from various sources. It can perform tasks such as extracting book titles from images and videos, summarizing extensive texts, and generating JSON data from code.
Access to Gemini AI
While it's not possible to run Gemini AI models locally without the internet, you can now use a top AI model from Google that does amazing things. It is readily available for you to use. You can set it up easily and run it right on your own computer.
Getting the Gemini API
First, you'll need an API key from Google. Go to Google's AI Page, find the Google Studio section, and click on "Get API key." Choose "Create your API key" in a new project, and you're ready to go.
Then, open your code editor (VScode, for example, might be a good choice) and set up a Python virtual environment in a new folder:
Create the virtual environment:
Now, create a file named
requirements.txt
and list these packages:
The google-generativeai
package lets you use Google's Gemini model, and streamlit
helps you build web apps easily.
Install the packages:
Paste your API key in a file named
.env
like this:
Now that everything is set up, you can start the fun part – coding!
There are two methods to implement this, let's look at both:
Method 1: Running Gemini with Python Notebook
This is the first way to run the Gemini AI locally on your computer.
Run the following steps in a Python notebook:
Import necessary packages:
Write a function to display text nicely:
Load your API key:
Check the available Gemini models:
Select a model you want to use:
Provide a prompt to the model to get the response:
To see the response in sections (chunks) or one line at a time:
Method 2: Run Gemini Using Streamlit
First, create a Python file named gemini.py
:
In this Streamlit application, you first retrieve the API key from a .env
file and load it into the GOOGLE_API_KEY
variable.
Then, you create a simple function called generate_content
that takes a user's input (prompt), passes it to the model, and then returns the text response.
In the Streamlit interface, there's a text input box provided by st.text_input
and a 'Generate' button. When you press the button, it calls the generate_content
function and displays the response text below the input field.
This is what you'll see in the Streamlit application when it's running.
Use Gemini 1.5 Pro with ChaLabs
We are happy to let you know that you can easily start using Google Gemini Models, including the latest Gemini 1.5 Pro, with our ChatLabs AI tool.
ChatLabs is advanced, easy-to-use platform that supports more than 30 most popular LLMs including GPT-4, Gemini 1.5, Llama 3, Mistral 8x22B, Claude Opus, and many others
To use all best AI models at one place, just go to https://labs.writingmate.ai and sign up.