Spaces:
Sleeping
Sleeping
Adding documentation
Browse files- workflow/RemoveBG.json +1 -1
- workflow/custom_nodes/model.py +8 -0
- workflow/custom_nodes/rmbg.py +8 -0
- workflow/docs/RemoveBG.md +15 -0
workflow/RemoveBG.json
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"version": "0", "type": "workflow", "nodes": [{"id": "2", "position": {"x": 187.5, "y": 52.5}, "type": "step", "data": {"label": "HuggingfaceDataset", "name": "HuggingfaceDataset", "parameters": {"dataset_id": {"type": "string", "description": "The dataset ID from Huggingface", "value": "microsoft/cats_vs_dogs"}, "split": {"type": "string", "default": "train", "description": "The split of the dataset to use", "value": "train"}, "shuffle": {"type": "boolean", "default": false, "description": "Whether to shuffle the dataset", "value": true}, "log_data": {"type": "boolean", "default": true, "description": "Whether to log the outputs as JSON to the node UI", "value": false}, "image_columns": {"type": "list[string]", "description": "The columns in the dataset that contain images. This is to let Graphbook know how to display the images in the UI.", "required": false, "value": ["image"]}, "kwargs": {"type": "dict", "description": "Additional keyword arguments to pass to the dataset", "required": false, "value": []}}, "inputs": [], "outputs": ["out"], "category": "Huggingface", "isCollapsed": false}}, {"id": "3", "type": "resource", "position": {"x": 187.5, "y": 282.5}, "data": {"name": "RMBGModel", "parameters": {"model_name": {"type": "string", "default": "briaai/RMBG-1.4", "required": false, "description": "The name of the RMBG model.", "value": "briaai/RMBG-1.4"}, "use_cuda": {"type": "boolean", "default": true, "required": false, "description": "Whether to use CUDA acceleration.", "value": false}}, "category": "BackgroundRemoval", "label": "RMBGModel", "isCollapsed": false}}, {"id": "4", "type": "step", "position": {"x": 444.5, "y": 52.5}, "data": {"name": "RemoveBackground", "parameters": {"batch_size": {"type": "number", "description": "The batch size for background removal.", "default": 8, "value": 8}, "model": {"type": "resource", "description": "The model to use for background removal."}, "output_dir": {"type": "string", "description": "The directory to save the output images.", "default": "/tmp/output", "value": "/
|
|
|
1 |
+
{"version": "0", "type": "workflow", "nodes": [{"id": "2", "position": {"x": 187.5, "y": 52.5}, "type": "step", "data": {"label": "HuggingfaceDataset", "name": "HuggingfaceDataset", "parameters": {"dataset_id": {"type": "string", "description": "The dataset ID from Huggingface", "value": "microsoft/cats_vs_dogs"}, "split": {"type": "string", "default": "train", "description": "The split of the dataset to use", "value": "train"}, "shuffle": {"type": "boolean", "default": false, "description": "Whether to shuffle the dataset", "value": true}, "log_data": {"type": "boolean", "default": true, "description": "Whether to log the outputs as JSON to the node UI", "value": false}, "image_columns": {"type": "list[string]", "description": "The columns in the dataset that contain images. This is to let Graphbook know how to display the images in the UI.", "required": false, "value": ["image"]}, "kwargs": {"type": "dict", "description": "Additional keyword arguments to pass to the dataset", "required": false, "value": []}}, "inputs": [], "outputs": ["out"], "category": "Huggingface", "isCollapsed": false}}, {"id": "3", "type": "resource", "position": {"x": 187.5, "y": 282.5}, "data": {"name": "RMBGModel", "parameters": {"model_name": {"type": "string", "default": "briaai/RMBG-1.4", "required": false, "description": "The name of the RMBG model.", "value": "briaai/RMBG-1.4"}, "use_cuda": {"type": "boolean", "default": true, "required": false, "description": "Whether to use CUDA acceleration.", "value": false}}, "category": "BackgroundRemoval", "label": "RMBGModel", "isCollapsed": false}}, {"id": "4", "type": "step", "position": {"x": 444.5, "y": 52.5}, "data": {"name": "RemoveBackground", "parameters": {"batch_size": {"type": "number", "description": "The batch size for background removal.", "default": 8, "value": 8}, "model": {"type": "resource", "description": "The model to use for background removal."}, "output_dir": {"type": "string", "description": "The directory to save the output images.", "default": "/tmp/output", "value": "/tmp/output"}}, "inputs": ["in"], "outputs": ["out"], "category": "BackgroundRemoval", "label": "RemoveBackground", "isCollapsed": false}}], "edges": [{"source": "2", "sourceHandle": "out", "target": "4", "targetHandle": "in", "data": {}, "id": "reactflow__edge-2out-4in"}, {"source": "3", "sourceHandle": "resource", "target": "4", "targetHandle": "model", "data": {}, "id": "reactflow__edge-3resource-4model"}]}
|
workflow/custom_nodes/model.py
CHANGED
@@ -16,6 +16,14 @@ from transformers import AutoModelForImageSegmentation
|
|
16 |
default=True,
|
17 |
)
|
18 |
def rmbg_model(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
model = AutoModelForImageSegmentation.from_pretrained(
|
20 |
self.model_name, trust_remote_code=True
|
21 |
)
|
|
|
16 |
default=True,
|
17 |
)
|
18 |
def rmbg_model(self):
|
19 |
+
"""
|
20 |
+
Loads the background removal model from the Hugging Face model hub.
|
21 |
+
By default, we are using [briaai/RMBG-1.4](https://huggingface.co/briaai/RMBG-1.4).
|
22 |
+
|
23 |
+
Args:
|
24 |
+
model_name (str): The name of the RMBG model.
|
25 |
+
use_cuda (bool): Whether to use CUDA acceleration.
|
26 |
+
"""
|
27 |
model = AutoModelForImageSegmentation.from_pretrained(
|
28 |
self.model_name, trust_remote_code=True
|
29 |
)
|
workflow/custom_nodes/rmbg.py
CHANGED
@@ -8,6 +8,14 @@ import os.path as osp
|
|
8 |
|
9 |
|
10 |
class RemoveBackground(steps.BatchStep):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
RequiresInput = True
|
12 |
Outputs = ["out"]
|
13 |
Parameters = {
|
|
|
8 |
|
9 |
|
10 |
class RemoveBackground(steps.BatchStep):
|
11 |
+
"""
|
12 |
+
Executes background removal on a batch of images using the provided model.
|
13 |
+
|
14 |
+
Args:
|
15 |
+
batch_size (int): The batch size (number of images) given to the background removal model at a time
|
16 |
+
model (resource): The model to use for background removal. Use the resource `BackgroundRemoval/RMBGModel` to load the model
|
17 |
+
output_dir (str): The directory to save the output images to
|
18 |
+
"""
|
19 |
RequiresInput = True
|
20 |
Outputs = ["out"]
|
21 |
Parameters = {
|
workflow/docs/RemoveBG.md
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div align="center">
|
2 |
+
<img src="https://github.com/graphbookai/graphbook/blob/main/docs/_static/graphbook.png?raw=true" alt="Graphbook Logo" height="64">
|
3 |
+
<h1 style="margin: 0 0 10px 0">RMBG Graphbook</h1>
|
4 |
+
</div>
|
5 |
+
|
6 |
+
This is a [Graphbook](https://github.com/graphbookai/graphbook) app that allows you to remove the background from any image dataset from Hugging Face.
|
7 |
+
|
8 |
+
* Model used: [briaai/RMBG-1.4](https://huggingface.co/briaai/RMBG-1.4)
|
9 |
+
* Dataset used: [microsoft/cats_vs_dogs](https://huggingface.co/datasets/microsoft/cats_vs_dogs)
|
10 |
+
|
11 |
+
You may swap datasets using the 🤗 Hugging Face extension or by simply changing the `dataset_id` in the HuggingfaceDataset node.
|
12 |
+
|
13 |
+
* [Repo](https://github.com/graphbookai/graphbook)
|
14 |
+
* [Docs](https://docs.graphbook.ai/)
|
15 |
+
* [Examples](https://github.com/graphbookai/graphbook-examples)
|