File size: 2,989 Bytes
6c7a313
1045f4d
 
6c7a313
 
 
1045f4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c7a313
1045f4d
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
title: chatbotappgradio
app_file: app.py
sdk: gradio
sdk_version: 5.14.0
---
# `hyperbolic-gradio`

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

# Installation

You can install `hyperbolic-gradio` directly using pip:

```bash
pip install hyperbolic-gradio
```

That's it! 

# Basic Usage

Just like if you were to use the `hyperbolic` API, you should first save your Hyperbolic API key to this environment variable:

```
export HYPERBOLIC_API_KEY=<your token>
```

Then in a Python file, write:

```python
import gradio as gr
import hyperbolic_gradio

gr.load(
    name='meta-llama/Meta-Llama-3-70B-Instruct',
    src=hyperbolic_gradio.registry,
).launch()
```

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

![ChatInterface](https://raw.githubusercontent.com/HyperbolicLabs/hyperbolic-gradio/master/chatinterface.png)

# Customization 

Once you can create a Gradio UI from an Hyperbolic API 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:

```py
import gradio as gr
import hyperbolic_gradio

gr.load(
    name='meta-llama/Meta-Llama-3-70B-Instruct',
    src=hyperbolic_gradio.registry,
    title='Hyperbolic-Gradio Integration',
    description="Chat with Meta-Llama-3-70B-Instruct model.",
    examples=["Explain quantum gravity to a 5-year old.", "How many R are there in the word Strawberry?"]
).launch()
```
![ChatInterface with customizations](https://raw.githubusercontent.com/HyperbolicLabs/hyperbolic-gradio/master/hyperbolic-gradio.png)

# Composition

Or use your loaded Interface within larger Gradio Web UIs, e.g.

```python
import gradio as gr
import hyperbolic_gradio

with gr.Blocks() as demo:
    with gr.Tab("Meta-Llama-3-70B-Instruct"):
        gr.load('meta-llama/Meta-Llama-3-70B-Instruct', src=hyperbolic_gradio.registry)
    with gr.Tab("Llama-3.2-3B-Instruct"):
        gr.load('meta-llama/Llama-3.2-3B-Instruct', src=hyperbolic_gradio.registry)

demo.launch()
```

# Under the Hood

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

# Supported Models in Hyperbolic AI

All chat API models supported by Hyperbolic AI are compatible with this integration. For a comprehensive list of available models and their specifications, please refer to the [Hyperbolic AI Models documentation](https://platform.hyperbolic.ai/docs/models).

-------

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

```py
import os

os.environ["HYPERBOLIC_API_KEY"] = ...
```