ysharma's picture
ysharma HF Staff
Update app.py
89520d9 verified
Raw
History Blame Contribute Delete
1.56 kB
"""
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()