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!
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()
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gemini_gradio-0.0.2.tar.gz.
File metadata
- Download URL: gemini_gradio-0.0.2.tar.gz
- Upload date:
- Size: 115.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03811b77fa18fcd4f1b0b83d6f1e9b1fcdbe4b868d846a3088f8688e2970256e
|
|
| MD5 |
47b3fc3d5c0758d6b82b75143fc70241
|
|
| BLAKE2b-256 |
d715d09492a41b06bf84674164e9dd60d62c69930acc49fe5c2b24920474a790
|
File details
Details for the file gemini_gradio-0.0.2-py3-none-any.whl.
File metadata
- Download URL: gemini_gradio-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1fb964f0e9ce98605d9fcb7852f902f3bbbbed24edb33698c04dd3a7d73f02e
|
|
| MD5 |
1fb8ea74bc2d52a2ba0aad838a95ad37
|
|
| BLAKE2b-256 |
25665debd593f8f42f535f9b588aaab3128acf2dad399d46473e826bf8471e7b
|