Skip to main content

A Python package for creating Gradio applications with Groq models

Project description

groq-gradio

groq-gradio is a Python package that simplifies the creation of machine learning applications powered by Groq for lightning-fast inference speed and low latency using easily deployable Gradio interfaces.

Features

  • Fast Inference Speed: Seamless integration with Groq API to leverage fast inference for your AI apps 🚀
  • Rapid Development: Functional frontend creation with a few lines of code (that can be easily deployed to HF Spaces) 🤩
  • Flexible UI Options: Ability to launch a responsive web interface with customizable titles, descriptions, and example prompts 🎨
  • Multi-Modal Model Support: Ability to build interfaces for any LLM powered by Groq via your Groq API Key 💪

Installation

Install groq-gradio using pip:

pip install groq-gradio

Quick Start

1. Set up your Groq API Key

First, if you haven't already, create a free account on GroqCloud and generate a Groq API Key. Set your Groq API Key as an environment variable:

export GROQ_API_KEY=<YOUR_GROQ_API_KEY>

2. Create a basic Gradio chat interface

Create a Python file, paste the following example code, and run the file:

import gradio as gr
import groq_gradio

gr.load(
    name='llama-3.2-3b-preview',
    src=groq_gradio.registry,
).launch()

As shown below, this will launch a simple Gradio chat interface for the llama-3.2-3b-preview model powered by Groq!

ChatInterface

Customization

Custom Interface Example

Once you create a Gradio UI from a Groq API endpoint, you can customize it by setting your own input and output components, or any other arguments to gr.Interface as shown in the example below.

ChatInterface with customizations

The example screenshot above was generated with the following few lines of code:

import gradio as gr # The Gradio library for creating web interfaces
import groq_gradio # Our package that seamlessly connects Gradio with Groq API

# Gradio function that loads a pre-configured interface:
gr.load(
    name='llama-3.2-3b-preview', # The specific model powered by Groq to use
    src=groq_gradio.registry, # Tells Gradio to use our custom interface registry as the source
    # Optional customization parameters:
    title='Groq-Gradio Integration', # The title shown at the top of our UI
    description="Chat with the Llama 3.2 3B Preview model powered by Groq.", # Subtitle
    examples=["Explain quantum gravity to a 5-year old.", "How many R are there in the word Strawberry?"] # Pre-written prompts users can click to try
).launch() # Creates and starts the web server!

Composition

You can also create multiple interfaces for multiple models using Gradio Blocks:

import gradio as gr
import groq_gradio

with gr.Blocks() as demo:
    with gr.Tab("Llama 3.2 3B Preview"):
        gr.load('llama-3.2-3b-preview', src=groq_gradio.registry)
    with gr.Tab("llama-3.2-1b-preview"):
        gr.load('llama-3.2-1b-preview', src=groq_gradio.registry)

demo.launch()

Technical Details

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

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

Troubleshooting

If you encounter a 401 authentication error, then the Groq API Client is not able to fetch your Groq API Key from your environment variable. In this case, set the key directly in your Python session:

import os

os.environ["GROQ_API_KEY"] = ...

Note: Please make sure to never share your Groq API Key publicly. If you are planning on making your app available publicly, remove your Groq API Key before publishing!

Contributing

Contributions are always welcome! Please feel free to submit a Pull Request that our team can review.

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

groq_gradio-0.0.1.tar.gz (291.9 kB view details)

Uploaded Source

Built Distribution

groq_gradio-0.0.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for groq_gradio-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9717701f2c74fe113382ad951330c2a5f9cf67576b9997361bd569da62e652c0
MD5 ac09c3e9b2cf5c9618d415cbcfbf140d
BLAKE2b-256 51e77d97bf96ea719dc16dd7a771e2184b644a3634b0fdc2155d58487dbfeb79

See more details on using hashes here.

File details

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

File metadata

  • Download URL: groq_gradio-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for groq_gradio-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 71951e9ecea1a268fe6c88eff751ba8fba42bba06b6f50ed103186c2cf2a4508
MD5 91a6cb3be887f2b0b7838791f493e7ab
BLAKE2b-256 4ec9fb738efe314ccecd2bbec5cdab20bc49d2b87a7d630cfdcd8836f16b2d18

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