Spaces:
Running
on
Zero
Running
on
Zero
File size: 4,830 Bytes
323d67d 6bae58f 323d67d 6bae58f 323d67d 6bae58f 323d67d |
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Artisitc Portrait Gen"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import torch\n",
"from artistic_portrait.pipeline import ArtisticPortraitXLPipeline\n",
"from diffusers import ControlNetModel\n",
"from PIL import Image\n",
"from ip_adapter_diffusers.ip_adapter import *\n",
"from diffusers import DPMSolverMultistepScheduler\n",
"from huggingface_hub import hf_hub_download\n",
"import os"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"device = \"cuda\"\n",
"dtype = torch.float16\n",
"style_adapter_path = \"models/ip_adapter_art_sdxl_512.pth\"\n",
"id_adapter_path = \"models/pulid_adapter_diffusers_1.1.pth\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if not os.path.exists(\"models/csd_clip.pth\"):\n",
" hf_hub_download(\n",
" repo_id=\"AisingioroHao0/IP-Adapter-Art\",\n",
" filename=\"csd_clip.pth\",\n",
" local_dir=\"models\",\n",
" )\n",
"if not os.path.exists(style_adapter_path):\n",
" hf_hub_download(\n",
" repo_id=\"AisingioroHao0/IP-Adapter-Art\",\n",
" filename=\"ip_adapter_art_sdxl_512.pth\",\n",
" local_dir=\"models\",\n",
" )\n",
"if not os.path.exists(id_adapter_path):\n",
" hf_hub_download(\n",
" repo_id=\"AisingioroHao0/IP-Adapter-Art\",\n",
" filename=\"pulid_adapter_diffusers_1.1.pth\",\n",
" local_dir=\"models\",\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"controlnet = ControlNetModel.from_pretrained(\n",
" \"xinsir/controlnet-openpose-sdxl-1.0\",\n",
" torch_dtype=dtype,\n",
").to(device)\n",
"pipe = ArtisticPortraitXLPipeline.from_pretrained(\n",
" \"stabilityai/stable-diffusion-xl-base-1.0\",\n",
" controlnet=controlnet,\n",
" safety_checker=None,\n",
" torch_dtype=torch.float16,\n",
" style_adapter_path=style_adapter_path,\n",
" id_adapter_path=id_adapter_path,\n",
" variant=\"fp16\",\n",
" device=device,\n",
").to(device)\n",
"pipe.scheduler = DPMSolverMultistepScheduler.from_config(\n",
" pipe.scheduler.config, timestep_spacing=\"trailing\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"height = 1024\n",
"width = 1024\n",
"artify_controlnet_scale = 0.0\n",
"style_scale = 1.0\n",
"id_scale = 1.0\n",
"controlnet_scale = 0.9\n",
"\n",
"if artify_controlnet_scale > 0:\n",
" pipe.load_style_adapter_to_controlnet(style_adapter_path)\n",
" set_ip_adapter_scale(pipe.controlnet, artify_controlnet_scale)\n",
"\n",
"style_image = Image.open(\"datasets/test/style_dataset/Abstract D'Oyley.jpg\")\n",
"id_image = Image.open(\"datasets/test/id_dataset/hinton.jpg\")\n",
"pose_image = Image.open(\"datasets/test/pose.jpg\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"result = pipe(\n",
" f\"portrait, solo, looking at viewer, best quality, masterpiece\",\n",
" negative_prompt=\"flaws in the eyes, flaws in the face, flaws, lowres, non-HDRi, low quality, worst quality,artifacts noise, text, watermark, glitch, deformed, mutated, ugly, disfigured, hands, low resolution, partially rendered objects, deformed or partially rendered eyes, deformed, deformed eyeballs, cross-eyed\",\n",
" control_image=pose_image,\n",
" controlnet_conditioning_scale=controlnet_scale,\n",
" width=width,\n",
" height=height,\n",
" num_inference_steps=20,\n",
" guidance_scale=7,\n",
" style_image=style_image,\n",
" id_image=id_image,\n",
" generator=torch.Generator(\"cuda\").manual_seed(42),\n",
" id_scale=1.0,\n",
" style_scale=1.0,\n",
" # num_zero=[None, 16],\n",
" # ortho=[None, 'ortho_v2'],\n",
").images[0]\n",
"result"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.10.16"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|