Skip to main content

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"] = ...

Metadata

Release files for perplexity-gradio 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for perplexity-gradio 0.0.1
File Size Uploaded Provenance
perplexity_gradio-0.0.1.tar.gz 71.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for perplexity-gradio 0.0.1
File Interpreter ABI Platform
perplexity_gradio-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 75.2 kB

Release files / perplexity_gradio-0.0.1.tar.gz

Download URL perplexity_gradio-0.0.1.tar.gz
Size 71.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1d6279ece92c852704f40c2020b5d0a2ffa6ec0afab764a6a35a438eeeabff19
BLAKE2b-256 checksum
How to use checksums
1b4c8ee3ad96dc2917253ed3c51c3abb5e460e4c84f760d274f57e450cc9bb7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.6

Release files / perplexity_gradio-0.0.1-py3-none-any.whl

Download URL perplexity_gradio-0.0.1-py3-none-any.whl
Size 3.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
630e4a7978567d7ea2c5e6001ffde48dd25fa7747a9e8450a9393fb933c0460e
BLAKE2b-256 checksum
How to use checksums
bc96a46a58ebf6f5a8da79bb729dd4a3f0147dda581dc68b380ae29369330c13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.6

Security for perplexity-gradio 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page