""" 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()