https://github.com/gradio-app/openai-gradio

https://github.com/gradio-app/openai-gradio

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.6%) to scientific vocabulary
Last synced: 6 months ago · JSON representation

Repository

Basic Info
  • Host: GitHub
  • Owner: gradio-app
  • Language: Python
  • Default Branch: master
  • Size: 125 KB
Statistics
  • Stars: 312
  • Watchers: 4
  • Forks: 35
  • Open Issues: 3
  • Releases: 0
Created over 1 year ago · Last pushed over 1 year ago
Metadata Files
Readme

README.md

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:

bash 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:

```python 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

Voice Chat

OpenAI-Gradio also supports voice chat capabilities. You can enable this in two ways:

  1. Using a realtime model: ```python import gradio as gr import openai_gradio

gr.load( name='gpt-4o-realtime-preview-2024-10-01', src=openai_gradio.registry ).launch() ```

  1. Explicitly enabling voice chat with any realtime model: ```python import gradio as gr import openai_gradio

gr.load( name='gpt-4o-mini-realtime-preview-2024-12-17', src=openaigradio.registry, enablevoice=True ).launch() ```

This will create a WebRTC-based interface that allows for real-time voice conversations with the AI model.

Voice Chat API Keys

For voice chat functionality, you'll need:

  1. OpenAI API key (required for all features): bash export OPENAI_API_KEY=<your OpenAI token>

  2. Twilio credentials (required for WebRTC voice chat): bash export TWILIO_ACCOUNT_SID=<your Twilio account SID> export TWILIO_AUTH_TOKEN=<your Twilio auth token>

You can get Twilio credentials by: 1. Creating a free account at Twilio 2. Finding your Account SID and Auth Token in the Twilio Console

Without Twilio credentials, the voice chat will still work but might have connectivity issues in some network environments.

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:

```py 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.

```python import gradio as gr import openai_gradio

with gr.Blocks() as demo: with gr.Tab("GPT-4-turbo"): gr.load('gpt-4-turbo', src=openaigradio.registry) with gr.Tab("GPT-3.5-turbo"): gr.load('gpt-3.5-turbo', src=openaigradio.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:

```py import os

os.environ["OPENAIAPIKEY"] = ... ```

Owner

  • Name: Gradio
  • Login: gradio-app
  • Kind: organization
  • Email: admin@gradio.app
  • Location: Mountain View, CA

Delightfully easy-to-use open-source tools that make machine learning easier and more accessible

GitHub Events

Total
  • Issues event: 2
  • Watch event: 135
  • Issue comment event: 1
  • Push event: 13
  • Pull request event: 1
  • Fork event: 14
Last Year
  • Issues event: 2
  • Watch event: 133
  • Issue comment event: 1
  • Push event: 13
  • Pull request event: 1
  • Fork event: 12

Committers

Last synced: 11 months ago

All Time
  • Total Commits: 31
  • Total Committers: 1
  • Avg Commits per committer: 31.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 31
  • Committers: 1
  • Avg Commits per committer: 31.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
AK391 a****n@h****o 31
Committer Domains (Top 20 + Academic)

Dependencies

pyproject.toml pypi
  • gradio >=5.0.0b5
  • openai *
requirements.txt pypi
  • gradio ==5.0.0b5
  • openai *