-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapi.py
479 lines (437 loc) · 29.6 KB
/
api.py
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
import os
import shutil
import traceback
import timeit
from datetime import datetime
import sys
from src import utils
from src import console
from gradio_client import Client
class ConfigApi:
def __init__(self):
self.ping=29
self.cancel=0
self.init=51
self.generate=67
self.models=46
self.styles=64
self.checkDelta=False
self.delta=0
self.deltaPing=0
self.deltaCancel=0
self.deltaInit=0
self.deltaGenerate=0
self.deltaModels=0
self.deltaStyles=0
class FooocusApi:
def __init__(self, base_url, outputFolder, FOOOCUS_MIN_RELEASE):
self.FOOOCUS_MIN_RELEASE=FOOOCUS_MIN_RELEASE
self.config=ConfigApi()
self.client=None
self.outputFolder=outputFolder
if base_url[0:7] != "http://"[0:7]:
base_url="http://"+base_url
self.base_url = base_url.strip()
self.emptyImage="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg=="
def getClient(self):
if (self.client==None):
# print("Open API client to Fooocus instance at "+self.base_url+" ...")
try:
self.client = Client(self.base_url, serialize=False)
console.printBB("[ok]Great! FoooXus is now connected to Fooocus[/ok]")
return self.client
except Exception as e:
self.client=None
console.printBB("[error]Connection to Fooocus failed...[/error]")
exceptionName=type(e).__name__
if exceptionName=="ConnectionError":
console.printBB("[error] ConnectionError, check that:[/error]")
console.printBB("[error] - Fooocus must be running, on the same device[/error]")
console.printBB("[error] - Fooocus address config.json is set to "+self.base_url+" [/error]")
else:
console.printBB("[error] "+exceptionName+"[/error]")
print(f"{e}")
print("")
return None
else:
return self.client
# Ping Fooocus instance
def pingFooocus(self, firstCall=False):
try:
client=self.getClient()
if(client is None):
# Not connected, so no call to predict
return {"ajax":True, "error":True}
result = client.predict( fn_index=self.config.ping+self.config.deltaPing )
if firstCall:
console.printBB("[ok]FoooXus is connected to Fooocus. Let's play in the web UI ![/ok]")
return {"ajax":True, "error":False, "ping":True, "fooocusUrl": self.base_url}
except Exception as e:
if self.config.deltaPing<=10:
console.printBB("[warning]pingFooocus() failed. Trying to find the right gradio API fn_index ("+str(self.config.ping)+"+"+str(self.config.deltaPing)+")[/warning]")
self.config.deltaPing+=1
#self.config.deltaInit+=1
#self.config.deltaGenerate+=1
#self.config.deltaCancel+=1
#self.config.deltaStyles+=1
self.config.deltaModels+=1
return self.pingFooocus(firstCall)
else:
console.printExceptionError(e)
console.printBB("[error]FoooXus is not connected to Fooocus gradio API :([/error]")
console.printBB("[error] - Fooocus must be running, on the same device[/error]")
console.printBB("[error] - Fooocus must be at least "+self.FOOOCUS_MIN_RELEASE+"[/error]")
console.printBB("[error] - If FoooXus app has already worked, Fooocus may have changed version.[/error]")
console.printBB("[error] it may break API calls[/error]")
console.printBB("")
return {"ajax":True, "error":True}
# Cancel generation
def sendCancel(self):
try:
console.printBB("[b] /!\ You have canceled the queue[/b]")
console.printBB("[b] [/b]")
result = self.getClient().predict( fn_index=self.config.cancel )
return {"ajax":True, "error":False}
except Exception as e:
console.printExceptionError(e)
return {"ajax":True, "error":True}
# Get list of all models installed on the Fooocus folder
def getModels(self):
try:
result = self.getClient().predict( fn_index=self.config.models+self.config.deltaModels )
models=[]
if (result[0]):
if (result[0]["choices"]):
for model in result[0]["choices"]:
models.append(model)
return {"ajax":True, "error":False, "models":models}
except Exception as e:
if self.config.deltaModels<10:
console.printBB("[warning]getModels() failed. Trying to find the right gradio API fn_index (i+"+str(self.config.deltaModels)+")[/warning]")
self.config.deltaModels+=1
self.config.deltaInit+=1
self.config.deltaGenerate+=1
return self.getModels()
else:
print("[error] getModels exception[/error]")
print(f"Error: {e}")
return {"ajax":True, "error":True}
# Get all styles available for Fooocus
def getStyles(self):
try:
result = self.getClient().predict( [], fn_index=self.config.styles+self.config.deltaStyles )
styles=[]
if ("choices" in result):
for style in result["choices"]:
if style[0]!="Random Style":
styles.append(style[0])
return {"ajax":True, "error":False, "styles":styles}
except:
if self.config.deltaStyles<10:
console.printBB("[warning]getStyles() failed. Trying to find the right gradio API fn_index (i+"+str(self.config.deltaStyles)+")[/warning]")
self.config.deltaStyles+=1
self.config.deltaModels+=1
self.config.deltaInit+=1
self.config.deltaGenerate+=1
return self.getStyles()
else:
return {"ajax":True, "error":True}
# Get all Loras from the loras-directory
def getLoras(self, dir):
try:
loras=utils.getFiles(dir, ".safetensors")
return {"ajax":True, "error":False, "loras":loras}
except:
return {"ajax":True, "error":True}
# InitFooocus does not exist since Fooocus V2.2.1. All parameters in CreateImage
def initFooocus(self, metadata={}):
return False
try:
adm=metadata.get("ADM Guidance").replace("(","").replace(")","")
admSplit=adm.split(", ")
result = self.getClient().predict(
True, # bool in 'Disable Preview' Checkbox component
float(admSplit[0]), # int | float (numeric value between 0.1 and 3.0) in 'Positive ADM Guidance Scaler' Slider component
float(admSplit[1]), # int | float (numeric value between 0.1 and 3.0) in 'Negative ADM Guidance Scaler' Slider component
float(admSplit[2]), # int | float (numeric value between 0.0 and 1.0) in 'ADM Guidance End At Step' Slider component
7, # int | float (numeric value between 1.0 and 30.0) in 'CFG Mimicking from TSNR' Slider component
metadata["Sampler"], # str (Option from: ['euler', 'euler_ancestral', 'heun', 'heunpp2', 'dpm_2', 'dpm_2_ancestral', 'lms', 'dpm_fast', 'dpm_adaptive', 'dpmpp_2s_ancestral', 'dpmpp_sde', 'dpmpp_sde_gpu', 'dpmpp_2m', 'dpmpp_2m_sde', 'dpmpp_2m_sde_gpu', 'dpmpp_3m_sde', 'dpmpp_3m_sde_gpu', 'ddpm', 'lcm', 'ddim', 'uni_pc', 'uni_pc_bh2']) in 'Sampler' Dropdown component
metadata["Scheduler"], # str (Option from: ['normal', 'karras', 'exponential', 'sgm_uniform', 'simple', 'ddim_uniform', 'lcm', 'turbo']) in 'Scheduler' Dropdown component
False, # bool in 'Generate Image Grid for Each Batch' Checkbox component
-1, # int | float (numeric value between -1 and 200) in 'Forced Overwrite of Sampling Step' Slider component
-1, # int | float (numeric value between -1 and 200) in 'Forced Overwrite of Refiner Switch Step' Slider component
-1, # int | float (numeric value between -1 and 2048) in 'Forced Overwrite of Generating Width' Slider component
-1, # int | float (numeric value between -1 and 2048) in 'Forced Overwrite of Generating Height' Slider component
-1, # int | float (numeric value between -1 and 1.0) in 'Forced Overwrite of Denoising Strength of "Vary"' Slider component
-1, # int | float (numeric value between -1 and 1.0) in 'Forced Overwrite of Denoising Strength of "Upscale"' Slider component
False, # bool in 'Mixing Image Prompt and Vary/Upscale' Checkbox component
False, # bool in 'Mixing Image Prompt and Inpaint' Checkbox component
False, # bool in 'Debug Preprocessors' Checkbox component
False, # bool in 'Skip Preprocessors' Checkbox component
0, # int | float (numeric value between 0.0 and 1.0) in 'Softness of ControlNet' Slider component
1, # int | float (numeric value between 1 and 255) in 'Canny Low Threshold' Slider component
1, # int | float (numeric value between 1 and 255) in 'Canny High Threshold' Slider component
"joint", # str (Option from: ['joint', 'separate', 'vae']) in 'Refiner swap method' Dropdown component
False, # bool in 'Enabled' Checkbox component
0, # int | float (numeric value between 0 and 2) in 'B1' Slider component
0, # int | float (numeric value between 0 and 2) in 'B2' Slider component
0, # int | float (numeric value between 0 and 4) in 'S1' Slider component
0, # int | float (numeric value between 0 and 4) in 'S2' Slider component
False, # bool in 'Debug Inpaint Preprocessing' Checkbox component
False, # bool in 'Disable initial latent in inpaint' Checkbox component
"None", # str (Option from: ['None', 'v1', 'v2.5', 'v2.6']) in 'Inpaint Engine' Dropdown component
0, # int | float (numeric value between 0.0 and 1.0) in 'Inpaint Denoising Strength' Slider component
0, # int | float (numeric value between 0.0 and 1.0) in 'Inpaint Respective Field' Slider component
False, # bool in 'Enable Mask Upload' Checkbox component
False, # bool in 'Invert Mask' Checkbox component
-64, # int | float (numeric value between -64 and 64) in 'Mask Erode or Dilate' Slider component
fn_index=self.config.init+self.config.deltaInit
)
return {"ajax":True, "error":False, "init":True}
except Exception as e:
if self.config.deltaInit<10:
console.printBB("[warning]initFooocus() failed. Trying to find the right gradio API fn_index (i+"+str(self.config.deltaInit)+")[/warning]")
self.config.deltaInit+=1
self.config.deltaGenerate+=1
return self.initFooocus(metadata)
else:
print("getModels exception")
print(f"Error: {e}")
return {"ajax":True, "error":True}
def sendCreateImage(self, metadata, uid):
try:
adm=metadata.get("ADM Guidance").replace("(","").replace(")","")
admSplit=adm.split(", ")
start_time = timeit.default_timer()
# self.initFooocus(metadata) # not present in Fooocus V2.2.1
# Check Turbo or Lighting models
now = datetime.now()
console.printBB("[hour]"+now.strftime("%H:%M:%S")+"[/hour] [b]#"+uid+"[/b] New generation asked and sent to Fooocus")
console.printBB(" [fade]Prompt:[/fade] "+metadata["Prompt"])
console.printBB(" [fade]Model:[/fade] "+metadata["Base Model"])
performance=metadata["Performance"]
if "lightning" in metadata["Base Model"].lower():
console.printBB(" [fade]Lightning model:[/fade] "+"Force to Lightning Performance")
performance="Lightning"
if "turbo" in metadata["Base Model"].lower():
console.printBB(" [fade]Turbo model:[/fade] "+"Force to Extreme Speed Performance")
performance="Extreme Speed"
console.printBB(" [fade]Styles:[/fade] "+"," .join(str(s) for s in metadata["Styles"]))
result = self.getClient().predict(
False, # bool in 'Generate Image Grid for Each Batch' Checkbox component
metadata["Prompt"], # str in 'parameter_10' Textbox component
metadata["Negative Prompt"],# str in 'Negative Prompt' Textbox component
metadata["Styles"], # List[str] in 'Selected Styles' Checkboxgroup component
performance, # str in 'Performance' Radio component
'1024×1024', # str in 'Aspect Ratios' Radio component
1, # int | float (numeric value between 1 and 64) in 'Image Number' Slider component
"png", # str in 'Output Format' Radio component
metadata["Seed"], # str in 'Seed' Textbox component
True, # bool in 'Read wildcards in order' Checkbox component
metadata["Sharpness"], # int | float (numeric value between 0.0 and 30.0) in 'Image Sharpness' Slider component
metadata["Guidance Scale"], # int | float (numeric value between 1.0 and 30.0) in 'Guidance Scale' Slider component
metadata["Base Model"], # str in 'Base Model (SDXL only)' Dropdown component
metadata["Refiner Model"], # str in 'Refiner (SDXL or SD 1.5)' Dropdown component
metadata["Refiner Switch"], # int | float (numeric value between 0.1 and 1.0) in 'Refiner Switch At' Slider component
True, # bool in 'Enable' Checkbox component
metadata["Lora 1"], # str in 'LoRA 1' Dropdown component
metadata["Weight Lora 1"], # int | float (numeric value between -2 and 2) in 'Weight' Slider component
True, # bool in 'Enable' Checkbox component
metadata["Lora 2"], # str in 'LoRA 2' Dropdown component
metadata["Weight Lora 2"], # int | float (numeric value between -2 and 2) in 'Weight' Slider component
True, # bool in 'Enable' Checkbox component
metadata["Lora 3"], # str in 'LoRA 3' Dropdown component
metadata["Weight Lora 3"], # int | float (numeric value between -2 and 2) in 'Weight' Slider component
True, # bool in 'Enable' Checkbox component
metadata["Lora 4"], # str in 'LoRA 4' Dropdown component
metadata["Weight Lora 4"], # int | float (numeric value between -2 and 2) in 'Weight' Slider component
True, # bool in 'Enable' Checkbox component
metadata["Lora 5"], # str in 'LoRA 5' Dropdown component
metadata["Weight Lora 5"], # int | float (numeric value between -2 and 2) in 'Weight' Slider component
True, # bool in 'Input Image' Checkbox component
"Howdy!", # str in 'parameter_91' Textbox component
"Disabled", # str in 'Upscale or Variation:' Radio component
self.emptyImage, # str (filepath or URL to image) in 'Drag above image to here' Image component
["Left"], # List[str] in 'Outpaint Direction' Checkboxgroup component
self.emptyImage, # str (filepath or URL to image) in 'Drag inpaint or outpaint image to here' Image component
"Howdy!", # str in 'Inpaint Additional Prompt' Textbox component
self.emptyImage, # str (filepath or URL to image) in 'Mask Upload' Image component
True, # bool in 'Disable Preview' Checkbox component
True, # bool in 'Disable Intermediate Results' Checkbox component
True, # bool in 'Disable seed increment' Checkbox component
False, # bool in 'Black Out NSFW' Checkbox component
float(admSplit[0]), # int | float (numeric value between 0.1 and 3.0) in 'Positive ADM Guidance Scaler' Slider component
float(admSplit[1]), # int | float (numeric value between 0.1 and 3.0) in 'Negative ADM Guidance Scaler' Slider component
float(admSplit[2]), # int | float (numeric value between 0.0 and 1.0) in 'ADM Guidance End At Step' Slider component
7, # int | float (numeric value between 1.0 and 30.0) in 'CFG Mimicking from TSNR' Slider component
1, # int | float (numeric value between 1 and 12) 'CLIP Skip' Slider component
metadata["Sampler"], # str (Option from: ['euler', 'euler_ancestral', 'heun', 'heunpp2', 'dpm_2', 'dpm_2_ancestral', 'lms', 'dpm_fast', 'dpm_adaptive', 'dpmpp_2s_ancestral', 'dpmpp_sde', 'dpmpp_sde_gpu', 'dpmpp_2m', 'dpmpp_2m_sde', 'dpmpp_2m_sde_gpu', 'dpmpp_3m_sde', 'dpmpp_3m_sde_gpu', 'ddpm', 'lcm', 'ddim', 'uni_pc', 'uni_pc_bh2']) in 'Sampler' Dropdown component
metadata["Scheduler"], # str (Option from: ['normal', 'karras', 'exponential', 'sgm_uniform', 'simple', 'ddim_uniform', 'lcm', 'turbo']) in 'Scheduler' Dropdown component
"Default (model)", # str (Option from: ['Default (model)']) 'VAE' Dropdown component
-1, # int | float (numeric value between -1 and 200) in 'Forced Overwrite of Sampling Step' Slider component
-1, # int | float (numeric value between -1 and 200) in 'Forced Overwrite of Refiner Switch Step' Slider component
-1, # int | float (numeric value between -1 and 2048) in 'Forced Overwrite of Generating Width' Slider component
-1, # int | float (numeric value between -1 and 2048) in 'Forced Overwrite of Generating Height' Slider component
-1, # int | float (numeric value between -1 and 1.0) in 'Forced Overwrite of Denoising Strength of "Vary"' Slider component
-1, # int | float (numeric value between -1 and 1.0) in 'Forced Overwrite of Denoising Strength of "Upscale"' Slider component
False, # bool in 'Mixing Image Prompt and Vary/Upscale' Checkbox component
False, # bool in 'Mixing Image Prompt and Inpaint' Checkbox component
False, # bool in 'Debug Preprocessors' Checkbox component
False, # bool in 'Skip Preprocessors' Checkbox component
1, # int | float (numeric value between 1 and 255) in 'Canny Low Threshold' Slider component
1, # int | float (numeric value between 1 and 255) in 'Canny High Threshold' Slider component
"joint", # str (Option from: ['joint', 'separate', 'vae']) in 'Refiner swap method' Dropdown component
0, # int | float (numeric value between 0.0 and 1.0) in 'Softness of ControlNet' Slider component
False, # bool in 'Enabled' Checkbox component
0, # int | float (numeric value between 0 and 2) in 'B1' Slider component
0, # int | float (numeric value between 0 and 2) in 'B2' Slider component
0, # int | float (numeric value between 0 and 4) in 'S1' Slider component
0, # int | float (numeric value between 0 and 4) in 'S2' Slider component
False, # bool in 'Debug Inpaint Preprocessing' Checkbox component
False, # bool in 'Disable initial latent in inpaint' Checkbox component
"None", # str (Option from: ['None', 'v1', 'v2.5', 'v2.6']) in 'Inpaint Engine' Dropdown component
0, # int | float (numeric value between 0.0 and 1.0) in 'Inpaint Denoising Strength' Slider component
0, # int | float (numeric value between 0.0 and 1.0) in 'Inpaint Respective Field' Slider component
False, # bool in 'Enable Mask Upload' Checkbox component
False, # bool in 'Invert Mask' Checkbox component
-64, # int | float (numeric value between -64 and 64) in 'Mask Erode or Dilate' Slider component
False, # bool in 'Save only final enhanced image' Checkbox component
False, # bool in 'Save Metadata to Images' Checkbox component
"fooocus", # str in 'Metadata Scheme' Radio component
self.emptyImage, # str (filepath or URL to image) in 'Image' Image component
0, # int | float (numeric value between 0.0 and 1.0) in 'Stop At' Slider component
0, # int | float (numeric value between 0.0 and 2.0) in 'Weight' Slider component
"ImagePrompt", # str in 'Type' Radio component
self.emptyImage, # str (filepath or URL to image) in 'Image' Image component
0, # int | float (numeric value between 0.0 and 1.0) in 'Stop At' Slider component
0, # int | float (numeric value between 0.0 and 2.0) in 'Weight' Slider component
"ImagePrompt", # str in 'Type' Radio component
self.emptyImage, # str (filepath or URL to image) in 'Image' Image component
0, # int | float (numeric value between 0.0 and 1.0) in 'Stop At' Slider component
0, # int | float (numeric value between 0.0 and 2.0) in 'Weight' Slider component
"ImagePrompt", # str in 'Type' Radio component
self.emptyImage, # str (filepath or URL to image) in 'Image' Image component
0, # int | float (numeric value between 0.0 and 1.0) in 'Stop At' Slider component
0, # int | float (numeric value between 0.0 and 2.0) in 'Weight' Slider component
"ImagePrompt", # str in 'Type' Radio component
False, # bool in 'Debug GroundingDINO' Checkbox component
-64, # int | float (numeric value between -64 and 64) in 'GroundingDINO Box Erode or Dilate' Slider component
False, # bool in 'Debug Enhance Masks' Checkbox component
self.emptyImage, # str (filepath or URL to image)
False, # bool in 'Enhance' Checkbox component
"Disabled", # str in 'Upscale or Variation:' Radio component
"Before First Enhancement", # str in 'Order of Processing' Radio component
"Original Prompts", # str in 'Prompt' Radio component
False, # bool in 'Enable' Checkbox component
"Howdy!", # str in 'Detection prompt' Textbox component
"Howdy!", # str in 'Enhancement positive prompt' Textbox component
"Howdy!", # str in 'Enhancement negative prompt' Textbox component
"u2net", # str (Option from: ['u2net', 'u2netp', 'u2net_human_seg', 'u2net_cloth_seg', 'silueta', 'isnet-general-use', 'isnet-anime', 'sam'])
"full", # str (Option from: ['full', 'upper', 'lower']) in 'Cloth category' Dropdown component
"vit_b", # str (Option from: ['vit_b', 'vit_l', 'vit_h']) in 'SAM model' Dropdown component
0, # int | float (numeric value between 0.0 and 1.0) in 'Text Threshold' Slider component
0, # int | float (numeric value between 0.0 and 1.0) in 'Box Threshold' Slider component
0, # int | float (numeric value between 0 and 10) in 'Maximum number of detections' Slider component
False, # bool in 'Disable initial latent in inpaint' Checkbox component
"None", # str (Option from: ['None', 'v1', 'v2.5', 'v2.6']) in 'Inpaint Engine' Dropdown component
0, # int | float (numeric value between 0.0 and 1.0) in 'Inpaint Denoising Strength' Slider component
0, # int | float (numeric value between 0.0 and 1.0) in 'Inpaint Respective Field' Slider component
-64, # int | float (numeric value between -64 and 64) in 'Mask Erode or Dilate' Slider component
False, # bool in 'Invert Mask' Checkbox component
False, # bool in 'Enable' Checkbox component
"Howdy!", # str in 'Detection prompt' Textbox component
"Howdy!", # str in 'Enhancement positive prompt' Textbox component
"Howdy!", # str in 'Enhancement negative prompt' Textbox component
"u2net", # str (Option from: ['u2net', 'u2netp', 'u2net_human_seg', 'u2net_cloth_seg', 'silueta', 'isnet-general-use', 'isnet-anime', 'sam']) in 'Mask generation model' Dropdown component
"full", # str (Option from: ['full', 'upper', 'lower']) in 'Cloth category' Dropdown component
"vit_b", # str (Option from: ['vit_b', 'vit_l', 'vit_h']) in 'SAM model' Dropdown component
0, # int | float (numeric value between 0.0 and 1.0) in 'Text Threshold' Slider component
0, # int | float (numeric value between 0.0 and 1.0) in 'Box Threshold' Slider component
0, # int | float (numeric value between 0 and 10) in 'Maximum number of detections' Slider component
False, # bool in 'Disable initial latent in inpaint' Checkbox component
"None", # str (Option from: ['None', 'v1', 'v2.5', 'v2.6']) in 'Inpaint Engine' Dropdown component
0, # int | float (numeric value between 0.0 and 1.0) in 'Inpaint Denoising Strength' Slider component
0, # int | float (numeric value between 0.0 and 1.0) in 'Inpaint Respective Field' Slider component
-64, # int | float (numeric value between -64 and 64) in 'Mask Erode or Dilate' Slider component
False, # bool in 'Invert Mask' Checkbox component
False, # bool in 'Enable' Checkbox component
"Howdy!", # str in 'Detection prompt' Textbox component
"Howdy!", # str in 'Enhancement positive prompt' Textbox component
"Howdy!", # str in 'Enhancement negative prompt' Textbox component
"u2net", # str (Option from: ['u2net', 'u2netp', 'u2net_human_seg', 'u2net_cloth_seg', 'silueta', 'isnet-general-use', 'isnet-anime', 'sam'])
"full", # str (Option from: ['full', 'upper', 'lower']) in 'Cloth category' Dropdown component
"vit_b", # str (Option from: ['vit_b', 'vit_l', 'vit_h']) in 'SAM model' Dropdown component
0, # int | float (numeric value between 0.0 and 1.0) in 'Text Threshold' Slider component
0, # int | float (numeric value between 0.0 and 1.0) in 'Box Threshold' Slider component
0, # int | float (numeric value between 0 and 10) in 'Maximum number of detections' Slider component
False, # bool in 'Disable initial latent in inpaint' Checkbox component
"None", # str (Option from: ['None', 'v1', 'v2.5', 'v2.6']) in 'Inpaint Engine' Dropdown component
0, # int | float (numeric value between 0.0 and 1.0) in 'Inpaint Denoising Strength' Slider component
0, # int | float (numeric value between 0.0 and 1.0) in 'Inpaint Respective Field' Slider component
-64, # int | float (numeric value between -64 and 64) in 'Mask Erode or Dilate' Slider component
False, # bool in 'Invert Mask' Checkbox component
fn_index=self.config.generate+self.config.deltaGenerate
)
result = self.getClient().predict(fn_index=self.config.generate+1)
end_time = timeit.default_timer()
# Generation failure
if len(result[3]['value'])==0:
console.printBB(" [b]#"+uid+"[/b] Generation image [error]failed[/error]")
return {
"ajax":True,
"error":True,
"image":False,
"uid": uid,
"metadata": metadata,
"start_time": start_time,
"end_time": end_time,
"elapsed_time": round((end_time - start_time)*1000),
"temp": "",
"name": "",
"file_size": "",
"result": result
}
# Generation success
if "name" in result[3]['value'][0]:
now = datetime.now()
console.printBB("[hour]"+now.strftime("%H:%M:%S")+"[/hour] [b]#"+uid+"[/b] [ok]Image is generated[/ok]")
picture=result[3]['value'][0]['name']
name=self.outputFolder+"/"+uid+result[3]['value'][0]['name'][-4:]
shutil.copyfile(picture, name)
if "action" in metadata:
if "compress" in metadata["action"]:
if "resize" in metadata["action"]:
if "copy" in metadata["action"]:
w, h=metadata["action"]["resize"]
# dirname = os.path.dirname(sys.argv[0])
# filename = utils.pathJoin(dirname, metadata["action"]["copy"])
# print("Remove file ? "+filename)
# if os.path.exists(filename):
# print("REMOVE FILE: "+filename)
# os.remove(filename)
utils.resizeAndCompressImage(picture, w, h, metadata["action"]["compress"], metadata["action"]["copy"])
image={ "ajax": True,
"error": False,
"image": True,
"uid": uid,
"metadata": metadata,
"start_time": start_time,
"end_time": end_time,
"elapsed_time": round((end_time - start_time)*1000),
"temp": result[3]['value'][0]['name'],
"name": "/"+name,
"file_size": os.path.getsize(picture),
"result": result
}
return image
except Exception as e:
if self.config.deltaGenerate<0:
console.printBB("[warning]sendCreateImage() failed. Trying to find the right gradio API fn_index (i+"+str(self.config.deltaGenerate)+")[/warning]")
self.config.deltaGenerate+=1
return self.sendCreateImage(metadata, uid)
else:
print("sendCreateImage exception")
print(f"Error: {e}")
print(" Check the Fooocus console terminal to view more indications")
traceback.print_exc() # Print the full traceback
return {"ajax":True, "error":True}