Views
No views yet

1HF_TOKEN=hf_aBcD1234 \
2 uv run --with git+https://github.com/finegrain-ai/finegrain-toolbox \
3 python foo.py1from pathlib import Path
2
3import torch
4from finegrain_toolbox.flux import Model, TextEncoder
5from finegrain_toolbox.processors import product_placement
6from huggingface_hub import hf_hub_download
7from PIL import Image
8
9device = torch.device("cuda")
10dtype = torch.bfloat16
11
12model = Model.from_pretrained(
13 "black-forest-labs/FLUX.1-Kontext-dev",
14 device=device,
15 dtype=dtype,
16)
17
18text_encoder = TextEncoder.from_pretrained(
19 "black-forest-labs/FLUX.1-Kontext-dev",
20 device=device,
21 dtype=dtype,
22)
23
24lora_path = Path(
25 hf_hub_download(
26 repo_id="finegrain/finegrain-product-placement-lora",
27 filename="finegrain-placement-v1-rank8.safetensors",
28 )
29)
30
31prompt = text_encoder.encode("Add this in the box")
32
33model.transformer.load_lora_adapter(lora_path, adapter_name="inserter")
34
35scene_image = Image.open("scene.webp")
36reference = Image.open("reference.webp")
37bbox = (1085, 1337, 1737, 3077)
38
39result = product_placement.process(
40 model=model,
41 scene=scene_image,
42 reference=reference,
43 bbox=bbox,
44 prompt=prompt,
45)
46
47result.output.save("output.webp")1@misc{fg2025pplace,
2 author = {The Finegrain Team},
3 title = {Finegrain Product Placement LoRA},
4 year = {2025},
5 publisher = {HuggingFace},
6}