{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "12f51647", "metadata": {}, "outputs": [], "source": [ "import torch\n", "from diffusers import Flux2Pipeline\n", "from diffusers.utils import load_image\n", "from PIL import Image\n", "\n", "repo_id = \"diffusers/FLUX.2-dev-bnb-4bit\" #quantized text-encoder and DiT. VAE still in bf16\n", "device = \"cuda:0\"\n", "torch_dtype = torch.bfloat16\n", "\n", "# ローカルでテキストエンコーダーを含む完全なパイプラインをロード\n", "pipe = Flux2Pipeline.from_pretrained(\n", " repo_id, torch_dtype=torch_dtype\n", ").to(device)\n", "\n", "# メモリ最適化(オプション)\n", "pipe.enable_model_cpu_offload()\n", "\n", "prompt = \"make the hand-drawn blueprint to a computer-created blueprint. Line drawing, with monochrome. delete all text, dimensions and unnecessary lines. make the line straight and clean. make the circle perfect. remove the shadow and background. only keep the blueprint lines.\"\n", "\n", "# prompt = \"convert the input image into a top-down view..\"\n", "# cat_image = load_image(\"https://huggingface.co/spaces/zerogpu-aoti/FLUX.1-Kontext-Dev-fp8-dynamic/resolve/main/cat.png\")\n", "input_image = Image.open('/home/localuser/Documents/flux2/l_ay4328_diymama03_fig04_w590.jpg')\n", "image = pipe(\n", " prompt=prompt, # prompt_embedsではなくpromptを直接渡す(ローカルでエンコード)\n", " image=[input_image], #optional multi-image input\n", " generator=torch.Generator(device=device).manual_seed(42),\n", " num_inference_steps=28, #28 steps can be a good trade-off\n", " guidance_scale=4\n", ").images[0]\n", "\n", "image.save(\"flux2_output_top_down.png\")" ] } ], "metadata": { "kernelspec": { "display_name": "flux", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.6" } }, "nbformat": 4, "nbformat_minor": 5 }