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](https://private-user-images.githubusercontent.com/35577566/328525310-156ae3e0-cffa-47a3-8a71-1bded78c4632.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTgxMjUzNjYsIm5iZiI6MTcxODEyNTA2NiwicGF0aCI6Ii8zNTU3NzU2Ni8zMjg1MjUzMTAtMTU2YWUzZTAtY2ZmYS00N2EzLThhNzEtMWJkZWQ3OGM0NjMyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjExVDE2NTc0NlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTM2MDg3Nzg2ZmI1MmMyZTFjODI1YWM3OTZhNGM5OWE0YzcxYzgyNTZjYjJiNDZiNDAxYTVmZWRhNjBhN2MxNGMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.7_TGoDVz0gFnPk8EDE2PVPde8Ljte0UdmPZI1x5Sgt4)
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 google.generativeai as genai
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)
-
If you don’t have Python installed, install it from Python.org.
-
Clone this repository.
-
Create a new virtual environment:
-
macOS:
$ python -m venv venv $ . venv/bin/activate
-
Windows:
> python -m venv venv > .\venv\Scripts\activate
-
-
Install the requirements:
$ pip install -r requirements.txt
-
Make a copy of the example environment variables file:
$ cp .env.example .env
-
Add your API key to the newly created
.env
file. -
Run the app:
$ flask run
You should now be able to access the app from your browser at the following URL: http://localhost:5000!
This repo includes code that was forked from another repo I made, under an MIT license.