Spaces:
Sleeping
Sleeping
File size: 7,802 Bytes
b382c07 0f76635 b382c07 |
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 |
import axios from "axios";
import FormData from "form-data";
import { fileTypeFromBuffer } from "file-type";
async function toAnime(imgbuffer) {
// base url
const BASE_URL = "https://tuan2308-diffusecraft.hf.space/";
// session hash
const session_hash = Math.random().toString(36).substring(2).slice(1);
// identification buffer
const types = await fileTypeFromBuffer(imgbuffer);
const filenames = "images_" + Math.floor(1000 + Math.random() * 9000) + "." + types.ext;
// upload form image with gradio
const uploadImage = async() => {
// input data with formdata
const form = new FormData();
form.append("files", Buffer.from(imgbuffer, "binary"), {
filename: filenames,
contentType: types.mime
});
// send input from gradio API
const res = await axios({
method: "POST",
url: BASE_URL + "upload",
data: form,
headers: {
...form.getHeaders()
}
})
return res.data[0]
}
const response = await axios({
method: "POST",
url: BASE_URL + "queue/join?__theme=light",
data: {
data: [
"anime",
"strange color, blurred , ugly, tiling, bad hand drawing, poorly drawn feet, poorly drawn face, out of frame, extra limbs, deformity, deformity, body out of frame, blur, bad anatomy, blurred, watermark, grainy, signature, cropped, draft , low detail, low quality, two faces, 2 faces, garbled, ugly, low resolution, tiled, repetitive , grainy, garbled, plastic, distorted , ostentatious, ugly, oversaturated, grainy, low resolution, distorted, blurry, bad anatomy, distortion, poorly drawn face, mutant , mutant, appendage, ugly, poorly drawn hand, missing limb, blurred, floating limb, disjointed limb, hand deformity, blurred, out of focus, long neck, long body, ugly, hideous, drawing bad, garbled, distorted, imperfect, surreal, bad hand, text, error, extra digits, less digits, garbled , worst quality , low quality, normal quality, jpeg artifact, signature, watermark, username, blurry, artist name, multiple hands, extra limb, extra finger, conjoined finger, deformed finger, old, bad eye, imperfect eye, misaligned eye , unnatural face, stiff face, stiff body, disproportionate, unnatural body, lack of body, unclear details, sticky details, low details, details distorted, ugly hands, imperfect hands, (deformed hands and fingers: 1.5), (long body :1.3), (mutated, poorly drawn :1.2) bad hands, fused hands , lost hand, arm disappeared, thighs disappeared, calves disappeared, legs disappeared, ui, lost fingers, (((((realistic, semi-realistic, render, outline)))), already crop, worst quality, low quality, jpeg shaping, ugly, duplicate, garbled, out of frame, extra fingers, mutated hand, poorly drawn hand, bad drawn face, mutated variable, deformed, blurred, dehydrated, bad anatomy, bad proportions, superfluous limbs, cloned face, deformity, gross proportions, deformed limbs, lost hands, lost legs, extra arms, extra legs , sticky fingers, too many fingers , long neck, text, close-up, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, sick, cropped amputee, extra fingers, mutated hand, bad hand drawing, bad drawn face, mutant, deformed, blurred, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, deformity, gross proportions, deformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck, blurred, deformed face, variable hands shape, deformed fingers, ugly, bad anatomy, extra fingers, extra hands, deformed eyes, logo, text (:1.2) (:1.2) , (:1.2) sketch, (poor quality) best:1.4), (low quality:1.4), (normal quality:1.4), low quality, bad anatomy, bad hand, vaginal vagina, ((monochrome)), ((scale) gray)), drooping eyelids, many eyebrows, (cropped), oversaturated, extra limb, amputee, deformed arms, long neck, long body, imperfection, (bad hands), signature, figure blurred, username, artist name, conjoined fingers, deformed fingers, bad eyes, imperfect eyes, misaligned eyes, unnatural face, unnatural body, error, bad photo, bad photo",
1,
28,
7.5,
true,
-1,
"loras/3DMM_V12.safetensors",
0.5,
null,
0.33,
null,
0.33,
null,
0.33,
null,
0.33,
"Euler a",
1024,
1024,
"cagliostrolab/animagine-xl-3.1",
null,
"img2img",
{
path: await (await uploadImage()),
meta: {
_type: "gradio.FileData"
},
mimetype: types.mime,
orig_name: filenames,
size: imgbuffer?.length,
url: BASE_URL + await (await uploadImage())
},
"Canny",
512,
1024,
[],
null,
null,
0.59,
100,
200,
0.1,
0.1,
1,
0,
1,
false,
"Compel",
null,
1.4,
100,
10,
30,
0.55,
"Use same sampler",
"",
"",
false,
true,
1,
true,
false,
true,
true,
false,
"./images",
false,
false,
false,
true,
1,
0.55,
false,
true,
false,
true,
false,
"Use same sampler",
false,
"",
"",
0.35,
true,
true,
false,
4,
4,
32,
false,
"",
"",
0.35,
true,
true,
false,
4,
4,
32,
false,
null,
null,
"plus_face",
"original",
0.7,
null,
null,
"base",
"style",
0.7
],
event_data: null,
fn_index: 11,
session_hash,
trigger_id: 14
}
});
if(response.data.event_id) {
const res = await axios({
method: "GET",
url: BASE_URL + "queue/data?session_hash=" + session_hash
});
const splited = res.data.split("\n");
const processStartsLine = splited.find(line => line.includes('process_completed'));
const processStartsData = JSON.parse(processStartsLine.replace('data: ', ''));
const processStartsLine2 = splited.find(line => line.includes('process_generating'));
const processStartsData2 = JSON.parse(processStartsLine2.replace('data: ', ''));
if(processStartsData?.success) {
return processStartsData.output.data;
} else if(processStartsData2?.success) {
return processStartsData2.output.data;
}
}
}
export { toAnime } |