Skip to content

Commit

Permalink
chore: env
Browse files Browse the repository at this point in the history
  • Loading branch information
Byaidu committed Dec 6, 2024
1 parent 6981951 commit a48b464
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions pdf2zh/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
}

flag_demo = False
if os.environ.get("PDF2ZH_DEMO"):
if os.getenv("PDF2ZH_DEMO"):
flag_demo = True
service_map = {
"Google": GoogleTranslator,
Expand All @@ -59,8 +59,8 @@
"First": [0],
"First 20 pages": list(range(0, 20)),
}
client_key = os.environ.get("PDF2ZH_CLIENT_KEY")
server_key = os.environ.get("PDF2ZH_SERVER_KEY")
client_key = os.getenv("PDF2ZH_CLIENT_KEY")
server_key = os.getenv("PDF2ZH_SERVER_KEY")


def verify_recaptcha(response):
Expand Down Expand Up @@ -150,7 +150,7 @@ def translate(
lang_to = lang_map[lang_to]

for i, env in enumerate(translator.envs.items()):
os.environ.setdefault(env[0], envs[i])
os.putenv(env[0], envs[i])

print(f"Files before translation: {os.listdir(output)}")

Expand Down Expand Up @@ -317,7 +317,7 @@ def on_select_service(service, evt: gr.EventData):
_envs.append(gr.update(visible=False, value=""))
for i, env in enumerate(translator.envs.items()):
_envs[i] = gr.update(
visible=True, label=env[0], value=os.environ.get(env[0], env[1])
visible=True, label=env[0], value=os.getenv(env[0], env[1])
)
return _envs

Expand Down
8 changes: 4 additions & 4 deletions pdf2zh/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class DeepLTranslator(BaseTranslator):
def __init__(self, service, lang_out, lang_in, model):
super().__init__(service, lang_out, lang_in, model)
self.session = requests.Session()
server_url = os.getenv("DEEPL_SERVER_URL")
server_url = os.getenv("DEEPL_SERVER_URL", self.envs["DEEPL_SERVER_URL"])
auth_key = os.getenv("DEEPL_AUTH_KEY")
self.client = deepl.Translator(auth_key, server_url=server_url)

Expand All @@ -177,7 +177,7 @@ class DeepLXTranslator(BaseTranslator):

def __init__(self, service, lang_out, lang_in, model):
super().__init__(service, lang_out, lang_in, model)
self.endpoint = os.getenv("DEEPLX_ENDPOINT")
self.endpoint = os.getenv("DEEPLX_ENDPOINT", self.envs["DEEPLX_ENDPOINT"])
self.session = requests.Session()

def translate(self, text):
Expand Down Expand Up @@ -252,8 +252,8 @@ class AzureTranslator(BaseTranslator):

def __init__(self, service, lang_out, lang_in, model):
super().__init__(service, lang_out, lang_in, model)
endpoint = os.environ["AZURE_ENDPOINT"]
api_key = os.environ["AZURE_APIKEY"]
endpoint = os.getenv("AZURE_ENDPOINT", self.envs["AZURE_ENDPOINT"])
api_key = os.getenv("AZURE_APIKEY")
credential = AzureKeyCredential(api_key)
self.client = TextTranslationClient(
endpoint=endpoint, credential=credential, region="chinaeast2"
Expand Down

0 comments on commit a48b464

Please sign in to comment.