File size: 2,781 Bytes
e26fef0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Concept C — a MODEL node (Hugging Face Inference Providers)
==========================================================

An operator with `kind: "model"` calls a model on HF Inference Providers — no
client code. Two ways to shape the call:

  • with `endpoint` (e.g. "text_to_image"): inputs are sent as NAMED kwargs
    (port id → value), so a port `id: "prompt"` becomes `prompt=...`.
  • without `endpoint`: `pipeline_tag` routes the inputs POSITIONALLY.

`provider` (default "auto") picks the serving provider. Outputs use
`output_index` to select from multi-value responses.

Graph:  reference(text) → model FLUX.1-schnell (text→image) → subject(image)

Needs a token to RUN (set HF_TOKEN or sign in on the canvas); it imports and
renders without one.

Run it:   python concepts/c_model_node.py
"""

import json
import os

import gradio as gr

GRAPH = {
    "schema_version": "2",
    "name": "Text to Image",
    "references": [
        {"id": "ref_prompt", "role": "reference", "label": "Prompt", "asset_type": "text",
         "inputs": [{"id": "in", "label": "Prompt", "type": "text"}],
         "outputs": [{"id": "out", "label": "Prompt", "type": "text"}],
         "data": {"out": "a red panda astronaut, watercolor"},
         "x": 60, "y": 120, "width": 220, "height": 90}
    ],
    "operators": [
        {"id": "op_flux", "role": "operator", "kind": "model",
         "model_id": "black-forest-labs/FLUX.1-schnell",
         "pipeline_tag": "text-to-image", "endpoint": "text_to_image",
         "provider": "auto", "label": "FLUX.1-schnell",
         "inputs": [{"id": "prompt", "label": "Prompt", "type": "text", "required": True}],
         "outputs": [{"id": "out_0", "label": "Image", "type": "image", "output_index": 0}],
         "data": {}, "x": 340, "y": 120, "width": 230, "height": 110}
    ],
    "subjects": [
        {"id": "sub_img", "role": "subject", "label": "Image", "asset_type": "image",
         "inputs": [{"id": "in", "label": "Image", "type": "image"}],
         "outputs": [{"id": "out", "label": "Image", "type": "image"}],
         "data": {}, "x": 640, "y": 120, "width": 240, "height": 220}
    ],
    "edges": [
        {"id": "e1", "from_node_id": "ref_prompt", "from_port_id": "out",
         "to_node_id": "op_flux", "to_port_id": "prompt", "type": "text"},
        {"id": "e2", "from_node_id": "op_flux", "from_port_id": "out_0",
         "to_node_id": "sub_img", "to_port_id": "in", "type": "image"},
    ],
}

GRAPH_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "c_model_node.json")
with open(GRAPH_PATH, "w", encoding="utf-8") as f:
    json.dump(GRAPH, f, indent=2)

demo = gr.Workflow(GRAPH_PATH)   # no bind: the model node needs no Python

if __name__ == "__main__":
    demo.launch()