{ "cells": [ { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "api_key = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'\n", "api_path = '/v3/async/instant-id'\n", "\n", "payload_data = {\n", "\t'extra': {\n", "\t\t'response_image_type': 'jpeg'\n", "\t},\n", "\t'model_name': 'sd_xl_base_1.0.safetensors',\n", "\t'face_image_assets_ids': [\n", "\t\t'cjIvbm92aXRhLWFpLWFzc2V0L2ltYWdlL1JtRDduaU16d3ljTWJOY0hCaXNYM1lwZDNkMnk2YVpl'\n", "\t],\n", "\t'ref_image_assets_ids': [\n", "\t\t'cjIvbm92aXRhLWFpLWFzc2V0L2ltYWdlL1R6WHNyYXdQRlBRZEp6bkJISDd3aHhkU3hOY0ZXc2FD'\n", "\t],\n", "\t'prompt': 'concept art of a man . digital artwork, illustrative, painterly, matte painting, highly detailed',\n", "\t'negative_prompt': 'realistic, photo-realistic, bad quality, bad anatomy, worst quality, low quality, lowres, extra fingers, blur, blurry, ugly, wrong proportions, watermark, image artifacts, bad eyes, bad hands, bad arms',\n", "\t'controlnet': {\n", "\t\t'units': [\n", "\t\t\t{\n", "\t\t\t\t'model_name': 'controlnet-openpose-sdxl-1.0',\n", "\t\t\t\t'strength': None,\n", "\t\t\t\t'guidance_start': None,\n", "\t\t\t\t'guidance_end': None,\n", "\t\t\t\t'preprocessor': 'openpose'\n", "\t\t\t}\n", "\t\t]\n", "\t},\n", "\t'loras': [\n", "\t\t{\n", "\t\t\t'model_name': 'xl_more_art-full_v1_113467.safetensors',\n", "\t\t\t'strength': 0.8\n", "\t\t}\n", "\t],\n", "\t'id_strength': None,\n", "\t'adapter_strength': None,\n", "\t'width': 768,\n", "\t'height': 1024,\n", "\t'image_num': 1,\n", "\t'steps': 25,\n", "\t'seed': -1,\n", "\t'guidance_scale': 7.5,\n", "\t'sampler_name': 'Euler a',\n", "\t'clip_skip': None\n", "}\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import requests\n", "import json\n", "\n", "\n", "headers = {\n", "\t'Content-type': 'application/json',\n", "\t'Authorization': f'Bearer {api_key}',\n", "}\n", "\n", "response = requests.request('POST', f'https://api.novita.ai{api_path}', headers=headers, data=json.dumps(payload_data))\n", "response.text\n" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'task_id': 'fe2701c1-7c5c-43ef-8570-ad7cbce850a3'}" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from novita_client import NovitaClient\n", "\n", "\n", "client = NovitaClient(api_key)\n", "\n", "res = client._post('/v3/async/instant-id', payload_data)\n", "res" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "V3TaskResponse(task=V3TaskResponseTask(task_id='fe2701c1-7c5c-43ef-8570-ad7cbce850a3', status=), images=[V3TaskImage(image_url='https://faas-output-image.s3.ap-southeast-1.amazonaws.com/prod/fe2701c1-7c5c-43ef-8570-ad7cbce850a3/2a889ab96bc946d5af40115ae47ccd46.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240227%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240227T114145Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=7b71d07fc5cdc68eca8f0ef356a3139a2932dec78897ef0482ec36aac036042b', image_type='jpeg', image_url_ttl=3600)], videos=[])" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "res2 = client.wait_for_task_v3(res['task_id'])\n", "res2" ] } ], "metadata": { "kernelspec": { "display_name": "env", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.1" } }, "nbformat": 4, "nbformat_minor": 2 }