ysharma HF Staff commited on
Commit
c68afbb
·
verified ·
1 Parent(s): c7d18e5

Deploy gr.Workflow example

Browse files
Files changed (3) hide show
  1. README.md +15 -7
  2. app.py +63 -0
  3. d_space_node.json +1 -0
README.md CHANGED
@@ -1,13 +1,21 @@
1
  ---
2
- title: Gr Workflow Concept D Space Node
3
- emoji: 🌍
4
- colorFrom: purple
5
- colorTo: blue
6
  sdk: gradio
7
- sdk_version: 6.24.0
8
- python_version: '3.13'
9
  app_file: app.py
10
  pinned: false
 
 
 
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
1
  ---
2
+ title: Concept D · space node
3
+ emoji: ✂️
4
+ colorFrom: indigo
5
+ colorTo: purple
6
  sdk: gradio
7
+ sdk_version: 6.22.0
 
8
  app_file: app.py
9
  pinned: false
10
+ hf_oauth: true
11
+ hf_oauth_scopes:
12
+ - inference-api
13
  ---
14
 
15
+ # ✂️ Concept D · space node
16
+
17
+ A kind:"space" operator that calls another Gradio Space (background removal) via gradio_client.
18
+
19
+ A live example from the blog **[Build anything with gr.Workflow](https://huggingface.co/blog)** — a visual, node-based AI pipeline builder built into Gradio.
20
+
21
+ > This demo calls Hugging Face models/Spaces. Click **Sign in with Hugging Face** on the canvas before running so the model & space nodes run under your own token.
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Concept D — a SPACE node (call any Gradio Space on the Hub)
3
+ ==========================================================
4
+
5
+ An operator with `kind: "space"` calls a Gradio Space's API. Set `space_id` and
6
+ `endpoint` (its api_name, e.g. "/image"); inputs are passed POSITIONALLY in port
7
+ order, and file inputs/outputs are handled for you. Find the endpoint + arg
8
+ order on the Space's "Use via API" panel.
9
+
10
+ Graph: reference(image) → space background-removal (/image) → subject(image)
11
+
12
+ The `/image` endpoint returns (original, cutout); the subject's output port uses
13
+ `output_index: 1` to keep the cutout.
14
+
15
+ Needs a token to RUN; imports and renders without one.
16
+
17
+ Run it: python concepts/d_space_node.py
18
+ """
19
+
20
+ import json
21
+ import os
22
+
23
+ import gradio as gr
24
+
25
+ GRAPH = {
26
+ "schema_version": "2",
27
+ "name": "Background Remover",
28
+ "references": [
29
+ {"id": "ref_img", "role": "reference", "label": "Image", "asset_type": "image",
30
+ "inputs": [{"id": "in", "label": "Image", "type": "image"}],
31
+ "outputs": [{"id": "out", "label": "Image", "type": "image"}],
32
+ "data": {}, "x": 60, "y": 120, "width": 220, "height": 150}
33
+ ],
34
+ "operators": [
35
+ {"id": "op_bg", "role": "operator", "kind": "space",
36
+ "space_id": "hf-applications/background-removal", "endpoint": "/image",
37
+ "label": "background-removal",
38
+ "inputs": [{"id": "in_image", "label": "Image", "type": "image", "required": True}],
39
+ "outputs": [{"id": "out_0", "label": "Cutout", "type": "image", "output_index": 1}],
40
+ "data": {}, "x": 340, "y": 120, "width": 240, "height": 120}
41
+ ],
42
+ "subjects": [
43
+ {"id": "sub_cut", "role": "subject", "label": "Cutout", "asset_type": "image",
44
+ "inputs": [{"id": "in", "label": "Cutout", "type": "image"}],
45
+ "outputs": [{"id": "out", "label": "Cutout", "type": "image"}],
46
+ "data": {}, "x": 640, "y": 120, "width": 240, "height": 220}
47
+ ],
48
+ "edges": [
49
+ {"id": "e1", "from_node_id": "ref_img", "from_port_id": "out",
50
+ "to_node_id": "op_bg", "to_port_id": "in_image", "type": "image"},
51
+ {"id": "e2", "from_node_id": "op_bg", "from_port_id": "out_0",
52
+ "to_node_id": "sub_cut", "to_port_id": "in", "type": "image"},
53
+ ],
54
+ }
55
+
56
+ GRAPH_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "d_space_node.json")
57
+ with open(GRAPH_PATH, "w", encoding="utf-8") as f:
58
+ json.dump(GRAPH, f, indent=2)
59
+
60
+ demo = gr.Workflow(GRAPH_PATH)
61
+
62
+ if __name__ == "__main__":
63
+ demo.launch()
d_space_node.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"schema_version":"2","name":"Background Remover","references":[{"id":"ref_img","role":"reference","label":"Image","asset_type":"image","inputs":[{"id":"in","label":"Image","type":"image"}],"outputs":[{"id":"out","label":"Image","type":"image"}],"data":{},"x":60,"y":120,"width":220,"height":136}],"operators":[{"id":"op_bg","role":"operator","kind":"space","space_id":"hf-applications/background-removal","endpoint":"/image","label":"background-removal","inputs":[{"id":"in_image","label":"Image","type":"image","required":true}],"outputs":[{"id":"out_0","label":"Cutout","type":"image","output_index":1}],"data":{},"x":340,"y":120,"width":240,"height":136}],"subjects":[{"id":"sub_cut","role":"subject","label":"Cutout","asset_type":"image","inputs":[{"id":"in","label":"Cutout","type":"image"}],"outputs":[{"id":"out","label":"Cutout","type":"image"}],"data":{},"x":640,"y":120,"width":240,"height":107}],"edges":[{"id":"e1","from_node_id":"ref_img","from_port_id":"out","to_node_id":"op_bg","to_port_id":"in_image","type":"image"},{"id":"e2","from_node_id":"op_bg","from_port_id":"out_0","to_node_id":"sub_cut","to_port_id":"in","type":"image"}]}