Skip to content

Commit

Permalink
Merge pull request #194 from sangww/main
Browse files Browse the repository at this point in the history
added an API layer
  • Loading branch information
Mikubill committed Feb 20, 2023
2 parents a8c5b4e + baf0c9c commit 5fed282
Show file tree
Hide file tree
Showing 2 changed files with 436 additions and 0 deletions.
63 changes: 63 additions & 0 deletions example/test_api.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"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",
" }\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": {
"language_info": {
"name": "python"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 5fed282

Please sign in to comment.