Skip to content

Get up and running in under 5 minutes with the Google AI Gemini API (in Python)

License

Notifications You must be signed in to change notification settings

tnvmadhav/gemini-api-quickstart

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gemini API Quickstart - Python

This repository contains a simple Python Flask App running with the Google AI Gemini API, designed to get you started building with Gemini's multi-modal capabilities. The app comes with a basic UI and a Flask backend.

Screenshot 2024-05-07 at 7 42 28 AM

Basic request

To send your first API request with the Gemini API Python SDK, make sure you have the right dependencies installed (see installation steps below) and then run the following code:

import os
import google.generativeai as genai

GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")

genai.configure(api_key=GOOGLE_API_KEY)
model = genai.GenerativeModel('gemini-pro')

chat = model.start_chat(history=[])
response = chat.send_message("In one sentence, explain how AI works to a child.")
# Note that the chat object is temporarily stateful, as you send messages and get responses, you can 
# see the history changing by doing `chat.history`.

print(response.text)

Setup

  1. If you don’t have Python installed, install it from Python.org.

  2. Clone this repository.

  3. Create a new virtual environment:

    • macOS:

      $ python -m venv venv
      $ . venv/bin/activate
    • Windows:

      > python -m venv venv
      > .\venv\Scripts\activate
  4. Install the requirements:

    $ pip install -r requirements.txt
  5. Make a copy of the example environment variables file:

    $ cp .env.example .env
  6. Add your API key to the newly created .env file.

  7. Run the app:

$ flask run

You should now be able to access the app from your browser at the following URL: http://localhost:5000!

Attribution

This repo includes code that was forked from another repo I made, under an MIT license.

About

Get up and running in under 5 minutes with the Google AI Gemini API (in Python)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 46.8%
  • CSS 37.0%
  • Python 16.2%