|
4 | 4 | "cell_type": "code",
|
5 | 5 | "execution_count": null,
|
6 | 6 | "metadata": {},
|
7 |
| - "outputs": [ |
8 |
| - { |
9 |
| - "ename": "", |
10 |
| - "evalue": "", |
11 |
| - "output_type": "error", |
12 |
| - "traceback": [ |
13 |
| - "\u001b[1;31mThe kernel failed to start as '/root/mambaforge/envs/webui/lib/python3.10/site-packages/psutil/_psutil_linux.cpython-310-x86_64-linux-gnu.so' could not be imported from '5.9.2 instead of 5.9.4'.\n", |
14 |
| - "\u001b[1;31mClick <a href='https://aka.ms/kernelFailuresModuleImportErrFromFile'>here</a> for more info." |
15 |
| - ] |
16 |
| - } |
17 |
| - ], |
| 7 | + "outputs": [], |
18 | 8 | "source": [
|
19 | 9 | "# controlnet + txt2img\n",
|
| 10 | + "# enable `Allow other script to control this extension` in settings\n", |
| 11 | + "\n", |
20 | 12 | "import requests\n",
|
21 | 13 | "import cv2\n",
|
22 | 14 | "from base64 import b64encode\n",
|
|
27 | 19 | " b64img = b64encode(buffer).decode(\"utf-8\")\n",
|
28 | 20 | " return b64img\n",
|
29 | 21 | "\n",
|
30 |
| - "\n", |
31 |
| - "b64img = readImage(\"test.png\")\n", |
| 22 | + "b64img = readImage(\"/root/workspace/nahida/0e17302b9bfa15402f783c29c0d1d34f.jpg\")\n", |
32 | 23 | "\n",
|
33 | 24 | "class controlnetRequest():\n",
|
34 | 25 | " def __init__(self, prompt):\n",
|
35 |
| - " self.url = \"http://localhost:7777/controlnet/txt2img\"\n", |
| 26 | + " self.url = \"http://localhost:7860/controlnet/txt2img\"\n", |
36 | 27 | " self.body = {\n",
|
37 | 28 | " \"prompt\": prompt,\n",
|
38 | 29 | " \"negative_prompt\": \"\",\n",
|
|
44 | 35 | " \"steps\": 15,\n",
|
45 | 36 | " \"cfg_scale\": 7,\n",
|
46 | 37 | " \"width\": 512,\n",
|
47 |
| - " \"height\": 512,\n", |
| 38 | + " \"height\": 768,\n", |
48 | 39 | " \"restore_faces\": True,\n",
|
49 | 40 | " \"eta\": 0,\n",
|
50 | 41 | " \"sampler_index\": \"Euler a\",\n",
|
51 | 42 | " \"controlnet_input_image\": [b64img],\n",
|
52 |
| - " \"controlnet_module\": 'openpose',\n", |
53 |
| - " \"controlnet_model\": 'control_sd15_openpose [fef5e48e]',\n", |
| 43 | + " \"controlnet_module\": 'canny',\n", |
| 44 | + " \"controlnet_model\": 'control_canny-fp16 [e3fe7712]',\n", |
54 | 45 | " \"controlnet_guidance\": 1.0,\n",
|
55 | 46 | " }\n",
|
56 | 47 | "\n",
|
57 | 48 | " def sendRequest(self):\n",
|
58 | 49 | " r = requests.post(self.url, json=self.body)\n",
|
59 | 50 | " return r.json()\n",
|
60 | 51 | "\n",
|
61 |
| - "js = controlnetRequest(\"walter white\").sendRequest()\n", |
62 |
| - "print(js)" |
| 52 | + "js = controlnetRequest(\"walter white\").sendRequest()" |
| 53 | + ] |
| 54 | + }, |
| 55 | + { |
| 56 | + "cell_type": "code", |
| 57 | + "execution_count": null, |
| 58 | + "metadata": {}, |
| 59 | + "outputs": [], |
| 60 | + "source": [ |
| 61 | + "import io, base64\n", |
| 62 | + "import matplotlib.pyplot as plt\n", |
| 63 | + "from PIL import Image\n", |
| 64 | + "\n", |
| 65 | + "pil_img = Image.open('/root/workspace/nahida/0e17302b9bfa15402f783c29c0d1d34f.jpg')\n", |
| 66 | + "image = Image.open(io.BytesIO(base64.b64decode(js[\"images\"][0])))\n", |
| 67 | + "mask_image = Image.open(io.BytesIO(base64.b64decode(js[\"images\"][1])))\n", |
| 68 | + "\n", |
| 69 | + "plt.figure()\n", |
| 70 | + "f, axarr = plt.subplots(1,3) \n", |
| 71 | + "axarr[0].imshow(pil_img) \n", |
| 72 | + "axarr[1].imshow(image) \n", |
| 73 | + "axarr[2].imshow(mask_image) " |
63 | 74 | ]
|
64 | 75 | }
|
65 | 76 | ],
|
66 | 77 | "metadata": {
|
67 | 78 | "kernelspec": {
|
68 |
| - "display_name": "webui", |
| 79 | + "display_name": "pynb", |
69 | 80 | "language": "python",
|
70 | 81 | "name": "python3"
|
71 | 82 | },
|
72 | 83 | "language_info": {
|
| 84 | + "codemirror_mode": { |
| 85 | + "name": "ipython", |
| 86 | + "version": 3 |
| 87 | + }, |
| 88 | + "file_extension": ".py", |
| 89 | + "mimetype": "text/x-python", |
73 | 90 | "name": "python",
|
74 |
| - "version": "3.10.8" |
| 91 | + "nbconvert_exporter": "python", |
| 92 | + "pygments_lexer": "ipython3", |
| 93 | + "version": "3.10.9" |
75 | 94 | },
|
76 | 95 | "orig_nbformat": 4,
|
77 | 96 | "vscode": {
|
78 | 97 | "interpreter": {
|
79 |
| - "hash": "bfdc572d05de84b0e25b3cefadad3fe196a31650b582a0267180110287606d68" |
| 98 | + "hash": "d73345514d8c18d9a1da7351d222dbd2834c7f4a09e728a0d1f4c4580fbec206" |
80 | 99 | }
|
81 | 100 | }
|
82 | 101 | },
|
|
0 commit comments