Skip to content

Commit

Permalink
use new core
Browse files Browse the repository at this point in the history
  • Loading branch information
Tohrusky committed Nov 8, 2024
1 parent caacca2 commit adef5e9
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 449 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ jobs:
linux-pip:
strategy:
matrix:
os-version: ['x64', 'arm64']
os-version: ['x64']

runs-on: ubuntu-20.04
steps:
Expand Down
8 changes: 2 additions & 6 deletions src/main/RunCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,9 @@ export async function KillCommand(): Promise<void> {
}

function CheckPipPackage(): boolean {
const command = `Final2x-core -o`
const command = `Final2x-core -h`

const result = spawnSync(command, { shell: true, encoding: 'utf-8' })

if (result.status === 0) {
return result.stdout.trim().toString() === '114514' // Magic Number String
} else {
return false
}
return result.status === 0
}
13 changes: 0 additions & 13 deletions src/main/getSystemInfo.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { app, BrowserWindow, ipcMain, Menu, nativeImage, shell, Tray } from 'electron'
import { join } from 'path'
import { electronApp, is, optimizer } from '@electron-toolkit/utils'
import { getSystemInfo } from './getSystemInfo'
import { KillCommand, RunCommand } from './RunCommand'
import { openDirectory } from './openDirectory'

Expand Down Expand Up @@ -31,8 +30,6 @@ function createWindow(): void {
app.dock.setIcon(nativeImage.createFromPath(icon))
}

ipcMain.handleOnce('getSystemInfo', getSystemInfo)

ipcMain.on('execute-command', RunCommand)

ipcMain.on('kill-command', KillCommand)
Expand Down
5 changes: 0 additions & 5 deletions src/renderer/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { onMounted, watch } from 'vue'
import { storeToRefs } from 'pinia'
import { useI18n } from 'vue-i18n'
import { getLanguage } from './utils'
import { updateDeviceList } from './utils/updateDeviceList'
import { useGlobalSettingsStore } from './store/globalSettingsStore'
import TrafficLightsButtons from './components/TrafficLightsButtons.vue'
import MyProgress from './components/MyProgress.vue'
Expand All @@ -26,10 +25,6 @@ onMounted(async () => {
// 当语言不是跟随环境时,设置语言
locale.value = getLanguage(langsNum.value).lang
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const res: Array<string> = await window.electron.ipcRenderer.invoke('getSystemInfo')
updateDeviceList(res)
})
const themeOverrides = {
Expand Down
22 changes: 1 addition & 21 deletions src/renderer/src/components/MyExternalLink.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
<script lang="ts" setup>
import { storeToRefs } from 'pinia'
import { BookOutline, FilmOutline } from '@vicons/ionicons5'
import { useGlobalSettingsStore } from '../store/globalSettingsStore'
const { langsNum } = storeToRefs(useGlobalSettingsStore())
import { FilmOutline } from '@vicons/ionicons5'
class openWebsite {
static async Docs(): Promise<void> {
const docsLink = 'https://final2x.tohru.top'
const docsLinkCN = 'https://final2x.tohru.top/zh'
if (langsNum.value === 1) {
window.open(docsLinkCN, '_blank')
} else {
window.open(docsLink, '_blank')
}
}
static async FinalRip(): Promise<void> {
const Link = 'https://github.com/TensoRaws/FinalRip'
Expand All @@ -27,12 +13,6 @@ class openWebsite {
<template>
<div class="MyExternalLink">
<n-space>
<n-button style="font-size: 36px" text @click="openWebsite.Docs">
<n-icon>
<book-outline />
</n-icon>
</n-button>

<n-button style="font-size: 36px" text @click="openWebsite.FinalRip">
<n-icon>
<film-outline />
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/components/MyProgress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function StartSR(): void {
const command = getFinal2xconfig()
CommandLOG.value += '\n' + JSON.stringify(deviceList.value) + '\n' + command + '\n'
CommandLOG.value += '\n' + command + '\n'
CommandLOG.value += 'OPEN OUTPUT FOLDER: ' + openOutputFolder.value + '\n'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down
16 changes: 6 additions & 10 deletions src/renderer/src/store/SRSettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,20 @@ import { defineStore } from 'pinia'
export const useSRSettingsStore = defineStore(
'SRSettings',
() => {
const selectedModel = ref('RealESRGAN')
const selectedScale = ref(2)
const selectedNoise = ref(-1)
const useTTA = ref(false)
const CustomScaleValue: Ref<number | null> = ref(null)
const selectedModel = ref('RealESRGAN_RealESRGAN_x2plus_2x.pth')
const ghProxy: Ref<string | null> = ref(null)
const targetScale: Ref<number | null> = ref(null)

return {
selectedModel,
selectedScale,
selectedNoise,
useTTA,
CustomScaleValue
ghProxy,
targetScale
}
},
{
persist: {
storage: localStorage,
paths: ['selectedModel', 'selectedScale', 'selectedNoise', 'useTTA', 'CustomScaleValue']
paths: ['selectedModel', 'ghProxy', 'targetScale']
}
}
)
14 changes: 9 additions & 5 deletions src/renderer/src/store/globalSettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ export const useGlobalSettingsStore = defineStore(

const langsNum = ref(114514)

const SRgpuid = ref(114514)
const deviceList: Ref<any[]> = ref([])
const SRdevice = ref('auto')
const deviceList: Ref<any[]> = ref([
{ value: 'auto', label: 'Auto' },
{ value: 'cuda', label: 'CUDA' },
{ value: 'mps', label: 'MPS' },
{ value: 'cpu', label: 'CPU' },
])

const ProgressPercentage = ref(0)
const CommandLOG = ref('')
Expand All @@ -31,7 +36,7 @@ export const useGlobalSettingsStore = defineStore(
naiveTheme,
changeRoute,
langsNum,
SRgpuid,
SRdevice,
deviceList,
ProgressPercentage,
CommandLOG,
Expand All @@ -46,11 +51,10 @@ export const useGlobalSettingsStore = defineStore(
storage: localStorage,
paths: [
'langsNum',
'SRgpuid',
'SRdevice',
'darkMode',
'naiveTheme',
'globalcolor',
'deviceList',
'openOutputFolder'
]
}
Expand Down
134 changes: 6 additions & 128 deletions src/renderer/src/utils/ModelOptions.ts
Original file line number Diff line number Diff line change
@@ -1,131 +1,9 @@
import { SelectOption } from 'naive-ui'
import {ref, Ref} from "vue";

/**
* @description: 模型选项
* @description: all SR models provided by ccrestoration
*/
export const modelOptions: SelectOption[] = [
{ label: 'RealCUGAN-se', value: 'RealCUGAN-se' },
{ label: 'RealCUGAN-pro', value: 'RealCUGAN-pro' },
{ label: 'APISR-RRDB', value: 'APISR-RRDB' },
{ label: 'RealESRGAN-animevideov3', value: 'RealESRGAN-animevideov3' },
{ label: 'RealESRGAN', value: 'RealESRGAN' },
{ label: 'RealESRGAN-anime', value: 'RealESRGAN-anime' },
{ label: 'Waifu2x-cunet', value: 'Waifu2x-cunet' },
{ label: 'Waifu2x-upconv_7_anime_style_art_rgb', value: 'Waifu2x-upconv_7_anime_style_art_rgb' },
{ label: 'Waifu2x-upconv_7_photo', value: 'Waifu2x-upconv_7_photo' }
]

/**
* @description: 模型 -> 模型Scale
*/
export interface ModelScaleOptionsType {
[key: string]: SelectOption[]
}

/**
* @description: 模型Scale选项
*/
export const modelScaleOptions: ModelScaleOptionsType = {
'RealCUGAN-se': [
{ label: '2', value: 2 },
{ label: '3', value: 3 },
{ label: '4', value: 4 }
],
'RealCUGAN-pro': [
{ label: '2', value: 2 },
{ label: '3', value: 3 }
],
'APISR-RRDB': [{ label: '4', value: 4 }],
'RealESRGAN-animevideov3': [
{ label: '2', value: 2 },
{ label: '3', value: 3 },
{ label: '4', value: 4 }
],
RealESRGAN: [{ label: '4', value: 4 }],
'RealESRGAN-anime': [{ label: '4', value: 4 }],
'Waifu2x-cunet': [
{ label: '1', value: 1 },
{ label: '2', value: 2 }
],
'Waifu2x-upconv_7_anime_style_art_rgb': [{ label: '2', value: 2 }],
'Waifu2x-upconv_7_photo': [{ label: '2', value: 2 }]
}

/**
* @description: 由模型和Scale获取Noise选项
* @param Model 模型
* @param Scale 模型Scale
*/
export function GetModelNoiseOptionsByNameAndScale(Model: string, Scale: number): SelectOption[] {
if (Model === 'RealCUGAN-se') {
if (Scale === 2) {
return [
{ label: '-1', value: -1 },
{ label: '0', value: 0 },
{ label: '1', value: 1 },
{ label: '2', value: 2 },
{ label: '3', value: 3 }
]
} else if (Scale === 3 || Scale === 4) {
return [
{ label: '-1', value: -1 },
{ label: '0', value: 0 },
{ label: '3', value: 3 }
]
}
} else if (Model === 'RealCUGAN-pro') {
if (Scale === 2 || Scale === 3) {
return [
{ label: '-1', value: -1 },
{ label: '0', value: 0 },
{ label: '3', value: 3 }
]
}
} else if (
Model === 'APISR-RRDB' ||
Model === 'RealESRGAN-animevideov3' ||
Model === 'RealESRGAN' ||
Model === 'RealESRGAN-anime'
) {
return [{ label: '0', value: 0 }]
} else if (Model === 'Waifu2x-cunet') {
if (Scale === 1) {
return [
{ label: '0', value: 0 },
{ label: '1', value: 1 },
{ label: '2', value: 2 },
{ label: '3', value: 3 }
]
} else if (Scale === 2) {
return [
{ label: '-1', value: -1 },
{ label: '0', value: 0 },
{ label: '1', value: 1 },
{ label: '2', value: 2 },
{ label: '3', value: 3 }
]
}
} else if (Model === 'Waifu2x-upconv_7_anime_style_art_rgb') {
if (Scale === 2) {
return [
{ label: '-1', value: -1 },
{ label: '0', value: 0 },
{ label: '1', value: 1 },
{ label: '2', value: 2 },
{ label: '3', value: 3 }
]
}
} else if (Model === 'Waifu2x-upconv_7_photo') {
if (Scale === 2) {
return [
{ label: '-1', value: -1 },
{ label: '0', value: 0 },
{ label: '1', value: 1 },
{ label: '2', value: 2 },
{ label: '3', value: 3 }
]
}
}

return [{ label: '0', value: 0 }]
}
export const modelOptions: Ref<any[]> = ref([
{ label: 'RealESRGAN_RealESRGAN_x2plus_2x', value: 'RealESRGAN_RealESRGAN_x2plus_2x.pth' },
{ label: 'RealESRGAN_AnimeJaNai_HD_V3_Compact_2x', value: 'RealESRGAN_AnimeJaNai_HD_V3_Compact_2x.pth' },
])
20 changes: 8 additions & 12 deletions src/renderer/src/utils/getFinal2xconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,18 @@ function getOutPutPATH(): string {
* @description: 返回最终的json字符串配置文件
*/
export const getFinal2xconfig = (): string => {
const { selectedModel, selectedScale, selectedNoise, useTTA, CustomScaleValue } =
const { selectedModel, ghProxy, targetScale } =
storeToRefs(useSRSettingsStore())
const { SRgpuid } = storeToRefs(useGlobalSettingsStore())
const { SRdevice } = storeToRefs(useGlobalSettingsStore())

const gpuID = SRgpuid.value === 114514 ? 0 : SRgpuid.value
const inputPATHList = ioPath.getList()
const outputPATH = getOutPutPATH()
const targetScale = CustomScaleValue.value === null ? 0 : CustomScaleValue.value
return JSON.stringify({
gpuid: gpuID,
inputpath: inputPATHList,
model: selectedModel.value,
modelscale: selectedScale.value,
modelnoise: selectedNoise.value,
outputpath: outputPATH,
targetscale: targetScale,
tta: useTTA.value
pretrained_model_name: selectedModel.value,
device: SRdevice.value,
gh_proxy: ghProxy.value,
target_scale: targetScale.value,
output_path: outputPATH,
input_path: inputPATHList
})
}
38 changes: 0 additions & 38 deletions src/renderer/src/utils/updateDeviceList.ts

This file was deleted.

Loading

0 comments on commit adef5e9

Please sign in to comment.