File size: 4,295 Bytes
370092f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
{
 "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=<V3TaskResponseStatus.TASK_STATUS_SUCCEED: 'TASK_STATUS_SUCCEED'>), 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
}