forked from Haidra-Org/AI-Horde
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kudos_standalone.js
84 lines (73 loc) · 2.15 KB
/
kudos_standalone.js
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
const doesDenoiseStrengthAffectSteps = false; // This is a server-side bug. Switch to true when fixed.
export default function calculateKudos(
width,
height,
steps,
samplerName,
hasSourceImage,
isImg2Img,
denoisingStrength,
postProcessors,
usesControlNet,
prompt,
shareWithLaionEnabled
) {
const result = Math.pow((width * height) - (64 * 64), 1.75) / Math.pow((1024 * 1024) - (64 * 64), 1.75);
steps = getAccurateSteps(steps, samplerName, hasSourceImage, isImg2Img, denoisingStrength);
let kudos = Math.round(((0.1232 * steps) + result * (0.1232 * steps * 8.75)) * 100) / 100;
for (let i = 0; i < postProcessors.length; i++) {
kudos = Math.round(kudos * 1.2 * 100) / 100;
}
if (usesControlNet) {
kudos = Math.round(kudos * 3 * 100) / 100;
}
const weightsCount = countParentheses(prompt);
kudos += weightsCount;
if (hasSourceImage) {
kudos = kudos * 1.5;
}
if (postProcessors.includes('RealESRGAN_x4plus')) {
kudos = kudos * 1.3;
}
if (postProcessors.includes('RealESRGAN_x4plus_anime_6B')) {
kudos = kudos * 1.3;
}
if (postProcessors.includes('CodeFormers')) {
kudos = kudos * 1.3;
}
let hordeTax = 3;
if (shareWithLaionEnabled) {
hordeTax = 1;
}
if (kudos < 10) {
hordeTax -= 1;
}
kudos += hordeTax;
return Math.round(kudos*100)/100;
}
function getAccurateSteps(steps, samplerName, hasSourceImage, isImg2Img, denoisingStrength) {
if (['k_dpm_adaptive'].includes(samplerName)) {
return 50;
}
if (['k_heun', 'k_dpm_2', 'k_dpm_2_a', 'k_dpmpp_2s_a'].includes(samplerName)) {
steps *= 2;
}
if (hasSourceImage && isImg2Img && doesDenoiseStrengthAffectSteps) {
steps *= denoisingStrength;
}
return steps;
}
function countParentheses(prompt) {
let openP = false;
let count = 0;
for (let i = 0; i < prompt.length; i++) {
const c = prompt[i];
if (c === "(") {
openP = true;
} else if (c === ")" && openP) {
openP = false;
count++;
}
}
return count;
}