Instructions to use beckx123/GufG with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use beckx123/GufG with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline from diffusers.utils import load_image # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("beckx123/GufG", dtype=torch.bfloat16, device_map="cuda") prompt = "Turn this cat into a dog" input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png") image = pipe(image=input_image, prompt=prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Download handler.py from beckx123/GufG: direct link, hf CLI and curl.
- Browser
- Download file 2.02 kB
-
https://huggingface.co/beckx123/GufG/resolve/main/handler.py
- Command line
-
hf download hf://beckx123/GufG/handler.py
-
curl -L -o handler.py https://huggingface.co/beckx123/GufG/resolve/main/handler.py
2.02 kB
| """Custom handler for a Hugging Face Inference Endpoint serving a Qwen-Image edit/generate model. | |
| Upload this file + requirements.txt to the root of your model repo (or a copy/fork of it). | |
| Request format (matches the ComfyUI node): | |
| {"inputs": "prompt", "parameters": {"steps": 40, "seed": 0, "size": "1024x1024", | |
| "neg": "...", "cfg": 4.0, "input_images": ["<b64 png>", ...]}} | |
| Response: a PIL image (served as image/png when the request sends Accept: image/png). | |
| """ | |
| import base64 | |
| import io | |
| import torch | |
| from diffusers import DiffusionPipeline | |
| from PIL import Image | |
| class EndpointHandler: | |
| def __init__(self, path=""): | |
| # `path` is the local snapshot of the repo the endpoint was created from. | |
| self.pipe = DiffusionPipeline.from_pretrained(path, torch_dtype=torch.bfloat16) | |
| self.pipe.to("cuda") | |
| self.pipe.set_progress_bar_config(disable=True) | |
| def __call__(self, data): | |
| prompt = data["inputs"] | |
| params = data.get("parameters", {}) or {} | |
| kwargs = { | |
| "prompt": prompt, | |
| "num_inference_steps": int(params.get("steps", 40)), | |
| "generator": torch.Generator("cuda").manual_seed(int(params.get("seed", 0))), | |
| } | |
| images = [ | |
| Image.open(io.BytesIO(base64.b64decode(b))).convert("RGB") | |
| for b in params.get("input_images", []) | |
| ] | |
| if images: | |
| kwargs["image"] = images if len(images) > 1 else images[0] | |
| size = params.get("size") | |
| if size: | |
| width, height = (int(v) for v in size.lower().split("x")) | |
| kwargs["width"], kwargs["height"] = width, height | |
| neg = params.get("neg") | |
| if neg: | |
| kwargs["negative_prompt"] = neg | |
| # Qwen-Image pipelines use true_cfg_scale (only active with a negative prompt) | |
| kwargs["true_cfg_scale"] = float(params.get("cfg", 4.0)) | |
| with torch.inference_mode(): | |
| return self.pipe(**kwargs).images[0] | |