From bfc909e99d97a9e6f1d49eb6a48b44fe0d85c99f Mon Sep 17 00:00:00 2001 From: Nayam Amarshe <25067102+NayamAmarshe@users.noreply.github.com> Date: Wed, 12 Apr 2023 18:55:24 +0530 Subject: [PATCH] Added scale --- main/index.js | 20 ++++++++++++++---- .../realesr-animevideov3-x2.bin | Bin .../realesr-animevideov3-x2.param | 0 .../realesr-animevideov3-x3.bin | Bin .../realesr-animevideov3-x3.param | 0 .../realesr-animevideov3-x4.bin | Bin .../realesr-animevideov3-x4.param | 0 renderer/components/Footer.tsx | 11 ++++------ renderer/components/LeftPaneImageSteps.tsx | 15 +++++++++++++ renderer/pages/index.tsx | 20 +++++++++++++----- 10 files changed, 50 insertions(+), 16 deletions(-) rename {future-use => models}/realesr-animevideov3-x2.bin (100%) rename {future-use => models}/realesr-animevideov3-x2.param (100%) rename {future-use => models}/realesr-animevideov3-x3.bin (100%) rename {future-use => models}/realesr-animevideov3-x3.param (100%) rename {future-use => models}/realesr-animevideov3-x4.bin (100%) rename {future-use => models}/realesr-animevideov3-x4.param (100%) diff --git a/main/index.js b/main/index.js index 431ccff..d61131b 100644 --- a/main/index.js +++ b/main/index.js @@ -79,6 +79,14 @@ electron_log_1.default.log(electron_1.app.getAppPath()); let imagePath = undefined; let folderPath = undefined; let customModelsFolderPath = undefined; +// Default models +const defaultModels = [ + "realesrgan-x4plus", + "remacri", + "ultramix_balanced", + "ultrasharp", + "realesrgan-x4plus-anime", +]; //------------------------Select File-----------------------------// // ! DONT FORGET TO RESTART THE APP WHEN YOU CHANGE CODE HERE electron_1.ipcMain.handle(commands_1.default.SELECT_FILE, () => __awaiter(void 0, void 0, void 0, function* () { @@ -169,6 +177,7 @@ const getModels = (folderPath) => { }; electron_1.ipcMain.on(commands_1.default.GET_MODELS_LIST, (event, payload) => __awaiter(void 0, void 0, void 0, function* () { if (payload) { + customModelsFolderPath = payload; mainWindow.webContents.send(commands_1.default.CUSTOM_MODEL_FILES_LIST, getModels(payload)); } })); @@ -201,6 +210,7 @@ electron_1.ipcMain.on(commands_1.default.DOUBLE_UPSCAYL, (event, payload) => __a let outputDir = payload.outputPath; const gpuId = payload.gpuId; const saveImageAs = payload.saveImageAs; + const isDefaultModel = defaultModels.includes(model); // COPY IMAGE TO TMP FOLDER const platform = (0, getPlatform_1.default)(); const fullfileName = platform === "win" @@ -210,7 +220,7 @@ electron_1.ipcMain.on(commands_1.default.DOUBLE_UPSCAYL, (event, payload) => __a const fileExt = (0, path_1.parse)(fullfileName).ext; const outFile = outputDir + "/" + fileName + "_upscayl_16x_" + model + "." + saveImageAs; // UPSCALE - let upscayl = (0, upscayl_1.spawnUpscayl)("realesrgan", (0, getArguments_1.getDoubleUpscaleArguments)(inputDir, fullfileName, outFile, binaries_1.modelsPath, model, gpuId, saveImageAs)); + let upscayl = (0, upscayl_1.spawnUpscayl)("realesrgan", (0, getArguments_1.getDoubleUpscaleArguments)(inputDir, fullfileName, outFile, isDefaultModel ? binaries_1.modelsPath : customModelsFolderPath !== null && customModelsFolderPath !== void 0 ? customModelsFolderPath : binaries_1.modelsPath, model, gpuId, saveImageAs)); let failed = false; let isAlpha = false; let failed2 = false; @@ -269,7 +279,7 @@ electron_1.ipcMain.on(commands_1.default.DOUBLE_UPSCAYL, (event, payload) => __a // IF NOT FAILED if (!failed) { // UPSCALE - let upscayl2 = (0, upscayl_1.spawnUpscayl)("realesrgan", (0, getArguments_1.getDoubleUpscaleSecondPassArguments)(isAlpha, outFile, binaries_1.modelsPath, model, gpuId, saveImageAs)); + let upscayl2 = (0, upscayl_1.spawnUpscayl)("realesrgan", (0, getArguments_1.getDoubleUpscaleSecondPassArguments)(isAlpha, outFile, isDefaultModel ? binaries_1.modelsPath : customModelsFolderPath !== null && customModelsFolderPath !== void 0 ? customModelsFolderPath : binaries_1.modelsPath, model, gpuId, saveImageAs)); upscayl2.process.stderr.on("data", onData2); upscayl2.process.on("error", onError2); upscayl2.process.on("close", onClose2); @@ -284,6 +294,7 @@ electron_1.ipcMain.on(commands_1.default.UPSCAYL, (event, payload) => __awaiter( const saveImageAs = payload.saveImageAs; let inputDir = (payload.imagePath.match(/(.*)[\/\\]/)[1] || ""); let outputDir = payload.outputPath; + const isDefaultModel = defaultModels.includes(model); // COPY IMAGE TO TMP FOLDER const fullfileName = payload.imagePath.replace(/^.*[\\\/]/, ""); const fileName = (0, path_1.parse)(fullfileName).name; @@ -305,7 +316,7 @@ electron_1.ipcMain.on(commands_1.default.UPSCAYL, (event, payload) => __awaiter( mainWindow.webContents.send(commands_1.default.UPSCAYL_DONE, outFile); } else { - const upscayl = (0, upscayl_1.spawnUpscayl)("realesrgan", (0, getArguments_1.getSingleImageArguments)(inputDir, fullfileName, outFile, binaries_1.modelsPath, model, scale, gpuId, saveImageAs)); + const upscayl = (0, upscayl_1.spawnUpscayl)("realesrgan", (0, getArguments_1.getSingleImageArguments)(inputDir, fullfileName, outFile, isDefaultModel ? binaries_1.modelsPath : customModelsFolderPath !== null && customModelsFolderPath !== void 0 ? customModelsFolderPath : binaries_1.modelsPath, model, scale, gpuId, saveImageAs)); let isAlpha = false; let failed = false; const onData = (data) => { @@ -349,8 +360,9 @@ electron_1.ipcMain.on(commands_1.default.FOLDER_UPSCAYL, (event, payload) => __a if (!fs_1.default.existsSync(outputDir)) { fs_1.default.mkdirSync(outputDir, { recursive: true }); } + const isDefaultModel = defaultModels.includes(model); // UPSCALE - const upscayl = (0, upscayl_1.spawnUpscayl)("realesrgan", (0, getArguments_1.getBatchArguments)(inputDir, outputDir, binaries_1.modelsPath, model, gpuId, saveImageAs)); + const upscayl = (0, upscayl_1.spawnUpscayl)("realesrgan", (0, getArguments_1.getBatchArguments)(inputDir, outputDir, isDefaultModel ? binaries_1.modelsPath : customModelsFolderPath !== null && customModelsFolderPath !== void 0 ? customModelsFolderPath : binaries_1.modelsPath, model, gpuId, saveImageAs)); let failed = false; const onData = (data) => { electron_log_1.default.log("🚀 => upscayl.stderr.on => stderr.toString()", data.toString()); diff --git a/future-use/realesr-animevideov3-x2.bin b/models/realesr-animevideov3-x2.bin similarity index 100% rename from future-use/realesr-animevideov3-x2.bin rename to models/realesr-animevideov3-x2.bin diff --git a/future-use/realesr-animevideov3-x2.param b/models/realesr-animevideov3-x2.param similarity index 100% rename from future-use/realesr-animevideov3-x2.param rename to models/realesr-animevideov3-x2.param diff --git a/future-use/realesr-animevideov3-x3.bin b/models/realesr-animevideov3-x3.bin similarity index 100% rename from future-use/realesr-animevideov3-x3.bin rename to models/realesr-animevideov3-x3.bin diff --git a/future-use/realesr-animevideov3-x3.param b/models/realesr-animevideov3-x3.param similarity index 100% rename from future-use/realesr-animevideov3-x3.param rename to models/realesr-animevideov3-x3.param diff --git a/future-use/realesr-animevideov3-x4.bin b/models/realesr-animevideov3-x4.bin similarity index 100% rename from future-use/realesr-animevideov3-x4.bin rename to models/realesr-animevideov3-x4.bin diff --git a/future-use/realesr-animevideov3-x4.param b/models/realesr-animevideov3-x4.param similarity index 100% rename from future-use/realesr-animevideov3-x4.param rename to models/realesr-animevideov3-x4.param diff --git a/renderer/components/Footer.tsx b/renderer/components/Footer.tsx index 1027327..060d370 100644 --- a/renderer/components/Footer.tsx +++ b/renderer/components/Footer.tsx @@ -2,14 +2,13 @@ import React from "react"; function Footer() { return ( -
+

Copyright © 2022 -{" "} + target="_blank"> Upscayl

@@ -18,16 +17,14 @@ function Footer() { + target="_blank"> TGS963 {" "} and{" "} + target="_blank"> Nayam Amarshe

diff --git a/renderer/components/LeftPaneImageSteps.tsx b/renderer/components/LeftPaneImageSteps.tsx index 415bf88..c5b9783 100644 --- a/renderer/components/LeftPaneImageSteps.tsx +++ b/renderer/components/LeftPaneImageSteps.tsx @@ -241,6 +241,21 @@ function LeftPaneImageSteps({
)} + +

Set Scale

+ +
+ | + | + | +
{/* STEP 3 */} diff --git a/renderer/pages/index.tsx b/renderer/pages/index.tsx index 5c219b7..96158e1 100644 --- a/renderer/pages/index.tsx +++ b/renderer/pages/index.tsx @@ -159,12 +159,22 @@ const Home = () => { // CUSTOM FOLDER LISTENER window.electron.on( commands.CUSTOM_MODEL_FILES_LIST, - (_, modelsList: string[]) => { - console.log("🚀 => file: index.tsx:161 => modelsList:", modelsList); - - modelsList.forEach((model: string) => { - setModelOptions((prev) => [...prev, { label: model, value: model }]); + (_, data: string[]) => { + const newModelOptions = data.map((model) => { + return { + value: model, + label: model, + }; }); + + // Add newModelsList to modelOptions and remove duplicates + const combinedModelOptions = [...modelOptions, ...newModelOptions]; + const uniqueModelOptions = combinedModelOptions.filter( + // Check if any model in the array appears more than once + (model, index, array) => + array.findIndex((t) => t.value === model.value) === index + ); + setModelOptions(uniqueModelOptions); } ); }, []);