Skip to main content

A Python package for creating Gradio applications with OpenAI models

Project description

openai-gradio

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

Installation

You can install openai-gradio directly using pip:

pip install openai-gradio

That's it!

Basic Usage

Just like if you were to use the openai API, you should first save your OpenAI API key to this environment variable:

export OPENAI_API_KEY=<your token>

Then in a Python file, write:

import gradio as gr
import openai_gradio

gr.load(
    name='gpt-4-turbo',
    src=openai_gradio.registry,
).launch()

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

ChatInterface

Customization

Once you can create a Gradio UI from an OpenAI 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 openai_gradio

gr.load(
    name='gpt-4-turbo',
    src=openai_gradio.registry,
    title='OpenAI-Gradio Integration',
    description="Chat with GPT-4-turbo 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 openai_gradio

with gr.Blocks() as demo:
    with gr.Tab("GPT-4-turbo"):
        gr.load('gpt-4-turbo', src=openai_gradio.registry)
    with gr.Tab("GPT-3.5-turbo"):
        gr.load('gpt-3.5-turbo', src=openai_gradio.registry)

demo.launch()

Under the Hood

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

Supported Models in OpenAI

All chat API models supported by OpenAI are compatible with this integration. For a comprehensive list of available models and their specifications, please refer to the OpenAI Models documentation.


Note: if you are getting a 401 authentication error, then the OpenAI API Client is not able to get the API token from the environment variable. This happened to me as well, in which case save it in your Python session, like this:

import os

os.environ["OPENAI_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

openai_gradio-0.0.5.tar.gz (110.7 kB view details)

Uploaded Source

Built Distribution

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

openai_gradio-0.0.5-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file openai_gradio-0.0.5.tar.gz.

File metadata

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

File hashes

Hashes for openai_gradio-0.0.5.tar.gz
Algorithm Hash digest
SHA256 959b1c8ffe95a74e3fc7d2e03c2f95c70a9b8075a5cfbfcf1d66fb7bd3721e66
MD5 63043e43d3e4bce35428cbb14d00a62e
BLAKE2b-256 5919fe7f87ec05bf8e8da57038db507f4bdf7d6bfe49e26e011616efce4aeba6

See more details on using hashes here.

File details

Details for the file openai_gradio-0.0.5-py3-none-any.whl.

File metadata

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

File hashes

Hashes for openai_gradio-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 455cb18b891dc7049bb8b2e1d9b1a43840d86f0b804131beb17d674282c30e18
MD5 7dd2e4b2f8503697748605450ad27506
BLAKE2b-256 3f8d38bea39163434ace9dcf2610613a8a2e77a4f192cb5494ee900de8cb0f67

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