1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-11-23 23:21:05 +01:00

Added custom model check

This commit is contained in:
Nayam Amarshe 2023-04-09 11:34:36 +05:30
parent 33f85d96d4
commit abd7063cb3
2 changed files with 25 additions and 6 deletions

View File

@ -94,6 +94,15 @@ let imagePath: string | undefined = undefined;
let folderPath: string | undefined = undefined;
let customModelsFolderPath: string | undefined = 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
ipcMain.handle(commands.SELECT_FILE, async () => {
@ -198,6 +207,7 @@ const getModels = (folderPath: string) => {
ipcMain.on(commands.GET_MODELS_LIST, async (event, payload) => {
if (payload) {
customModelsFolderPath = payload;
mainWindow.webContents.send(
commands.CUSTOM_MODEL_FILES_LIST,
getModels(payload)
@ -241,6 +251,8 @@ ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
const gpuId = payload.gpuId as string;
const saveImageAs = payload.saveImageAs as string;
const isDefaultModel = defaultModels.includes(model);
// COPY IMAGE TO TMP FOLDER
const platform = getPlatform();
const fullfileName =
@ -259,7 +271,7 @@ ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
inputDir,
fullfileName,
outFile,
modelsPath,
isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath,
model,
gpuId,
saveImageAs
@ -334,7 +346,7 @@ ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
getDoubleUpscaleSecondPassArguments(
isAlpha,
outFile,
modelsPath,
isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath,
model,
gpuId,
saveImageAs
@ -357,6 +369,8 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
let inputDir = (payload.imagePath.match(/(.*)[\/\\]/)[1] || "") as string;
let outputDir = payload.outputPath as string;
const isDefaultModel = defaultModels.includes(model);
// COPY IMAGE TO TMP FOLDER
const fullfileName = payload.imagePath.replace(/^.*[\\\/]/, "") as string;
@ -388,7 +402,7 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
inputDir,
fullfileName,
outFile,
modelsPath,
isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath,
model,
scale,
gpuId,
@ -448,13 +462,16 @@ ipcMain.on(commands.FOLDER_UPSCAYL, async (event, payload) => {
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
const isDefaultModel = defaultModels.includes(model);
// UPSCALE
const upscayl = spawnUpscayl(
"realesrgan",
getBatchArguments(
inputDir,
outputDir,
modelsPath,
isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath,
model,
gpuId,
saveImageAs

View File

@ -5,10 +5,12 @@ export type TModelsList = {
value: string;
}[];
export const modelsListAtom = atom<TModelsList>([
export const defaultModelsList = [
{ label: "General Photo (Real-ESRGAN)", value: "realesrgan-x4plus" },
{ label: "General Photo (Remacri)", value: "remacri" },
{ label: "General Photo (Ultramix Balanced)", value: "ultramix_balanced" },
{ label: "General Photo (Ultrasharp)", value: "ultrasharp" },
{ label: "Digital Art", value: "realesrgan-x4plus-anime" },
]);
];
export const modelsListAtom = atom<TModelsList>(defaultModelsList);