Skip to main content

A Python package for creating Gradio applications with AI models

Project description

ai-gradio

A Python package that makes it easy for developers to create machine learning apps powered by OpenAI, Google's Gemini models, and CrewAI.

Installation

You can install ai-gradio with different providers:

# Install with OpenAI support
pip install 'ai-gradio[openai]'

# Install with Gemini support  
pip install 'ai-gradio[gemini]'

# Install with CrewAI support
pip install 'ai-gradio[crewai]'

# Install with all providers
pip install 'ai-gradio[all]'

Basic Usage

First, set your API key in the environment:

For OpenAI:

export OPENAI_API_KEY=<your token>

For Gemini:

export GEMINI_API_KEY=<your token>

Then in a Python file:

import gradio as gr
from ai_gradio import registry

# Create a Gradio interface
interface = gr.load(
    name='gpt-4-turbo',  # or 'gemini-pro' for Gemini
    src=registry,
    title='AI Chat',
    description='Chat with an AI model'
).launch()

Features

Text Chat

Basic text chat is supported for all models. The interface provides a chat-like experience where you can have conversations with the AI model.

Voice Chat (OpenAI only)

Voice chat is supported for OpenAI realtime models. You can enable it in two ways:

# Using a realtime model
interface = gr.load(
    name='gpt-4o-realtime-preview-2024-10-01',
    src=registry
).launch()

# Or explicitly enabling voice chat with any realtime model
interface = gr.load(
    name='gpt-4o-mini-realtime-preview-2024-12-17',
    src=registry,
    enable_voice=True
).launch()

Voice Chat Configuration

For voice chat functionality, you'll need:

  1. OpenAI API key (required):
export OPENAI_API_KEY=<your OpenAI token>
  1. Twilio credentials (recommended for better WebRTC performance):
export TWILIO_ACCOUNT_SID=<your Twilio account SID>
export TWILIO_AUTH_TOKEN=<your Twilio auth token>

You can get Twilio credentials by:

  • Creating a free account at Twilio
  • Finding your Account SID and Auth Token in the Twilio Console

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

Video Chat (Gemini only)

Video chat is supported for Gemini models. You can enable it by setting enable_video=True:

interface = gr.load(
    name='gemini-pro',
    src=registry,
    enable_video=True
).launch()

AI Agent Teams with CrewAI

CrewAI support allows you to create teams of AI agents that work together to solve complex tasks. Enable it by using the CrewAI provider:

interface = gr.load(
    name='crewai:gpt-4-turbo',
    src=registry,
    title='AI Team Chat',
    description='Chat with a team of specialized AI agents'
).launch()

CrewAI Types

The CrewAI integration supports different specialized agent teams:

  • support: A team of support agents that help answer questions, including:

    • Senior Support Representative
    • Support Quality Assurance Specialist
  • article: A team of content creation agents, including:

    • Content Planner
    • Content Writer
    • Editor

You can specify the crew type when creating the interface:

interface = gr.load(
    name='crewai:gpt-4-turbo',
    src=registry,
    crew_type='article',  # or 'support'
    title='AI Writing Team',
    description='Create articles with a team of AI agents'
).launch()

When using the support crew type, you can provide a documentation URL that the agents will reference when answering questions. The interface will automatically show a URL input field.

Provider Selection

When loading a model, you can specify the provider explicitly using the format provider:model_name.

# Explicit provider
interface = gr.load(
    name='gemini:gemini-pro',
    src=registry
).launch()

Customization

You can customize the interface by adding examples, changing the title, or adding a description:

interface = gr.load(
    name='gpt-4-turbo',
    src=registry,
    title='Custom AI Chat',
    description='Chat with an AI assistant',
    examples=[
        "Explain quantum computing to a 5-year old",
        "What's the difference between machine learning and AI?"
    ]
).launch()

Composition

You can combine multiple models in a single interface using Gradio's Blocks:

import gradio as gr
from ai_gradio import registry

with gr.Blocks() as demo:
    with gr.Tab("GPT-4"):
        gr.load('gpt-4-turbo', src=registry)
    with gr.Tab("Gemini"):
        gr.load('gemini-pro', src=registry)
    with gr.Tab("CrewAI"):
        gr.load('crewai:gpt-4-turbo', src=registry)

demo.launch()

Supported Models

OpenAI Models

  • gpt-4-turbo
  • gpt-4
  • gpt-3.5-turbo

Gemini Models

  • gemini-pro
  • gemini-pro-vision
  • gemini-2.0-flash-exp

CrewAI Models

  • crewai:gpt-4-turbo
  • crewai:gpt-4
  • crewai:gpt-3.5-turbo

Requirements

  • Python 3.10 or higher
  • gradio >= 5.9.1

Additional dependencies are installed based on your chosen provider:

  • OpenAI: openai>=1.58.1
  • Gemini: google-generativeai
  • CrewAI: crewai>=0.1.0, langchain>=0.1.0, langchain-openai>=0.0.2, crewai-tools>=0.0.1

Troubleshooting

If you get a 401 authentication error, make sure your API key is properly set. You can set it manually in your Python session:

import os

# For OpenAI
os.environ["OPENAI_API_KEY"] = "your-api-key"

# For Gemini
os.environ["GEMINI_API_KEY"] = "your-api-key"

No Providers Error

If you see an error about no providers being installed, make sure you've installed the package with the desired provider:

# Install with OpenAI support
pip install 'ai-gradio[openai]'

# Install with Gemini support
pip install 'ai-gradio[gemini]'

# Install with CrewAI support
pip install 'ai-gradio[crewai]'

# Install all providers
pip install 'ai-gradio[all]'

Optional Dependencies

For voice chat functionality:

  • gradio-webrtc
  • numba==0.60.0
  • pydub
  • librosa
  • websockets
  • twilio
  • gradio_webrtc[vad]
  • numpy

For video chat functionality:

  • opencv-python
  • Pillow

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

ai_gradio-0.1.3.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

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

ai_gradio-0.1.3-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file ai_gradio-0.1.3.tar.gz.

File metadata

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

File hashes

Hashes for ai_gradio-0.1.3.tar.gz
Algorithm Hash digest
SHA256 e920edf7c81c62a2e4be77725b1e9819d733d7563a42140afa228411f7e9f28e
MD5 adb607e0e8da349c9e81e551bceaa84a
BLAKE2b-256 d3c245d7852495a551b468f8e1ab41de37eb1e398413b183468a51a40e2e3f42

See more details on using hashes here.

File details

Details for the file ai_gradio-0.1.3-py3-none-any.whl.

File metadata

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

File hashes

Hashes for ai_gradio-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cb252e5b2440002690d831854be830a666fe4eeffc8355808e1d5bf8f9d5f56f
MD5 6f7b38f3a398f89f60b348e8385b5769
BLAKE2b-256 42aae50292034b942b5d06dbe905fd9b5441df18bcd2cf0ca9339e4214546c4d

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