-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from sangww/main
added an API layer
- Loading branch information
Showing
2 changed files
with
436 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.