Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions run.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"github.com/spf13/cobra"
"github.com/yashschandra/upscayl-cli/upscayl"
"log"
Expand All @@ -15,11 +16,33 @@ func getRunCommand() *cobra.Command {
url, _ := cmd.Flags().GetString("url")
model, _ := cmd.Flags().GetString("model-name")
outputPath, _ := cmd.Flags().GetString("output")
outputScale, _ := cmd.Flags().GetInt("output-scale")
compress, _ := cmd.Flags().GetInt("compress")
tileSizeStr, _ := cmd.Flags().GetString("tile-size")
modelPath, _ := cmd.Flags().GetString("model-path")
format, _ := cmd.Flags().GetString("format")
tta, _ := cmd.Flags().GetBool("tta")

scaleStr := fmt.Sprintf("%d", outputScale)

var tileSize *int
if tileSizeStr != "0" {
var t int
fmt.Sscanf(tileSizeStr, "%d", &t)
tileSize = &t
}

input := upscayl.Input{
ImagePath: imagePath,
ImageURL: url,
Model: model,
OutputPath: outputPath,
ImagePath: imagePath,
ImageURL: url,
Model: model,
OutputPath: outputPath,
Scale: scaleStr,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can directly do fmt.Sprintf("%d", outputScale) without defining a new variable to keep code slightly cleaner

Compression: fmt.Sprintf("%d", compress),
TileSize: tileSize,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately for this (and other tile size related code) to work, we have to pass the value (not pointer)

args = append(args, fmt.Sprintf("-t %d", input.TileSize))

ModelPath: modelPath,
SaveImageAs: format,
TTAMode: tta,
}
outputPath, err := upscayl.Upscayl(input)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions upscayl/upscayl.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,12 @@ func upscaylImage(input Input) (string, error) {
return "", errors.New("model does not exist")
}
args = append(args, fmt.Sprintf("-m %s", input.ModelPath))
if input.SaveImageAs == "" {
if input.SaveImageAs == "" || input.SaveImageAs == "ext/png" {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding a condition here, lets remove the default ext/png set at

cmd.Flags().StringP("format", "f", "ext/png", "Output image format (jpg/png/webp)")

input.SaveImageAs = filepath.Ext(input.ImagePath)[1:]
}
args = append(args, fmt.Sprintf("-f %s", input.SaveImageAs))
if input.SaveImageAs != "" {
args = append(args, fmt.Sprintf("-f %s", input.SaveImageAs))
}
if input.GPUId != nil {
args = append(args, fmt.Sprintf("-g %d", input.GPUId))
}
Expand Down