diff --git a/MangaJaNaiConverterGui/Services/PythonService.cs b/MangaJaNaiConverterGui/Services/PythonService.cs index 3677e05..5581413 100644 --- a/MangaJaNaiConverterGui/Services/PythonService.cs +++ b/MangaJaNaiConverterGui/Services/PythonService.cs @@ -148,7 +148,7 @@ public string InstallUpdatePythonDependenciesCommand var relPythonPath = @".\python\python\python.exe"; - return $@"{relPythonPath} -m pip install torch==2.3.1 torchvision==0.18.1 --index-url https://download.pytorch.org/whl/cu121 && {relPythonPath} -m pip install {string.Join(" ", dependencies)}"; + return $@"{relPythonPath} -m pip install torch==2.1.0 torchvision==0.18.1 --index-url https://download.pytorch.org/whl/cu121 && {relPythonPath} -m pip install {string.Join(" ", dependencies)}"; } } diff --git a/MangaJaNaiConverterGui/ViewModels/MainWindowViewModel.cs b/MangaJaNaiConverterGui/ViewModels/MainWindowViewModel.cs index a43e7a1..d8d779b 100644 --- a/MangaJaNaiConverterGui/ViewModels/MainWindowViewModel.cs +++ b/MangaJaNaiConverterGui/ViewModels/MainWindowViewModel.cs @@ -172,6 +172,13 @@ public string[] DeviceList } } + private string _pythonPipList = string.Empty; + public string PythonPipList + { + get => _pythonPipList; + set => this.RaiseAndSetIfChanged(ref _pythonPipList, value); + } + private AvaloniaDictionary _displayDeviceMap = []; [DataMember] public AvaloniaDictionary DisplayDeviceMap @@ -830,6 +837,56 @@ public async Task InitializeDeviceList() return []; } + public async Task RunPythonPipList() + { + List result = []; + + // Create a new process to run the CMD command + using (var process = new Process()) + { + _runningProcess = process; + process.StartInfo.FileName = "cmd.exe"; + process.StartInfo.Arguments = @$"/C .\python\python\python.exe -m pip list"; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.RedirectStandardError = true; + process.StartInfo.UseShellExecute = false; + process.StartInfo.CreateNoWindow = true; + process.StartInfo.WorkingDirectory = _pythonService.BackendDirectory; + process.StartInfo.StandardOutputEncoding = Encoding.UTF8; + process.StartInfo.StandardErrorEncoding = Encoding.UTF8; + + // Create a StreamWriter to write the output to a log file + try + { + process.ErrorDataReceived += (sender, e) => + { + if (!string.IsNullOrEmpty(e.Data)) + { + //outputFile.WriteLine(e.Data); // Write the output to the log file + //ConsoleQueueEnqueue(e.Data); + Debug.WriteLine(e.Data); + } + }; + + process.OutputDataReceived += (sender, e) => + { + if (!string.IsNullOrEmpty(e.Data)) + { + result.Add(e.Data); + } + }; + + process.Start(); + process.BeginOutputReadLine(); + process.BeginErrorReadLine(); // Start asynchronous reading of the output + await process.WaitForExitAsync(); + } + catch (IOException) { } + } + + return string.Join("\n", result); + } + public async void ShowSettingsDialog() { var result = await ShowDialog.Handle(this); @@ -902,7 +959,7 @@ public void WriteCurrentWorkflowToFile(string fullPath) File.WriteAllText(fullPath, lines); } - public async void CheckAndExtractBackend() + public async Task CheckAndExtractBackend() { await Task.Run(async () => { @@ -956,6 +1013,23 @@ await Downloader.DownloadFileAsync(download.Url, targetPath, (progress) => { UseCpu = true; } + + PythonPipList = await RunPythonPipList(); + } + + public async Task ReinstallBackend() + { + if (Directory.Exists(_pythonService.ModelsDirectory)) + { + Directory.Delete(_pythonService.ModelsDirectory, true); + } + + if (Directory.Exists(_pythonService.PythonDirectory)) + { + Directory.Delete(_pythonService.PythonDirectory, true); + } + + await CheckAndExtractBackend(); } public async Task DownloadModels() diff --git a/MangaJaNaiConverterGui/Views/MainWindow.axaml b/MangaJaNaiConverterGui/Views/MainWindow.axaml index 8e658aa..8e79e81 100644 --- a/MangaJaNaiConverterGui/Views/MainWindow.axaml +++ b/MangaJaNaiConverterGui/Views/MainWindow.axaml @@ -105,12 +105,12 @@ - + - + - + @@ -436,7 +436,7 @@ Advanced settings are locked for the default workflow, and are displayed below for reference only. Select any custom workflow to modify the advanced settings for that workflow. - + @@ -447,103 +447,103 @@ - - - - - Resolution Range - - px - - - - - px - Range of image resolutions to activate this chain. Select a common resolution from the drop down or type a custom resolution. Larger resolutions require more processing power to upscale. A dimension value of 0 means any value for that dimension, for example 0x1250 means any width, and 1250px tall. A maximum resolution of 0x0 means no resolution limit. - - - - Scaling Factor Range - - x - - - - - x - Range of necessary scaling factor to activate this chain. A maximum scaling factor of 0 means no maximum limit. - - - - Is Color Image - Is Grayscale Image - Whether the image is color and/or grayscale. Images that appear grayscale but have faint color due to JPEG artifacts are still considered grayscale. - - - - - - - - + + + + + Resolution Range + + px + + - + + px + Range of image resolutions to activate this chain. Select a common resolution from the drop down or type a custom resolution. Larger resolutions require more processing power to upscale. A dimension value of 0 means any value for that dimension, for example 0x1250 means any width, and 1250px tall. A maximum resolution of 0x0 means no resolution limit. + + + + Scaling Factor Range + + x + + - + + x + Range of necessary scaling factor to activate this chain. A maximum scaling factor of 0 means no maximum limit. + + + + Is Color Image + Is Grayscale Image + Whether the image is color and/or grayscale. Images that appear grayscale but have faint color due to JPEG artifacts are still considered grayscale. + - - Auto Adjust Levels on Grayscale Images - If checked, automatically increase the contrast of all grayscale images if necessary. For best results with the MangaJaNai grayscale model, this setting is recommend when upscaling images which appear to be faded. This will have no effect on color images or grayscale images with sufficient contrast. - - - Resize Height Before Upscale - - px - - Resize each image to this height before upscaling, set to 0 to disable. - - - - Resize Width Before Upscale - - px - - Resize each image to this width before upscaling, set to 0 to disable. - - - - Resize Factor Before Upscale - - % - - Resize each image by this factor before upscaling. This setting is ignored if Resize Height Before Upscale is specified. - + + + + + + + + Auto Adjust Levels on Grayscale Images + If checked, automatically increase the contrast of all grayscale images if necessary. For best results with the MangaJaNai grayscale model, this setting is recommend when upscaling images which appear to be faded. This will have no effect on color images or grayscale images with sufficient contrast. + + + Resize Height Before Upscale + + px + + Resize each image to this height before upscaling, set to 0 to disable. + + + + Resize Width Before Upscale + + px + + Resize each image to this width before upscaling, set to 0 to disable. + + + + Resize Factor Before Upscale + + % + + Resize each image by this factor before upscaling. This setting is ignored if Resize Height Before Upscale is specified. + + + + + Model + + + The upscaling model to run. To choose from more models, add PyTorch (*.pth) model files to the models directory. + + + + Model Tile Size + + px + Tile size to use when upscaling images with the selected model. The image is cut into tiles in order to upscale without running into the VRAM limits of your GPU. Larger is better when the GPU has enough VRAM to support it. The auto setting estimates the largest tile size which can be used based on available VRAM and is recommended for most users. + - - Model - - - The upscaling model to run. To choose from more models, add PyTorch (*.pth) model files to the models directory. - - Model Tile Size - - px - Tile size to use when upscaling images with the selected model. The image is cut into tiles in order to upscale without running into the VRAM limits of your GPU. Larger is better when the GPU has enough VRAM to support it. The auto setting estimates the largest tile size which can be used based on available VRAM and is recommended for most users. - + - - - - - + - A chain is a a set of upscale settings which can be activated based on conditions such as the image resolution and whether the image is color or grayscale. - This allows you to specify different upscale models for different types of images. + A chain is a a set of upscale settings which can be activated based on conditions such as the image resolution and whether the image is color or grayscale. + This allows you to specify different upscale models for different types of images. @@ -582,110 +582,123 @@ - - - - - - - - - - - - - - Auto Update - - Whether to automatically check for and install app updates. - - + + + + + + + - - - - - + + + + + + + Auto Update + + Whether to automatically check for and install app updates. + + - - - + + + + + - - - + + + - - - + + + - - - + + - - - - App is not installed; auto update settings unavailable. + + + - - - - - - - - + - GPU - - - Which GPU to use for upscaling with PyTorch. - + App is not installed; auto update settings unavailable. + + + - - CPU Mode - - Use CPU for upscaling with PyTorch instead of GPU. - - + + + + + + + + GPU + + + Which GPU to use for upscaling with PyTorch. + + - - FP16 Mode - - Runs PyTorch upscaling in FP16 mode for less VRAM usage and speedup on RTX GPUs. - - + + CPU Mode + + Use CPU for upscaling with PyTorch instead of GPU. + - - - - - - - - - - + + FP16 Mode + + Runs PyTorch upscaling in FP16 mode for less VRAM usage and speedup on RTX GPUs. + - + + - - - - - Return - - - - - + + + + + + + + + + + + + + + +