Spaces:
Sleeping
Sleeping
Update lib/enchance.js
Browse files- lib/enchance.js +47 -1
lib/enchance.js
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
import WebSocket from "ws"
|
|
|
|
|
2 |
|
3 |
async function upscaler(images) {
|
4 |
return new Promise((resolve, reject) => {
|
@@ -48,5 +50,49 @@ async function upscaler(images) {
|
|
48 |
})
|
49 |
|
50 |
}
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import WebSocket from "ws"
|
2 |
+
import Jimp from "jimp"
|
3 |
+
import FormData from "form-data"
|
4 |
|
5 |
async function upscaler(images) {
|
6 |
return new Promise((resolve, reject) => {
|
|
|
50 |
})
|
51 |
|
52 |
}
|
53 |
+
async function processImageUpscaler({ buffer, method, filenames, mimetype }) {
|
54 |
+
return new Promise(async (resolve, reject) => {
|
55 |
+
let Methods = ["enhance"];
|
56 |
+
Methods.includes(method) ? (method = method) : (method = Methods[0]);
|
57 |
|
58 |
+
let buffer,
|
59 |
+
Form = new FormData(),
|
60 |
+
scheme = "https" + "://" + "inferenceengine" + ".vyro" + ".ai/" + method;
|
61 |
+
|
62 |
+
Form.append("model_version", 1);
|
63 |
+
|
64 |
+
Form.append("image", buffer, {
|
65 |
+
filename: filenames,
|
66 |
+
contentType: mimetype,
|
67 |
+
});
|
68 |
+
|
69 |
+
Form.submit({
|
70 |
+
url: scheme,
|
71 |
+
host: "inferenceengine" + ".vyro" + ".ai",
|
72 |
+
path: "/" + method,
|
73 |
+
protocol: "https:",
|
74 |
+
headers: {
|
75 |
+
"User-Agent": "okhttp/4.9.3",
|
76 |
+
Connection: "Keep-Alive",
|
77 |
+
"Accept-Encoding": "gzip",
|
78 |
+
},
|
79 |
+
},
|
80 |
+
function(err, res) {
|
81 |
+
if (err) reject(err);
|
82 |
+
let data = [];
|
83 |
+
res
|
84 |
+
.on("data", function(chunk) {
|
85 |
+
data.push(chunk);
|
86 |
+
})
|
87 |
+
.on("end", () => {
|
88 |
+
resolve(Buffer.concat(data));
|
89 |
+
});
|
90 |
+
res.on("error", (e) => {
|
91 |
+
reject(e);
|
92 |
+
});
|
93 |
+
}
|
94 |
+
);
|
95 |
+
});
|
96 |
+
};
|
97 |
+
|
98 |
+
export { upscaler, processImageUpscaler }
|