Skip to main content

A Python package for creating Gradio applications with Google Gemini models

Project description

gemini-gradio

is a Python package that makes it very easy for developers to create machine learning apps that are powered by Google's Gemini API.

Installation

  1. Clone the repository:
git clone https://github.com/AK391/gemini-gradio.git
  1. Navigate to the project directory:
cd gemini-gradio
  1. Install the package in editable mode:
pip install -e .

Basic Usage

You'll need to set up your Gemini API key first:

export GEMINI_API_KEY=<your token>

Then in a Python file, write:

import gradio as gr
import gemini_gradio

gr.load(
    name='gemini-1.5-pro-002',
    src=gemini_gradio.registry,
).launch()

Run the Python file, and you should see a Gradio Interface connected to the Gemini model!

ChatInterface

Customization

Once you can create a Gradio UI from a Gemini endpoint, you can customize it by setting your own input and output components, or any other arguments to gr.Interface. For example, the screenshot below was generated with:

import gradio as gr
import gemini_gradio

gr.load(
    name='gemini-1.5-pro-002',
    src=gemini_gradio.registry,
    title='Gemini-Gradio Integration',
    description="Chat with Gemini Pro model.",
    examples=["Explain quantum gravity to a 5-year old.", "How many R are there in the word Strawberry?"]
).launch()

ChatInterface with customizations

Composition

Or use your loaded Interface within larger Gradio Web UIs, e.g.

import gradio as gr
import gemini_gradio

with gr.Blocks() as demo:
    with gr.Tab("Gemini Pro"):
        gr.load('gemini-1.5-pro-002', src=gemini_gradio.registry)
    with gr.Tab("gemini-1.5-flash"):
        gr.load('gemini-1.5-flash', src=gemini_gradio.registry)

demo.launch()

Under the Hood

The gemini-gradio Python library has two dependencies: google-generativeai and gradio. It defines a "registry" function gemini_gradio.registry, which takes in a model name and returns a Gradio app.

Supported Models in Gemini

All chat API models supported by Google's Gemini are compatible with this integration. For a comprehensive list of available models and their specifications, please refer to the Google AI Studio documentation.


Note: if you are getting an authentication error, then the Gemini API Client is not able to get the API token from the environment variable. You can set it in your Python session like this:

import os

os.environ["GEMINI_API_KEY"] = ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gemini_gradio-0.0.1.tar.gz (114.8 kB view details)

Uploaded Source

Built Distribution

gemini_gradio-0.0.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file gemini_gradio-0.0.1.tar.gz.

File metadata

  • Download URL: gemini_gradio-0.0.1.tar.gz
  • Upload date:
  • Size: 114.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.6

File hashes

Hashes for gemini_gradio-0.0.1.tar.gz
Algorithm Hash digest
SHA256 14e52b5baa066cbb52b4b5665e060f35155e000be274a7d3e9a0c687ea6c12ff
MD5 594ddf1ed46e82d90496fde2ae320c3a
BLAKE2b-256 903e90ad8335c0198bad744c9e8c6fd74717b1eb9e250870a1b4be5269e4980f

See more details on using hashes here.

File details

Details for the file gemini_gradio-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for gemini_gradio-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 da095009315c6787776ca5d7ea708548e296b20843390d8c75cfd05ec15cef0f
MD5 23b23e2ceb5a897f69450d0c9c07feeb
BLAKE2b-256 761e7c4fba8c304071a1f2ceec92542f2b5f9f04d079cc4d19ad74f08381d8a2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page