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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"nbformat": 4,
|
3 |
+
"nbformat_minor": 0,
|
4 |
+
"metadata": {
|
5 |
+
"colab": {
|
6 |
+
"provenance": [],
|
7 |
+
"gpuType": "T4"
|
8 |
+
},
|
9 |
+
"kernelspec": {
|
10 |
+
"name": "python3",
|
11 |
+
"display_name": "Python 3"
|
12 |
+
},
|
13 |
+
"language_info": {
|
14 |
+
"name": "python"
|
15 |
+
},
|
16 |
+
"accelerator": "GPU"
|
17 |
+
},
|
18 |
+
"cells": [
|
19 |
+
{
|
20 |
+
"cell_type": "markdown",
|
21 |
+
"source": [
|
22 |
+
"Install the library"
|
23 |
+
],
|
24 |
+
"metadata": {
|
25 |
+
"id": "BV2F3IkW7lT5"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
{
|
29 |
+
"cell_type": "code",
|
30 |
+
"source": [
|
31 |
+
"!pip install diffusers\n",
|
32 |
+
"!pip install Pillow"
|
33 |
+
],
|
34 |
+
"metadata": {
|
35 |
+
"id": "f5RXwnZi7ql2",
|
36 |
+
"colab": {
|
37 |
+
"base_uri": "https://localhost:8080/"
|
38 |
+
},
|
39 |
+
"outputId": "61617fd7-6aa0-42bc-d07b-1cd1c67ec43d"
|
40 |
+
},
|
41 |
+
"execution_count": null,
|
42 |
+
"outputs": [
|
43 |
+
{
|
44 |
+
"output_type": "stream",
|
45 |
+
"name": "stdout",
|
46 |
+
"text": [
|
47 |
+
"Collecting diffusers\n",
|
48 |
+
" Downloading diffusers-0.29.2-py3-none-any.whl.metadata (19 kB)\n",
|
49 |
+
"Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.10/dist-packages (from diffusers) (8.2.0)\n",
|
50 |
+
"Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from diffusers) (3.15.4)\n",
|
51 |
+
"Requirement already satisfied: huggingface-hub>=0.23.2 in /usr/local/lib/python3.10/dist-packages (from diffusers) (0.23.5)\n",
|
52 |
+
"Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from diffusers) (1.26.4)\n",
|
53 |
+
"Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.10/dist-packages (from diffusers) (2024.5.15)\n",
|
54 |
+
"Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from diffusers) (2.31.0)\n",
|
55 |
+
"Requirement already satisfied: safetensors>=0.3.1 in /usr/local/lib/python3.10/dist-packages (from diffusers) (0.4.3)\n",
|
56 |
+
"Requirement already satisfied: Pillow in /usr/local/lib/python3.10/dist-packages (from diffusers) (9.4.0)\n",
|
57 |
+
"Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.23.2->diffusers) (2024.6.1)\n",
|
58 |
+
"Requirement already satisfied: packaging>=20.9 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.23.2->diffusers) (24.1)\n",
|
59 |
+
"Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.23.2->diffusers) (6.0.1)\n",
|
60 |
+
"Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.23.2->diffusers) (4.66.4)\n",
|
61 |
+
"Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.23.2->diffusers) (4.12.2)\n",
|
62 |
+
"Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.10/dist-packages (from importlib-metadata->diffusers) (3.19.2)\n",
|
63 |
+
"Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->diffusers) (3.3.2)\n",
|
64 |
+
"Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->diffusers) (3.7)\n",
|
65 |
+
"Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->diffusers) (2.0.7)\n",
|
66 |
+
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->diffusers) (2024.7.4)\n",
|
67 |
+
"Downloading diffusers-0.29.2-py3-none-any.whl (2.2 MB)\n",
|
68 |
+
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m2.2/2.2 MB\u001b[0m \u001b[31m38.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
69 |
+
"\u001b[?25hInstalling collected packages: diffusers\n",
|
70 |
+
"Successfully installed diffusers-0.29.2\n",
|
71 |
+
"Requirement already satisfied: Pillow in /usr/local/lib/python3.10/dist-packages (9.4.0)\n"
|
72 |
+
]
|
73 |
+
}
|
74 |
+
]
|
75 |
+
},
|
76 |
+
{
|
77 |
+
"cell_type": "markdown",
|
78 |
+
"source": [
|
79 |
+
"Importation Class Fron Library"
|
80 |
+
],
|
81 |
+
"metadata": {
|
82 |
+
"id": "yCM1UVvK87D6"
|
83 |
+
}
|
84 |
+
},
|
85 |
+
{
|
86 |
+
"cell_type": "code",
|
87 |
+
"execution_count": null,
|
88 |
+
"metadata": {
|
89 |
+
"id": "oQZ9MSf33sJo",
|
90 |
+
"colab": {
|
91 |
+
"base_uri": "https://localhost:8080/"
|
92 |
+
},
|
93 |
+
"outputId": "1cf4be43-fc01-4f17-f3f5-38ff0c1b5fc7"
|
94 |
+
},
|
95 |
+
"outputs": [
|
96 |
+
{
|
97 |
+
"output_type": "stream",
|
98 |
+
"name": "stderr",
|
99 |
+
"text": [
|
100 |
+
"/usr/local/lib/python3.10/dist-packages/diffusers/models/vq_model.py:20: FutureWarning: `VQEncoderOutput` is deprecated and will be removed in version 0.31. Importing `VQEncoderOutput` from `diffusers.models.vq_model` is deprecated and this will be removed in a future version. Please use `from diffusers.models.autoencoders.vq_model import VQEncoderOutput`, instead.\n",
|
101 |
+
" deprecate(\"VQEncoderOutput\", \"0.31\", deprecation_message)\n",
|
102 |
+
"/usr/local/lib/python3.10/dist-packages/diffusers/models/vq_model.py:25: FutureWarning: `VQModel` is deprecated and will be removed in version 0.31. Importing `VQModel` from `diffusers.models.vq_model` is deprecated and this will be removed in a future version. Please use `from diffusers.models.autoencoders.vq_model import VQModel`, instead.\n",
|
103 |
+
" deprecate(\"VQModel\", \"0.31\", deprecation_message)\n"
|
104 |
+
]
|
105 |
+
}
|
106 |
+
],
|
107 |
+
"source": [
|
108 |
+
"import torch\n",
|
109 |
+
"from diffusers import AutoPipelineForImage2Image\n",
|
110 |
+
"from diffusers.utils import load_image, make_image_grid\n",
|
111 |
+
"from PIL import Image"
|
112 |
+
]
|
113 |
+
},
|
114 |
+
{
|
115 |
+
"cell_type": "markdown",
|
116 |
+
"source": [
|
117 |
+
"Defiende Model"
|
118 |
+
],
|
119 |
+
"metadata": {
|
120 |
+
"id": "Hdz_Sdza5dH0"
|
121 |
+
}
|
122 |
+
},
|
123 |
+
{
|
124 |
+
"cell_type": "code",
|
125 |
+
"source": [
|
126 |
+
"Model_ID = \"kandinsky-community/kandinsky-2-2-decoder\""
|
127 |
+
],
|
128 |
+
"metadata": {
|
129 |
+
"id": "EWWt67554KUE"
|
130 |
+
},
|
131 |
+
"execution_count": null,
|
132 |
+
"outputs": []
|
133 |
+
},
|
134 |
+
{
|
135 |
+
"cell_type": "markdown",
|
136 |
+
"source": [
|
137 |
+
"Load a checkpoint into the AutoPipelineForImage2Image class"
|
138 |
+
],
|
139 |
+
"metadata": {
|
140 |
+
"id": "ZF7YAu_E4-66"
|
141 |
+
}
|
142 |
+
},
|
143 |
+
{
|
144 |
+
"cell_type": "code",
|
145 |
+
"source": [
|
146 |
+
"!pip inst"
|
147 |
+
],
|
148 |
+
"metadata": {
|
149 |
+
"id": "z0PK-qjXjfg4"
|
150 |
+
},
|
151 |
+
"execution_count": null,
|
152 |
+
"outputs": []
|
153 |
+
},
|
154 |
+
{
|
155 |
+
"cell_type": "code",
|
156 |
+
"source": [
|
157 |
+
"pipeline = AutoPipelineForImage2Image.from_pretrained(\n",
|
158 |
+
" Model_ID, torch_dtype=torch.float16, use_safetensors=True\n",
|
159 |
+
")\n",
|
160 |
+
"pipeline.enable_model_cpu_offload()\n",
|
161 |
+
"# remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed\n",
|
162 |
+
"pipeline.enable_xformers_memory_efficient_attention()"
|
163 |
+
],
|
164 |
+
"metadata": {
|
165 |
+
"id": "ouPl34nS3-J-"
|
166 |
+
},
|
167 |
+
"execution_count": null,
|
168 |
+
"outputs": []
|
169 |
+
},
|
170 |
+
{
|
171 |
+
"cell_type": "markdown",
|
172 |
+
"source": [
|
173 |
+
"Load an image to pass to the pipeline:"
|
174 |
+
],
|
175 |
+
"metadata": {
|
176 |
+
"id": "anRfKcIW4xTz"
|
177 |
+
}
|
178 |
+
},
|
179 |
+
{
|
180 |
+
"cell_type": "code",
|
181 |
+
"source": [
|
182 |
+
"init_image = Image.open('/content/sample_data/New file (2).png')"
|
183 |
+
],
|
184 |
+
"metadata": {
|
185 |
+
"id": "HsAxLauF5pnE"
|
186 |
+
},
|
187 |
+
"execution_count": null,
|
188 |
+
"outputs": []
|
189 |
+
},
|
190 |
+
{
|
191 |
+
"cell_type": "markdown",
|
192 |
+
"source": [
|
193 |
+
"Write Prompt"
|
194 |
+
],
|
195 |
+
"metadata": {
|
196 |
+
"id": "oJSACBLt5_Sj"
|
197 |
+
}
|
198 |
+
},
|
199 |
+
{
|
200 |
+
"cell_type": "code",
|
201 |
+
"source": [
|
202 |
+
"prompt = \"3D Mesh Model Head Cat, Rendrer Object Mode, detailed, cute, adorable, 8k\""
|
203 |
+
],
|
204 |
+
"metadata": {
|
205 |
+
"id": "3ngRjHTY6ISS"
|
206 |
+
},
|
207 |
+
"execution_count": null,
|
208 |
+
"outputs": []
|
209 |
+
},
|
210 |
+
{
|
211 |
+
"cell_type": "markdown",
|
212 |
+
"source": [
|
213 |
+
"Pass a prompt and image to the pipeline to generate an image:"
|
214 |
+
],
|
215 |
+
"metadata": {
|
216 |
+
"id": "HBFMaceZ6bp3"
|
217 |
+
}
|
218 |
+
},
|
219 |
+
{
|
220 |
+
"cell_type": "code",
|
221 |
+
"source": [
|
222 |
+
"image = pipeline(prompt, image=init_image).images[0]"
|
223 |
+
],
|
224 |
+
"metadata": {
|
225 |
+
"id": "T1EoPGoR6e0Z"
|
226 |
+
},
|
227 |
+
"execution_count": null,
|
228 |
+
"outputs": []
|
229 |
+
},
|
230 |
+
{
|
231 |
+
"cell_type": "markdown",
|
232 |
+
"source": [
|
233 |
+
"Display the image (optional)"
|
234 |
+
],
|
235 |
+
"metadata": {
|
236 |
+
"id": "xqEmoIFD8lsH"
|
237 |
+
}
|
238 |
+
},
|
239 |
+
{
|
240 |
+
"cell_type": "code",
|
241 |
+
"source": [
|
242 |
+
"make_image_grid([init_image, image], rows=1, cols=2)"
|
243 |
+
],
|
244 |
+
"metadata": {
|
245 |
+
"id": "QPwjH7th8rQB"
|
246 |
+
},
|
247 |
+
"execution_count": null,
|
248 |
+
"outputs": []
|
249 |
+
}
|
250 |
+
]
|
251 |
+
}
|