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

  1. Clone this repo: git clone https://github.com/AK391/openai-gradio.git
  2. Navigate into the folder that you cloned this repo into: cd openai-gradio
  3. Install this package: pip install -e .

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

Model Context Length Output Length Dtype / Precision
gpt-4-turbo 128000 Varies -
gpt-3.5-turbo 4096 Varies -
gpt-3.5-turbo-16k 16384 Varies -
gpt-4 8192 Varies -
gpt-4-32k 32768 Varies -

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

Uploaded Source

Built Distribution

openai_gradio-0.0.1-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for openai_gradio-0.0.1.tar.gz
Algorithm Hash digest
SHA256 731af63e01e4f3fd1ca4dcad3c7c214cce18390b0b11647c7859b02e196dc3ad
MD5 ea714df0a2af8983a65be27268b49690
BLAKE2b-256 9351296ce02d1d1e33ee3437798773b6572b73c4f00ccf1f02969e2ef6af9dd2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openai_gradio-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3d038296265eca6f303d9597d0e08f02a09dc7b72d10886d54d70bfd39054b57
MD5 5cb19c4158f2d34e675de455acf68914
BLAKE2b-256 f4b4e71e18156ecdf4cf9af715435691d6f8c357fada88bce23f41f1894714db

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