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

You can install gemini-gradio directly using pip:

pip install gemini-gradio

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.3.tar.gz (117.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gemini_gradio-0.0.3-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gemini_gradio-0.0.3.tar.gz
  • Upload date:
  • Size: 117.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.6

File hashes

Hashes for gemini_gradio-0.0.3.tar.gz
Algorithm Hash digest
SHA256 6d53c9995ce87f8f8faff98ae23cf54c1634f8315545ee8798ccb321747d1452
MD5 c2678d53dc87e5a2a94a5d12765d4d6e
BLAKE2b-256 2ba79759ac5c630b4a61ee44be885e3f1cebbbe091d4359cd6f70cb60375c935

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gemini_gradio-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.6

File hashes

Hashes for gemini_gradio-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bf8f848bd223f80ad446a5f20fc8b67f7b579702671bb897e94600baa1f01478
MD5 f45945d0388133ee84f50645eea65a5b
BLAKE2b-256 cb47645a9b646ce24bc49c71f4fb17f844238bab1b797070e8da68dcba6c4f1c

See more details on using hashes here.

Supported by

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