Skip to main content

A Python package for replicating Gradio applications

Project description

sambanova_gradio

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

Installation

pip install sambanova-gradio

That's it!

Basic Usage

Just like if you were to use the sambanova API, you should first save your sambanova API token to this environment variable:

export SAMBANOVA_API_KEY=<your token>

Then in a Python file, write:

import gradio as gr
import sambanova_gradio

gr.load(
    name='Meta-Llama-3.1-405B-Instruct',
    src=sambanova_gradio.registry,
).launch()

or simply without setting the environment variable

# text only chatbot
import gradio as gr
import sambanova_gradio

gr.load("Meta-Llama-3.1-70B-Instruct-8k", src=sambanova_gradio.registry, accept_token=True).launch()
# multimodal chatbot
import gradio as gr
import sambanova_gradio

gr.load("Llama-3.2-11B-Vision-Instruct", src=sambanova_gradio.registry, accept_token=True, multimodal = True).launch()

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

ChatInterface

Customization

Once you can create a Gradio UI from a sambanova 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 sambanova_gradio

gr.load(
    name='Meta-Llama-3.1-405B-Instruct',
    src=sambanova_gradio.registry,
    title='Sambanova-Gradio Integration',
    description="Chat with Meta-Llama-3.1-405B-Instruct 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 sambanova_gradio

with gr.Blocks() as demo:
    with gr.Tab("405B"):
        gr.load('Meta-Llama-3.1-405B-Instruct', src=sambanova_gradio.registry)
    with gr.Tab("70B"):
        gr.load('Meta-Llama-3.1-70B-Instruct-8k', src=sambanova_gradio.registry)

demo.launch()

Under the Hood

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

Supported Models in Sambanova Cloud

Access Meta’s Llama 3.2 and 3.1 family of models at full precision via the SambaNova Cloud API!

Model details for Llama 3.2 family:

  1. Llama 3.2 1B:
    • Model ID: Meta-Llama-3.2-1B-Instruct
    • Context length: 4,096 tokens
  2. Llama 3.2 3B:
    • Model ID: Meta-Llama-3.2-3B-Instruct
    • Context length: 4,096 tokens
  3. Llama 3.2 11B Vision:
    • Model ID: Llama-3.2-11B-Vision-Instruct
    • Context length: 4096 tokens
  4. Llama 3.2 90B Vision:
    • Model ID: Llama-3.2-90B-Vision-Instruct
    • Context length: 4096 tokens

Model details for Llama 3.1 family:

  1. Llama 3.1 8B:
    • Model ID: Meta-Llama-3.1-8B-Instruct
    • Context length: 4k, 8k, 16k
  2. Llama 3.1 70B:
    • Model ID: Meta-Llama-3.1-70B-Instruct
    • Context length: 4k, 8k, 16k, 32k, 64k
  3. Llama 3.1 405B:
    • Model ID: Meta-Llama-3.1-405B-Instruct
    • Context length: 4k, 8k

Note: if you are getting a 401 authentication error, then the sambanova 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["SAMBANOVA_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

sambanova_gradio-0.1.9.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

sambanova_gradio-0.1.9-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file sambanova_gradio-0.1.9.tar.gz.

File metadata

  • Download URL: sambanova_gradio-0.1.9.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.0

File hashes

Hashes for sambanova_gradio-0.1.9.tar.gz
Algorithm Hash digest
SHA256 8ebff984eace20d5072d0bd70bc1f7bf276f6f681d5a3a888c38761076fae2af
MD5 1d39bbda0236c40fd2f21a8149ec6c4a
BLAKE2b-256 83c537871861a9b805d5107abe8e1f427299a134b172e1f86bd37f015b80909c

See more details on using hashes here.

File details

Details for the file sambanova_gradio-0.1.9-py3-none-any.whl.

File metadata

File hashes

Hashes for sambanova_gradio-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 6b1ce225d49def5b6cb119726af01045b17e53df807c570e159228b485ca3ae6
MD5 fb20671692b7e2faa579640f586d2c35
BLAKE2b-256 d31e7647456e646750b213dd3b04e112206f82142d03a4446776e48cde88b628

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