Spaces:
Running
Running
import axios from "axios"; | |
import FormData from "form-data"; | |
async function processImageUpscaler({ buffer, method, filenames, mimetype }) { | |
return new Promise(async (resolve, reject) => { | |
let Methods = ["enhance"]; | |
Methods.includes(method) ? (method = method) : (method = Methods[0]); | |
let formData = new FormData(); | |
formData.append("model_version", 1); | |
formData.append("image", Buffer.from(buffer), { | |
filename: filenames, | |
contentType: mimetype, | |
}); | |
const headers = { | |
"User-Agent": "okhttp/4.9.3", | |
Connection: "Keep-Alive", | |
"Accept-Encoding": "gzip", | |
"Content-Type": "multipart/form-data", | |
}; | |
const instance = axios.create({ | |
transformRequest: [], | |
}); | |
instance.post(`https://inferenceengine.vyro.ai/${method}`, formData, { headers }) | |
.then(response => { | |
resolve(Buffer.from(response.data), "binary"); | |
}) | |
.catch(error => { | |
reject(error); | |
}); | |
}); | |
}; | |
export { processImageUpscaler }; |