A Python package for replicating Gradio applications using Together AI
Project description
together_gradio
is a Python package that makes it very easy for developers to create machine learning apps that are powered by Together's Inference API.
Installation
- Clone this repo:
git clone git@github.com:gradio-app/together_gradio.git
- Navigate into the folder that you cloned this repo into:
cd together_gradio
- Install this package:
pip install -e .
That's it!
Basic Usage
Just like if you were to use the Together
Client, you should first save your together API token to this environment variable:
export TOGETHER_API_KEY=<your token>
Then in a Python file, write:
import gradio as gr
import together_gradio
gr.load(
name='meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo',
src=together_gradio.registry,
).launch()
Run the Python file, and you should see a Gradio ChatInterface connected to the model on Together!
Customization
Once you can create a Gradio UI from a Together endpoint, you can customize it by setting your own input and output components, or any other arguments to gr.ChatInterface
. For example, the screenshot below was generated with:
import gradio as gr
import together_gradio
gr.load(
name='meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo',
src=together_gradio.registry,
title='Together-Gradio Integration',
description="Chat with Meta-Llama-3.1-70B-Instruct-Turbo model.",
examples=["Explain quantum gravity to a 5-year old.", "How many R are there in the word Strawberry?"]
).launch()
Composition
Or use your loaded Interface within larger Gradio Web UIs, e.g.
import gradio as gr
import together_gradio
with gr.Blocks() as demo:
with gr.Tab("8B"):
gr.load('meta-llama/Meta-Llama-3-8B-Instruct-Lite', src=Together_gradio.registry)
with gr.Tab("70B"):
gr.load('meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo', src=Together_gradio.registry)
demo.launch()
Under the Hood
The Together-gradio
Python library has two dependencies: Together_cloud_sdk
and gradio
. It defines a "registry" function Together_gradio.registry
, which takes in a model name and returns a Gradio app.
Supported Models in Together API
Currently the available options are: llama3.1-8b, llama3.1-70b
Note: if you are getting a 401 authentication error, then the Together 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["TOGETHER_API_KEY"] = ...
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file together_gradio-0.0.1.tar.gz
.
File metadata
- Download URL: together_gradio-0.0.1.tar.gz
- Upload date:
- Size: 62.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48ed2a0b20fe48d92de043ac4f3383277be2635aa618d8a2f8e6ad3db171b2b8 |
|
MD5 | 498e66d0eca6ff672f88a711b68f0e2a |
|
BLAKE2b-256 | 898fa771cc8c822688a241c13439e22d34b09a06b0cae0484aedf104fb55cdc1 |
File details
Details for the file together_gradio-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: together_gradio-0.0.1-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1e5cea4743ca1453f097cd35e55100880ac88f56e12af613bb8e140c123b20f |
|
MD5 | 271563902a09915f772577cdae98c957 |
|
BLAKE2b-256 | c1ae71c91dabae48d58786281d473a849cb03145720ffeb1c1ff0db057aba990 |