Skip to content

feat(gui): Support hiding services and their details#746

Merged
awwaawwa merged 6 commits intoPDFMathTranslate:mainfrom
git-deprecated:fix-gradio-ui
Mar 11, 2025
Merged

feat(gui): Support hiding services and their details#746
awwaawwa merged 6 commits intoPDFMathTranslate:mainfrom
git-deprecated:fix-gradio-ui

Conversation

@tylzh97
Copy link
Contributor

@tylzh97 tylzh97 commented Mar 11, 2025

fix #744 problems

Adding two Configure "ENABLED_SERVICES" and "HIDDEN_GRADIO_DETAILS"

and fix some typos.

{
    "USE_MODELSCOPE": "0",
    "translators": [
        {
            "name": "grok",
            "envs": {
                "GORK_API_KEY": null,
                "GORK_MODEL": "grok-2-1212"
            }
        },
        {
            "name": "openai",
            "envs": {
                "OPENAI_BASE_URL": "https://api.openai.com/v1",
                "OPENAI_API_KEY": "sk-xxxxx",
                "OPENAI_MODEL": "gpt-4o-mini"
            }
        }
    ],
    "ENABLED_SERVICES": [
        "OpenAI",
        "Grok",
        "Deepseek"
    ],
    "HIDDEN_GRADIO_DETAILS": true,
    "PDF2ZH_LANG_FROM": "English",
    "PDF2ZH_LANG_TO": "Simplified Chinese",
    "NOTO_FONT_PATH": "/app/SourceHanSerifCN-Regular.ttf"
}

tylzh97 added 2 commits March 11, 2025 06:04
2. A dumb way to fix PDFMathTranslate#744, which keys still in Gradio,
   there is also have risk of key leakage, but the
   GUI view is more clean.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR addresses issues with the gradio UI by fixing translator naming inconsistencies and adding two new configuration options to control enabled services and gradio detail visibility. Key changes include replacing "GorkTranslator" with "GrokTranslator" across multiple files, introducing configuration-based filtering for services via ENABLED_SERVICES, and adding a flag for hiding gradio details via HIDDEN_GRADIO_DETAILS.

Reviewed Changes

File Description
pdf2zh/gui.py Renames translator, adds config handling for enabled services and gradio detail visibility, and updates dropdown defaults.
pdf2zh/converter.py Updates translator reference from GorkTranslator to GrokTranslator.
pdf2zh/pdf2zh.py Renames translator reference from GorkTranslator to GrokTranslator.
pdf2zh/translator.py Renames class from GorkTranslator to GrokTranslator.

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

pdf2zh/gui.py:585

  • Setting the Dropdown's default value to an empty string may cause issues if it does not match any of the choices in enabled_services. Consider using a default value that is present in the enabled_services list.
value=""

@tylzh97
Copy link
Contributor Author

tylzh97 commented Mar 11, 2025

sorry... i guess i have made a mistake. the assertion about enabled_services is too absolute, we need to keep the original when the configuration is not effective. I'll fix it later

@awwaawwa
Copy link
Collaborator

Please handle the situation when these two parameters are not obtained.

CleanShot 2025-03-11 at 15 01 43@2x

@hellofinch
Copy link
Collaborator

hellofinch commented Mar 11, 2025

@tylzh97 @awwaawwa mask的问题,我再次确认了一下,gradio有bug。已经向上游提了issue,在上游确认后再进行修改。
gradio-app/gradio#10781

@tylzh97
Copy link
Contributor Author

tylzh97 commented Mar 11, 2025

Please handle the situation when these two parameters are not obtained.

CleanShot 2025-03-11 at 15 01 43@2x

I intend to set the default configuration to empty because I noticed that the default value does not trigger the "on_select" logic, causing a disruption in the initialization process of related variables.

@awwaawwa
Copy link
Collaborator

Please handle the situation when these two parameters are not obtained.
CleanShot 2025-03-11 at 15 01 43@2x

I intend to set the default configuration to empty because I noticed that the default value does not trigger the "on_select" logic, causing a disruption in the initialization process of related variables.

This will prevent all pdf2zh -i users from using it normally, including all users using .exe

@hellofinch
Copy link
Collaborator

@tylzh97 默认值可以保留Google和bing。这样的话也可以在其他api失效时能够有备用service作为补充。

@awwaawwa
Copy link
Collaborator

@tylzh97 默认值可以保留Google和bing。这样的话也可以在其他api失效时能够有备用service作为补充。

Just display everything directly by default, it doesn't affect users who don't use this feature at all.

@awwaawwa
Copy link
Collaborator

Before the configuration system is completely refactored, we should not introduce too many changes in this area. The initialization of the translator will be completely changed in the configuration system refactoring.

@tylzh97
Copy link
Contributor Author

tylzh97 commented Mar 11, 2025

Gotcha. This is a very simple PR that can meet the real deployment needs. I will ensure that the performance in the default configuration state remains unchanged, and I will submit a patch later. As for Gradio, I am not familiar with nor have used Gradio Mask. Using '***' as a placeholder can ensure that our keys are not leaked.

@awwaawwa
Copy link
Collaborator

Gotcha. This is a very simple PR that can meet the real deployment needs. I will ensure that the performance in the default configuration state remains unchanged, and I will submit a patch later. As for Gradio, I am not familiar with nor have used Gradio Mask. Using '***' as a placeholder can ensure that our keys are not leaked.

Let's handle it this way, this PR will serve as a workaround to temporarily support this requirement. The formal solution will be implemented after the configuration system restructuring is completed.

@hellofinch
Copy link
Collaborator

Gotcha. This is a very simple PR that can meet the real deployment needs. I will ensure that the performance in the default configuration state remains unchanged, and I will submit a patch later. As for Gradio, I am not familiar with nor have used Gradio Mask. Using '***' as a placeholder can ensure that our keys are not leaked.

这个方式应该做不到想要的效果,或者最简单的方式就是直接把相关的部分的type直接设置成password。无论是URL还是API key都设成password。等上游bug解决了,我们就可以动态的设置相关的mask了。

@awwaawwa awwaawwa requested a review from Copilot March 11, 2025 07:33
@tylzh97
Copy link
Contributor Author

tylzh97 commented Mar 11, 2025

  1. 默认配置的情况下:
image
  1. 配置了三个配置,但是没有隐藏的情况下:
image

image

  1. 两个配置都开启的情况下:
image

网络请求信息:
image

翻译结果:
image

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR fixes UI issues in the Gradio interface and corrects naming inconsistencies with the translator classes, while also addressing typos. Key changes include:

  • Renaming all occurrences of "GorkTranslator" to "GrokTranslator".
  • Introducing new configuration keys ("ENABLED_SERVICES" and "HIDDEN_GRADIO_DETAILS") to control available services and hide API keys in the UI.
  • Fixing typos in error messages and comments.

Reviewed Changes

File Description
pdf2zh/gui.py Updated translator reference, added service configuration logic, and fixed error message wording.
pdf2zh/converter.py Renamed translator reference from GorkTranslator to GrokTranslator.
pdf2zh/pdf2zh.py Renamed translator reference from GorkTranslator to GrokTranslator.
pdf2zh/translator.py Renamed class from GorkTranslator to GrokTranslator.

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@awwaawwa
Copy link
Collaborator

Please use black . to format the code

@awwaawwa awwaawwa changed the title Fix gradio UI feat(gui): Support hiding services and their details Mar 11, 2025
@hellofinch
Copy link
Collaborator

有个小问题,目前这样的设计的话,是不是没有了在web上修改API的能力了?

@awwaawwa
Copy link
Collaborator

Can you write a simple document to describe this feature at https://github.com/Byaidu/PDFMathTranslate/blob/main/docs/ADVANCED.md. @tylzh97

@awwaawwa
Copy link
Collaborator

有个小问题,目前这样的设计的话,是不是没有了在web上修改API的能力了?

When this function is needed, it's obviously not desirable for users to modify the API on the webui.

@tylzh97
Copy link
Contributor Author

tylzh97 commented Mar 11, 2025

有个小问题,目前这样的设计的话,是不是没有了在web上修改API的能力了?

是的 我就是这样设计的 因为部署给普通用户使用 也没必要让普通用户修改 API 了[捂脸]

如果需要修改 API 和 API_KEY 那么直接使用项目官网的网页版本就好了 私有化部署可能没有这个需求

@tylzh97
Copy link
Contributor Author

tylzh97 commented Mar 11, 2025

有个小问题,目前这样的设计的话,是不是没有了在web上修改API的能力了?

可以选择不开启 "HIDDEN_GRADIO_DETAILS" 选项 , 这样也允许用户在 Gradio 中修改 API 以及 API_KEY

@awwaawwa awwaawwa requested a review from Copilot March 11, 2025 08:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

A feature update to support hiding services and their detailed information via two new configuration options while also correcting typos and renaming translators.

  • Added documentation for the new configuration keys ENABLED_SERVICES and HIDDEN_GRADIO_DETAILS
  • Renamed translator references from GorkTranslator to GrokTranslator across multiple modules
  • Updated Gradio UI behavior to hide real API keys and enforce enabled service filtering

Reviewed Changes

File Description
docs/ADVANCED.md Added documentation for new configuration options and updated JSON sample usage
pdf2zh/gui.py Updated translator naming, introduced logic for enabled services, and masked API keys
pdf2zh/pdf2zh.py Updated translator list to use GrokTranslator
pdf2zh/translator.py Renamed class from GorkTranslator to GrokTranslator
pdf2zh/converter.py Updated translator list initialization to use GrokTranslator

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

pdf2zh/gui.py:668

  • [nitpick] Consider revising the comment for clarity, for example: 'We use "***" to mask the real API key.'
value = "***"  # We use "***" Present Real API_KEY

@awwaawwa awwaawwa merged commit dc42ded into PDFMathTranslate:main Mar 11, 2025
7 checks passed
@awwaawwa
Copy link
Collaborator

Thank you for your contribution. According to https://funstory-ai.github.io/BabelDOC/CONTRIBUTOR_REWARD/ , you can apply for a monthly membership redemption code for Immersive Translate.

@awwaawwa
Copy link
Collaborator

There is a https://github.com/tylzh97/PDFMathTranslate/blob/fix-gradio-ui/.github/workflows/fork-build.yml CI that can build ghcr docker for forks as well.

The pdf2zh main branch just released 1.9.5, and the next release should be in about 3-5 days or a week. During this period, you can use the ghcr docker image built from the forked repository.

@awwaawwa
Copy link
Collaborator

Or you can also use the image with the dev tag from the main line.

@tylzh97
Copy link
Contributor Author

tylzh97 commented Mar 11, 2025

There is a https://github.com/tylzh97/PDFMathTranslate/blob/fix-gradio-ui/.github/workflows/fork-build.yml CI that can build ghcr docker for forks as well.

The pdf2zh main branch just released 1.9.5, and the next release should be in about 3-5 days or a week. During this period, you can use the ghcr docker image built from the forked repository.

Gotcha, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Hide detailed configuration of translation services in gradio + unconfigured translation services

4 participants