This commit is contained in:
mrq 2022-10-04 21:25:47 +00:00
parent 8eeb0a87c4
commit fa82334f4e
3 changed files with 73 additions and 56 deletions

View File

@ -1,5 +1,11 @@
# Textual Inversion Guide w/ E621 Content # Textual Inversion Guide w/ E621 Content
An up-to-date repo with all the necessary files can be found here: https://git.coom.tech/mrq/stable-diffusion-utils
**!**WARNING**!** **!**CAUTION**!** ***DO NOT POST THE REPO'S URL ON 4CHAN*** **!**CAUTION**!** **!**WARNING**!**
`coom.tech` is an automatic 30-day ban if posted. I am not responsible if you share that URL. Share the [rentry](https://rentry.org/sd-e621-textual-inversion/) instead.
## Assumptions ## Assumptions
This guide assumes the following basics: This guide assumes the following basics:

View File

@ -0,0 +1,5 @@
{
"dependencies": {
"node-fetch": "^2.6.7"
}
}

View File

@ -18,66 +18,72 @@ for ( let i in csv ) {
// for starters, you can also add "anthro", "male", "female", as they're very common tags // for starters, you can also add "anthro", "male", "female", as they're very common tags
let filters = [ let filters = [
"female" "female"
] ];
for ( let i in files ) (async () => { let parse = async () => {
let file = files[i]; for ( let i in files ) {
let md5 = file.match(/^([a-f0-9]{32})/)[1]; let file = files[i];
let ext = file.split(".").pop() let md5 = file.match(/^([a-f0-9]{32})/);
console.log(i, files.length, md5, ext); if ( !md5 ) continue;
md5 = md5[1];
let ext = file.split(".").pop()
console.log(i, files.length, md5, ext);
let r = await Fetch( `https://e621.net/posts.json?tags=md5:${md5}`, { let r = await Fetch( `https://e621.net/posts.json?tags=md5:${md5}`, {
headers: { headers: {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36' 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'
}
} );
let json = JSON.parse(await r.text());
json = json.posts[0];
if ( !json ) continue;
tags = [];
let artist = "";
let content = "";
switch ( json.rating ) {
case "s": content = "safe content"; break;
case "q": content = "questionable content"; break;
case "e": content = "explict content"; break;
} }
} );
let json = JSON.parse(await res.text());
json = json.posts[0];
if ( !json ) continue;
tags = [];
let artist = ""; for ( let cat in json.tags ) {
let content = ""; if ( cat === "artist" ) {
switch ( json.rating ) { let tag = "by " + json.tags["artist"].join(" and ")
case "s": content = "safe content"; break; if ( !kson.tags[tag] ) continue;
case "q": content = "questionable content"; break; artist = tag;
case "e": content = "explict content"; break; } else for ( let k in json.tags[cat] ) {
} let tag = json.tags[cat][k];
if ( !kson.tags[tag] ) continue;
for ( let cat in json.tags ) { if ( tag.indexOf("/") >= 0 ) continue;
if ( cat === "artist" ) { if ( filters.includes(tag) ) continue;
let tag = "by " + json.tags["artist"].join(" and ") tags.push(tag);
if ( !kson.tags[tag] ) continue; }
artist = tag;
} else for ( let k in json.tags[cat] ) {
let tag = json.tags[cat][k];
if ( !kson.tags[tag] ) continue;
if ( tag.indexOf("/") >= 0 ) continue;
if ( filters.includes(tag) ) continue;
tags.push(tag);
} }
tags = tags.sort( (a, b) => {
return kson.tags[b] - kson.tags[a]
})
if ( artist ) tags.unshift(artist);
if ( content ) tags.unshift(content);
kson.files[md5] = tags;
let jointmp = "";
let filtered = [];
for ( let i in tags ) {
if ( (jointmp + " " + tags[i]).length > 192 ) break; // arbitrary limit for filenames and tokens, adjust if you're getting bitched at from the web UI
jointmp += " " + tags[i];
filtered.push(tags[i])
}
let joined = filtered.join(" ")
require("fs").copyFileSync(`./in/${file}`, `./out/${joined}.${ext}`)
// rate limit
await new Promise( (resolve) => {
setTimeout(resolve, 500)
} )
} }
tags = tags.sort( (a, b) => { }
return kson.tags[b] - kson.tags[a]
})
if ( artist ) tags.unshift(artist);
if ( content ) tags.unshift(content);
kson.files[md5] = tags; parse();
let jointmp = "";
let filtered = [];
for ( let i in tags ) {
if ( (jointmp + " " + tags[i]).length > 192 ) break; // arbitrary limit for filenames and tokens, adjust if you're getting bitched at from the web UI
jointmp += " " + tags[i];
filtered.push(tags[i])
}
let joined = filtered.join(" ")
require("fs").copyFileSync(`./in/${file}`, `./out/${joined}.${ext}`)
// rate limit
await new Promise( (resolve) => {
setTimeout(resolve, 500)
} )
})();