Skip to main content

A Python package for creating Gradio applications with Perplexity models

Project description

perplexity-gradio

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

Installation

You can install perplexity-gradio directly using pip:

pip install perplexity-gradio

That's it!

Basic Usage

You should first save your Perplexity API key to this environment variable:

export PERPLEXITY_API_KEY=<your token>

Then in a Python file, write:

import gradio as gr
import perplexity_gradio

gr.load(
    name='llama-3.1-sonar-large-128k-online',
    src=perplexity_gradio.registry,
).launch()

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

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 perplexity_gradio

gr.load(
    name='llama-3.1-sonar-large-128k-online',
    src=perplexity_gradio.registry,
    title='Perplexity-Gradio Integration',
    description="Chat with llama-3.1-sonar-large-128k-online 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 perplexity_gradio

with gr.Blocks() as demo:
    with gr.Tab("llama-3.1-sonar-large-128k-online"):
        gr.load('llama-3.1-sonar-large-128k-online', src=perplexity_gradio.registry)
    with gr.Tab("llama-3.1-sonar-small-128k-online"):
        gr.load('llama-3.1-sonar-small-128k-online', src=perplexity_gradio.registry)

demo.launch()

Under the Hood

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

Supported Models

For a comprehensive list of available models and their specifications, please refer to the Perplexity Model Cards documentation.

Note: The Online LLMs' search subsystem does not attend to the system prompt. The system prompt can be used to provide instructions related to style, tone, and language of the response.

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["PERPLEXITY_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

perplexity_gradio-0.0.1.tar.gz (71.8 kB view details)

Uploaded Source

Built Distribution

perplexity_gradio-0.0.1-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for perplexity_gradio-0.0.1.tar.gz
Algorithm Hash digest
SHA256 1d6279ece92c852704f40c2020b5d0a2ffa6ec0afab764a6a35a438eeeabff19
MD5 fa5b414022c7f72532d401e65cc30f31
BLAKE2b-256 1b4c8ee3ad96dc2917253ed3c51c3abb5e460e4c84f760d274f57e450cc9bb7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for perplexity_gradio-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 630e4a7978567d7ea2c5e6001ffde48dd25fa7747a9e8450a9393fb933c0460e
MD5 bd15f24b1497243c11bc36d1a6c6d1d2
BLAKE2b-256 bc96a46a58ebf6f5a8da79bb729dd4a3f0147dda581dc68b380ae29369330c13

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