File size: 14,259 Bytes
360b897
 
 
 
 
 
 
 
c0187ee
 
a937d9d
 
 
 
 
 
 
 
 
c0187ee
 
a937d9d
 
c0187ee
 
 
 
 
 
 
fb9dac4
02a9a82
c0187ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eb1464e
c0187ee
 
 
 
 
 
a937d9d
c0187ee
a937d9d
c0187ee
 
 
a937d9d
c0187ee
 
 
a937d9d
c0187ee
 
 
a937d9d
c0187ee
 
 
 
 
a937d9d
c0187ee
 
a937d9d
c0187ee
 
 
a937d9d
c0187ee
 
 
 
 
 
 
 
 
 
a937d9d
c0187ee
 
 
 
 
 
 
 
 
 
a937d9d
c0187ee
 
 
 
 
 
 
 
 
 
a937d9d
c0187ee
 
 
 
 
 
 
 
 
 
a937d9d
c0187ee
 
 
 
 
 
 
 
 
 
a937d9d
c0187ee
 
 
 
 
 
 
 
 
 
a937d9d
c0187ee
 
 
 
 
 
 
 
 
 
a937d9d
c0187ee
 
 
 
 
 
 
 
 
 
 
 
a937d9d
c0187ee
a937d9d
c0187ee
a937d9d
c0187ee
a937d9d
c0187ee
 
 
 
 
a937d9d
c0187ee
 
 
eb1464e
 
 
 
c0187ee
 
 
 
 
 
a937d9d
c0187ee
 
 
 
 
 
 
 
 
a937d9d
c0187ee
 
 
 
 
 
 
 
 
a937d9d
c0187ee
 
 
 
 
 
 
 
 
a937d9d
c0187ee
 
 
 
 
 
 
 
 
a937d9d
c0187ee
 
 
 
 
 
 
 
 
a937d9d
c0187ee
 
 
 
 
 
 
 
 
a937d9d
c0187ee
 
 
 
 
 
 
eb1464e
 
 
 
 
 
 
 
c0187ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eb1464e
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
---
title: README
emoji: 😻
colorFrom: purple
colorTo: red
sdk: static
pinned: false
---
# Hugging Face + Visual Blocks Custom Components

<p align="center">
    <br/>
    <picture> 
        <source media="(prefers-color-scheme: dark)" srcset="https://huggingface.co/spaces/hf-vb/README/raw/main/hf-vb-logo-dark.svg" width="400" style="max-width: 100%;">
        <source media="(prefers-color-scheme: light)" srcset="https://huggingface.co/spaces/hf-vb/README/raw/main/hf-vb-logo.svg" width="400" style="max-width: 100%;">
        <img alt="transformers.js javascript library logo" src="https://huggingface.co/spaces/hf-vb/README/raw/main/hf-vb-logo.svg" width="400" style="max-width: 100%;">
    </picture>
    <br/>
</p>

Visual blocks is an amazing tool from our friends at [Google](https://github.com/google/visualblocks)
that allows you to easily create and experiment with machine learning pipelines using a visual interface.
This repository contains the source code for custom components that allow you to use Hugging Face client and server models in your Visual Blocks pipelines.
We've created a few nodes supporting different tasks and models following our [Tasks](https://huggingface.co/tasks) definitions.

> [!NOTE]
> Visual Blocks seems to be mostly working in Chrome. If you are having trouble with the interface, try using Chrome, and please submit an [issue](https://github.com/google/visualblocks/issues) to the Visual Blocks team.

Important links:

- https://visualblocks.withgoogle.com
- https://github.com/huggingface/visual-blocks-custom-components
- https://www.npmjs.com/package/huggingface-visualblocks-nodes
- https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest

<details>
<summary> Table of Contents</summary>

- [How to use the custom components](#how-to-use-the-custom-components)
- [Nodes and Examples](#nodes-and-examples)
  - [Client Nodes](#client-nodes)
    - [Translation](#translation)
    - [Token Classification](#token-classification)
    - [Text Classification](#text-classification)
    - [Object Detection](#object-detection)
    - [Image Segmentation](#image-segmentation)
    - [Image Classification](#image-classification)
    - [Depth Estimation](#depth-estimation)
    - [Background Removal](#background-removal)
  - [Server Nodes](#server-nodes)
    - [Text Generation and Chat Completion](#text-generation-and-chat-completion)
    - [Fill Mask](#fill-mask)
    - [Image Classification](#image-classification-1)
    - [Summarization](#summarization)
    - [Text Classification](#text-classification-1)
    - [Text Generation](#text-generation)
    - [Text to Image](#text-to-image)
    - [Token Classification](#token-classification-1)
  - [Extra Examples](#extra-examples)
- [Local Development](#local-development)

</details>

## How to use the custom components

To start playing with our custom components you need to **Add a custom node** to your Visual Blocks project. First you need to start a new project [https://visualblocks.withgoogle.com/#/edit/new](https://visualblocks.withgoogle.com/#/edit/new), then click on the "+" button in the bottom left corner to add a new node.

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/left_button.png" width="200">

Then input the pre-bundled code from our npm package. You can do this by pasting the following link into the input field and clicking "Submit":

```
https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest
```

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/custom_node.jpg" width="450">

Then you will be able to see three Hugging Face Collections: Client, Server and Common.

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/collections.jpg" width="250">

# Nodes and Examples

## Client Nodes

Client nodes are nodes running tranformers pipelines on the client side using [Transformers.js](https://github.com/xenova/transformers.js). All Client nodes have WASM and WebGPU (experimental) backend support, and you can find web-compatible models by visiting https://huggingface.co/models?library=transformers.js.

> [!NOTE]
> WebGPU support in transformers.js is still experimental and may not work on all devices. Not all models are supported by WebGPU backend yet.

### Translation

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/translation.jpg" width="500">

[**Translation Node Example**](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/client/translation_client_.json)

More info:

- https://huggingface.co/tasks/translation
- https://huggingface.co/docs/transformers.js/api/pipelines#module_pipelines.TranslationPipeline

### Token Classification

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/token.jpg" width="500">

[**Token Classification Node Exampl**e](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/client/token_classification_client_.json)

More info:

- https://huggingface.co/tasks/token-classification
- https://huggingface.co/docs/transformers.js/api/pipelines#module_pipelines.TokenClassificationPipeline

### Text Classification

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/text-classification.jpg" width="500">

[**Text Classification Node Example**](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/client/text_classification_client_.json)

More info:

- https://huggingface.co/tasks/text-classification
- https://huggingface.co/docs/transformers.js/api/pipelines#module_pipelines.TextClassificationPipeline

### Object Detection

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/object-detc.jpg" width="500">

[**Object Detection Node Example**](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/client/object_detection_client_.json)

More info:

- https://huggingface.co/tasks/object-detection
- https://huggingface.co/docs/transformers.js/api/pipelines#module_pipelines.ObjectDetectionPipeline

### Image Segmentation

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/segment.jpg" width="500">

[**Image Segmentation Node Example**](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/client/image_segmentation_client_.json)

More info:

- https://huggingface.co/tasks/image-segmentation
- https://huggingface.co/docs/transformers.js/api/pipelines#module_pipelines.ImageSegmentationPipeline

### Image Classification

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/class.jpg" width="500">

[**Image Classification Node Example**](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/client/image_classification_client_.json)

More info:

- https://huggingface.co/tasks/image-classification
- https://huggingface.co/docs/transformers.js/api/pipelines#module_pipelines.ImageClassificationPipeline

### Depth Estimation

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/dept-es.jpg" width="500">

[Depth Estimation Node Example](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/client/depth_estimation_client_.json)

More info:

- https://huggingface.co/tasks/depth-estimation
- https://huggingface.co/docs/transformers.js/api/pipelines#module_pipelines.DepthEstimationPipeline

### Background Removal

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/removal.jpg" width="500">

[**Background Removal Node Example**](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/client/background_removal_client_.json)

## Server Nodes

Server nodes are nodes running Transformers pipeline tasks using the [Hugging Face Serverless API](https://huggingface.co/docs/api-inference/en/index). For a few selected LLM models, it's running using our hosted [Text Generation Inference](https://huggingface.co/docs/text-generation-inference/en/index), our fast, optimized inference for LLMs.

> [!NOTE]
> You can use the Hugging Face Serverless API for free with limited usage, after which you'll be rate limited. If you need more usage, you can create an account at https://huggingface.co/join and get an API token at https://huggingface.co/settings/tokens or log in using the Hugging Face Login node.

For server nodes you have the option to Login using your Hugging Face account to get more usage and access to private models. Using **Hugging Face Hub Login**

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/server/button-auth.jpg" width="250">

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/server/auth.jpg" width="400">

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/server/button-logged.jpg" width="250">

If successful, you can obtain your **Apikey** directly from the **Hugging Face Hub Login** node.

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/server/logged.jpg" width="350">

### Text Generation and Chat Completion

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/server/chat-template.jpg" width="500">

[**Chat Template Text Generation Node Example**](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/server/chat_template_text_generation_server_.json)

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/chat_completion.jpg" width="500">

[**Chat Completion Node Example**](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/server/chat_completion_server_.json)

More info:

- https://huggingface.co/tasks/text-generation

### Fill Mask

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/server/fill-mask.jpg" width="500">

[**Fill Mask Node Example**](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/server/fill_mask_server_.json)

More info:

- https://huggingface.co/tasks/fill-mask

### Image Classification

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/server/image-class.jpg" width="500">

[**Image Classification Node Example**](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/server/image_classification_server_.json)

More info:

- https://huggingface.co/tasks/image-classification

### Summarization

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/server/summarization.jpg" width="500">

[**Summarization Node Example**](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/server/summarization_server_.json)

More info:

- https://huggingface.co/tasks/summarization

### Text Classification

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/server/text-class.jpg" width="500">

[**Text Classification Node Example**](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/server/text_classification_server_.json)

More info:

- https://huggingface.co/tasks/text-classification

### Text Generation

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/server/text-generation.jpg" width="500">

[**Text Generation Node Example**](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/server/text_generation_server_.json)

More info:

- https://huggingface.co/tasks/text-generation

### Text to Image

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/server/text-to-image.jpg" width="500">

[**Text to Image Node Example**](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/server/text_to_image_server_.json)

More info:

- https://huggingface.co/tasks/text-to-image

### Token Classification

<img src="https://huggingface.co/spaces/hf-vb/README/resolve/main/server/token-class.jpg" width="500">

[**Token Classification Node Example**](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/server/token_classification_server_.json)

More info:

- https://huggingface.co/tasks/token-classification

## Extra Examples

[**Background Removal Text to Image**](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/extras/background_removal_text_to_image.json)

[**Chat Completion Text to Image Depth**](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/extras/chat_completion_txt2img_depth.json)

[**Image Segmentation Webcam Client**](https://visualblocks.withgoogle.com/#/edit/new_hfdemo?project_json=https://cdn.jsdelivr.net/npm/huggingface-visualblocks-nodes@latest/examples/extras/image_segmentation_webcam_client.json)

# Local Development

1. Clone the repository

   ```bash
   git clone https://github.com/huggingface/visual-blocks-custom-components.git
   cd visual-blocks-custom-components
   ```

2. Install the dependencies

   ```bash
   npm i
   ```

3. Run the development server

   ```bash
   npm run dev
   ```

4. Visit Google's staging server

5. Click the + in the bottom left corner to add the custom nodes.

6. Paste in the link to the script (e.g., http://localhost:8080/index.js) and click "Submit".