{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "ename": "", "evalue": "", "output_type": "error", "traceback": [ "\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", "\u001b[1;31mClick here for more info." ] } ], "source": [ "# controlnet + txt2img\n", "import requests\n", "import cv2\n", "from base64 import b64encode\n", "\n", "def readImage(path):\n", " img = cv2.imread(path)\n", " retval, buffer = cv2.imencode('.jpg', img)\n", " b64img = b64encode(buffer).decode(\"utf-8\")\n", " return b64img\n", "\n", "\n", "b64img = readImage(\"test.png\")\n", "\n", "class controlnetRequest():\n", " def __init__(self, prompt):\n", " self.url = \"http://localhost:7777/controlnet/txt2img\"\n", " self.body = {\n", " \"prompt\": prompt,\n", " \"negative_prompt\": \"\",\n", " \"seed\": -1,\n", " \"subseed\": -1,\n", " \"subseed_strength\": 0,\n", " \"batch_size\": 1,\n", " \"n_iter\": 1,\n", " \"steps\": 15,\n", " \"cfg_scale\": 7,\n", " \"width\": 512,\n", " \"height\": 512,\n", " \"restore_faces\": True,\n", " \"eta\": 0,\n", " \"sampler_index\": \"Euler a\",\n", " \"controlnet_input_image\": [b64img],\n", " \"controlnet_module\": 'openpose',\n", " \"controlnet_model\": 'control_sd15_openpose [fef5e48e]',\n", " \"controlnet_guidance\": 1.0,\n", " }\n", "\n", " def sendRequest(self):\n", " r = requests.post(self.url, json=self.body)\n", " return r.json()\n", "\n", "js = controlnetRequest(\"walter white\").sendRequest()\n", "print(js)" ] } ], "metadata": { "kernelspec": { "display_name": "webui", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.10.8" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "bfdc572d05de84b0e25b3cefadad3fe196a31650b582a0267180110287606d68" } } }, "nbformat": 4, "nbformat_minor": 2 }