Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: What just happen? Manga Translator became Unusable at latest commit @,@ #756

Closed
DuckDuckGo-prog opened this issue Nov 30, 2024 · 14 comments
Labels
bug Something isn't working

Comments

@DuckDuckGo-prog
Copy link

DuckDuckGo-prog commented Nov 30, 2024

Issue

root@For-src:~/test-manga-image-translator# python3 -m manga_translator -h
usage: manga_translator [-h] [-v] [--attempts ATTEMPTS] [--ignore-errors] [--model-dir MODEL_DIR]
[--use-gpu | --use-gpu-limited] [--font-path FONT_PATH] [--pre-dict PRE_DICT] [--post-dict POST_DICT]
[--kernel-size KERNEL_SIZE] [--config-file CONFIG_FILE]
{local,ws,shared} ...

Seamlessly translate mangas into a chosen language

positional arguments:
{local,ws,shared} Mode of operation
local Run in batch translation mode
ws Run in WebSocket mode
shared Run in API mode

options:
-h, --help show this help message and exit
-v, --verbose Print debug info and save intermediate images in result folder
--attempts ATTEMPTS Retry attempts on encountered error. -1 means infinite times.
--ignore-errors Skip image on encountered error.
--model-dir MODEL_DIR
Model directory (by default ./models in project root)
--use-gpu Turn on/off gpu (auto switch between mps and cuda)
--use-gpu-limited Turn on/off gpu (excluding offline translator)
--font-path FONT_PATH
Path to font file
--pre-dict PRE_DICT Path to the pre-translation dictionary file
--post-dict POST_DICT
Path to the post-translation dictionary file
--kernel-size KERNEL_SIZE
Set the convolution kernel size of the text erasure area to completely clean up text residues
--config-file CONFIG_FILE
path to the config file

Cooking new arguments?

Command Line Arguments

python3 -m manga_translator -v --mode batch

Console logs

sage: manga_translator [-h] [-v] [--attempts ATTEMPTS] [--ignore-errors] [--model-dir MODEL_DIR]
                        [--use-gpu | --use-gpu-limited] [--font-path FONT_PATH] [--pre-dict PRE_DICT] [--post-dict POST_DICT]
                        [--kernel-size KERNEL_SIZE] [--config-file CONFIG_FILE]
                        {local,ws,shared} ...
manga_translator: error: argument --model-dir: No such directory: "batch"
root@For-src:~/test-manga-image-translator#

Thanks very much for the #703 update though works very well for me as an isolated commit

@DuckDuckGo-prog DuckDuckGo-prog added the bug Something isn't working label Nov 30, 2024
@DuckDuckGo-prog DuckDuckGo-prog changed the title [Bug]: What just happen? Manga Translator became Unusable @,@ [Bug]: What just happen? Manga Translator became Unusable at latest commit @,@ Nov 30, 2024
@frederik-uni
Copy link
Contributor

I moved everything to a config file, which makes it easier to use & understand. could support templates for different use cases easier. the --mode argument didn't really make sense in the first place so you just us either like thispython3 -m manga_translator local -v --attempts 100 --config-file='path/to/file'

@frederik-uni
Copy link
Contributor

#757 for more info

@BlaskKilt
Copy link

BlaskKilt commented Nov 30, 2024

I moved everything to a config file, which makes it easier to use & understand. could support templates for different use cases easier. the --mode argument didn't really make sense in the first place so you just us either like thispython3 -m manga_translator local -v --attempts 100 --config-file='path/to/file'

I got unrecognized args using your config structure and config examples can you clarify this ?

manga_translator: error: unrecognized arguments: -v --attempts 100 --font-path fonts/SSRosehipBold.otf --config-file=config-example.json
root@For-src:/test-manga-image-translator# python3 -m manga_translator -v local --font-path fonts/SSRosehipBold.otf --config-file='config-example.json' -i /root/hmanga/11.28.24/
usage: manga_translator [-h] [-v] [--attempts ATTEMPTS] [--ignore-errors]
[--model-dir MODEL_DIR]
[--use-gpu | --use-gpu-limited]
[--font-path FONT_PATH] [--pre-dict PRE_DICT]
[--post-dict POST_DICT] [--kernel-size KERNEL_SIZE]
[--config-file CONFIG_FILE]
{local,ws,shared} ...
manga_translator: error: unrecognized arguments: --font-path fonts/SSRosehipBold.otf --config-file=config-example.json
root@For-src:
/test-manga-image-translator# ^C
root@For-src:~/test-manga-image-translator#

@frederik-uni
Copy link
Contributor

@BlaskKilt my bad I wrote parser instead of parser_batch in file args.py:108

@BlaskKilt
Copy link

BlaskKilt commented Nov 30, 2024

python3 -m manga_translator local -v --attempts 100 --config-file=

also don't forget font path and ignore errors in local ignore errors for me is helpful when mocr getting error by division by zero which I prefer skip

usage: manga_translator [-h] [-v] [--attempts ATTEMPTS] [--ignore-errors]
[--model-dir MODEL_DIR]
[--use-gpu | --use-gpu-limited]
[--font-path FONT_PATH] [--pre-dict PRE_DICT]
[--post-dict POST_DICT] [--kernel-size KERNEL_SIZE]
{local,ws,shared} ...
manga_translator: error: unrecognized arguments: -v --attempts 5 --font-path fonts/SSRosehipBold.otf
root@For-src:~/test-manga-image-translator#

@frederik-uni
Copy link
Contributor

@BlaskKilt just noticed that argparse is a piece of shit & the order in which you define the structure of the args actually matters.

I fixed this stupid order thing with this workaround. pushed to a open pull request:

args, unknown = parser.parse_known_args()
args = Namespace(**{**vars(args), **vars(reparse(unknown))})

@frederik-uni
Copy link
Contributor

@BlaskKilt these belong to the global parser, which seems to require these args to be placed before the mode which is unintuitive to me. what I did to work around that was to parse the args once & every unknown arg gets rephrased by the global parser. I think it should do that by default, but it does not. is fixed in #759

@BlaskKilt
Copy link

BlaskKilt commented Nov 30, 2024

Thanks, by the way, for taking on the cumbersome work. You have my appreciation. I am also glad I could be of help to you until the issue gets fix

I'll be waiting until these merges to main

@BlaskKilt
Copy link

BlaskKilt commented Nov 30, 2024

@BlaskKilt these belong to the global parser, which seems to require these args to be placed before the mode which is unintuitive to me. what I did to work around that was to parse the args once & every unknown arg gets rephrased by the global parser. I think it should do that by default, but it does not. is fixed in #759

Can you add --detector and --detection-size to usage command its more good for me If I use it as command cause I'm changing detector every batch translate because of errors and --detection-size for it's right size some images trip up the detector until I fix detection-size same problem as detector that causes error

@frederik-uni
Copy link
Contributor

frederik-uni commented Dec 1, 2024

@BlaskKilt it kinda belongs in a config file & for the API takes the config as input. Maybe something that can override the config would be useful to you. I usually use the api anyway, bc you don’t have the startup time.

The ages are only stuff that needs to be set at startup& things that can be changed at runtime(server) is in the config.

Why don’t you ask ChatGPT to write you a simple bash script that replaces the detector &detection-size(regex) in the config and executes the translator afterwards

@BlaskKilt
Copy link

@BlaskKilt it kinda belongs in a config file & for the API takes the config as input. Maybe something that can override the config would be useful to you. I usually use the api anyway, bc you don’t have the startup time.

I'm open to any alternative is good thank you

@BlaskKilt
Copy link

@BlaskKilt it kinda belongs in a config file & for the API takes the config as input. Maybe something that can override the config would be useful to you. I usually use the api anyway, bc you don’t have the startup time.

The ages are only stuff that needs to be set at startup& things that can be changed at runtime(server) is in the config.

Why don’t you ask ChatGPT to write you a simple bash script that replaces the detector &detection-size(regex) in the config and executes the translator afterwards

The thing is I'm using VPS server kinda shorten it for me if I directly command it.

@frederik-uni
Copy link
Contributor

frederik-uni commented Dec 1, 2024

let me introduce you to bash scripting. you let chatgpt write your own little script that does the job for you. don't see the issue. btw if you are using a server why aren't you using the server/main.py. you don't need to wait for the startup & can just send the requests with the config you need to your server. don't really see the point there to host it on a server to run it manually

#!/bin/bash

# Function to print usage
usage() {
    echo "Usage: $0 [options]"
    echo "Options:"
    echo "  -h, --help           Show this help message"
    echo "  -a, --arg ARG        Argument with a value"
    echo "  -f, --flag           Flag without a value"
    echo "  -n, --number NUMBER  Argument with a number"
    exit 1
}

# Check if no arguments are provided
if [ $# -eq 0 ]; then
    usage
fi

# Parse command-line arguments
while [[ $# -gt 0 ]]; do
    key="$1"
    case $key in
        -h|--help)
            usage
            ;;
        -a|--arg)
            ARG_VALUE="$2"
            echo "Argument: $ARG_VALUE"
            shift # past argument
            shift # past value
            ;;
        -f|--flag)
            echo "Flag is set"
            shift # past argument
            ;;
        -n|--number)
            NUMBER_VALUE="$2"
            echo "Number: $NUMBER_VALUE"
            shift # past argument
            shift # past value
            ;;
        *)
            echo "Unknown option: $key"
            usage
            ;;
    esac
done

@BlaskKilt
Copy link

BlaskKilt commented Dec 1, 2024

let me introduce you to bash scripting. you let chatgpt write your own little script that does the job for you. don't see the issue. btw if you are using a server why aren't you using the server/main.py. you don't need to wait for the startup & can just send the requests with the config you need to your server. don't really see the point there to host it on a server to run it manually

#!/bin/bash

# Function to print usage
usage() {
    echo "Usage: $0 [options]"
    echo "Options:"
    echo "  -h, --help           Show this help message"
    echo "  -a, --arg ARG        Argument with a value"
    echo "  -f, --flag           Flag without a value"
    echo "  -n, --number NUMBER  Argument with a number"
    exit 1
}

# Check if no arguments are provided
if [ $# -eq 0 ]; then
    usage
fi

# Parse command-line arguments
while [[ $# -gt 0 ]]; do
    key="$1"
    case $key in
        -h|--help)
            usage
            ;;
        -a|--arg)
            ARG_VALUE="$2"
            echo "Argument: $ARG_VALUE"
            shift # past argument
            shift # past value
            ;;
        -f|--flag)
            echo "Flag is set"
            shift # past argument
            ;;
        -n|--number)
            NUMBER_VALUE="$2"
            echo "Number: $NUMBER_VALUE"
            shift # past argument
            shift # past value
            ;;
        *)
            echo "Unknown option: $key"
            usage
            ;;
    esac
done

Thanks, I will use it when I finish fixing my local as intended or is there batch translations for server? not like the previous one?

tested the server now Can we have option for groq as translator?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants