How to Get Started with Gemini Pro: Building AI Applications with Large Language Models

Manan Garg
4 min readDec 24, 2023

--

In the rapidly advancing field of artificial intelligence, the utilization of Large Language Models (LLMs) has become pivotal for developers and enterprise customers seeking to empower their applications with advanced capabilities. Google DeepMind’s Gemini stands out as a versatile and powerful LLM, capable of understanding and interacting with diverse types of information, including text, code, audio, image, and video. This blog will guide you through the process of getting started with Gemini Pro, exploring its features, understanding its significance, and building a simple application that demonstrates its capabilities.

By Google DeepMind — Logo may be based here, Public Domain, https://commons.wikimedia.org/w/index.php?curid=140305521

Importance of Building AI Applications with LLMs

Large Language Models (LLMs) form the backbone of many AI applications, enabling them to comprehend and process information in a manner similar to human understanding. The significance lies in their ability to generalize and seamlessly combine different modalities of data. Gemini, developed by Google DeepMind, is a testament to the progress in this direction.

https://deepmind.google/

Introducing Gemini: A Multimodal AI Powerhouse

Gemini represents the culmination of large-scale collaborative efforts across Google teams, including Google Research. This model is designed to be multimodal, meaning it can understand and operate across different types of information, such as text, code, audio, image, and video. Its flexibility allows it to efficiently run on various platforms, from data centers to mobile devices.

https://deepmind.google/technologies/gemini/#capabilities

Pricing and Availability — Gemini Pro

As of now, Gemini Pro is freely available for exploration. However, it’s important to note that a pay-as-you-go pricing model will be introduced in the future. For detailed pricing information and updates, visit the official pricing page.

Gemini API Pricing | Google AI for Developers

Let’s build our first LLM application!

Below is the step-by-step tutorial on creating your first Language Model (LLM) application using the powerful Gemini Pro model from Google GenerativeAI and the Streamlit library. By the end of this tutorial, you’ll have a functional web application that generates technical documentation for your code with just a few clicks. Let’s get started!

Prerequisites

Before we begin, make sure you have the following installed:

  • Python (version 3.10 or higher)
  • Pip (Python package installer)
  • A code editor of your choice (e.g., VSCode, PyCharm)

Step 1: Setup Your Development Environment

Create a new directory for your project and navigate to it using your terminal or command prompt.

mkdir LLM_Project
cd LLM_Project

Step 2: Install Dependencies

Create a virtual environment to manage your project dependencies and install the required libraries.

python -m venv my_env
source my_venv/bin/activate # On Windows, use 'venv\Scripts\activate'
pip install streamlit google-generativeai

Step 3: Obtain Gemini Pro API Key

Visit Google Makersuite to obtain your Gemini Pro API Key.

Step 4: Create the Streamlit App

Now, let’s create the main application file, app.py. Open your code editor and create a new file with the following content:

# Import necessary libraries
import streamlit as st
import google.generativeai as genai

# Initialize Streamlit app
st.set_page_config(page_title="Create Technical Documentation")
st.header("Create Technical Documentation")

# Sidebar for Gemini Pro API Key input
with st.sidebar:
# Input for Gemini Pro API Key
gemini_api_key = st.text_input("Gemini Pro API Key", key="api_key", type="password")
# Link to obtain Gemini Pro API Key
"[Get a Gemini Pro API key](https://makersuite.google.com/u/2/app/apikey)"

# Function to load Gemini Pro model and get responses
def get_gemini_response(question):
# Configure Gemini API
genai.configure(api_key=gemini_api_key)
# Initialize Gemini Pro model
model = genai.GenerativeModel('gemini-pro')
# Generate content using the model
response = model.generate_content(question)
return response.text

# Text area for user input
input = st.text_area("Input your code here: ", key="input", height=250)

# Button to generate documentation
submit = st.button("Generate Documentation")

# If the generate documentation button is clicked
if submit:
# Check if Gemini Pro API key is provided
if not gemini_api_key:
st.info("Please add your Gemini Pro API key to continue.")
st.stop()

# Create a prompt for the Gemini model
prompt = "Create a technical documentation for the code: " + input
# Get Gemini's response based on the prompt
response = get_gemini_response(prompt)

# Display the generated documentation
st.write(response)

Step 5: Run Your Application Locally

Save the app.py file and run the Streamlit app locally in your terminal or command prompt:

streamlit run app.py

Your default web browser should open with the Streamlit app running. Enter your Gemini Pro API Key in the sidebar and your code in the text area, click the “Generate Documentation” button.

Congratulations! You’ve just built your first LLM application with Gemini Pro and Streamlit. Feel free to explore and customize the app further based on your needs.

Github Link for the codebase

Streamlit Link for the application

Create Technical Documentation · Streamlit (llm-project-create-technical-documentation.streamlit.app)

Conclusion

In this tutorial, we covered the entire process of setting up your development environment, installing dependencies, obtaining a Gemini Pro API Key, creating the Streamlit app, and running it locally. You can now use this foundation to build more sophisticated LLM applications or customize this one for different use cases.

Happy coding! 😊

--

--

Manan Garg
Manan Garg

Written by Manan Garg

Passionate about building innovative AI solutions! Experienced in Gen AI, LLMs, Data Science, Machine and Deep Learning models. Let's shape the future together!