File size: 1,562 Bytes
b945d7a 89520d9 b945d7a 89520d9 b945d7a | 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 | """
06 · Instruction Image Editor (REAL AI — needs a Hugging Face token) · one model node
===========================================================================================
Upload an image, type an edit instruction ("make it a snowy winter scene", "turn
the car red", "add sunglasses"), and get the edited photo back. The whole app is
a single `model` operator calling `Qwen/Qwen-Image-Edit` on
Hugging Face Inference Providers — no client code, no API wiring.
Graph:
[Image] ─┐
├─▶ (model) Qwen/Qwen-Image-Edit (image_to_image) ─▶ 🖼️ Edited image
[Edit instruction] ─┘
Why a plain `model` node works here: the `image_to_image` endpoint schema is
exactly {image, prompt} → image, so the canvas keeps the ports as authored.
SETUP:
export HF_TOKEN=hf_xxxxx # or: hf auth login (Windows: setx HF_TOKEN ...)
python apps/06_image_editor/app.py
On the hosted Space, click "Sign in with Hugging Face" first so the edit runs
under your own token.
"""
import os
import gradio as gr
WORKFLOW = os.path.join(os.path.dirname(os.path.abspath(__file__)), "workflow.json")
demo = gr.Workflow(WORKFLOW) # no bind: the model node calls HF for you
if __name__ == "__main__":
from huggingface_hub import get_token
if not get_token() and not os.environ.get("HF_TOKEN"):
print("\n ⚠ No Hugging Face token found — the edit will fail until you set\n"
" HF_TOKEN (or `hf auth login`), or sign in inside the app.\n")
demo.launch()
|