Spaces:
Runtime error
Runtime error
ikechan8370
commited on
Commit
•
e7cf850
1
Parent(s):
0482da5
Update utils.py
Browse files
utils.py
CHANGED
@@ -337,19 +337,19 @@ async def translate(text: str, lang_from: str = "auto", lang_to: str = "zh") ->
|
|
337 |
resp = await client.get(url, params=params)
|
338 |
result = resp.json()
|
339 |
return result["trans_result"][0]["dst"]
|
|
|
340 |
async def translate_microsoft(text: str, lang_from: str = "zh-CN", lang_to: str = "ja") -> str:
|
341 |
if lang_to == 'jp':
|
342 |
lang_to = 'ja'
|
343 |
params = {
|
344 |
"text": text,
|
345 |
-
"
|
346 |
-
"to": lang_to,
|
347 |
}
|
348 |
-
url = "
|
349 |
async with httpx.AsyncClient() as client:
|
350 |
resp = await client.get(url, params=params)
|
351 |
result = resp.json()
|
352 |
-
return result["
|
353 |
|
354 |
def random_text() -> str:
|
355 |
return random.choice(["刘一", "陈二", "张三", "李四", "王五", "赵六", "孙七", "周八", "吴九", "郑十"])
|
|
|
337 |
resp = await client.get(url, params=params)
|
338 |
result = resp.json()
|
339 |
return result["trans_result"][0]["dst"]
|
340 |
+
|
341 |
async def translate_microsoft(text: str, lang_from: str = "zh-CN", lang_to: str = "ja") -> str:
|
342 |
if lang_to == 'jp':
|
343 |
lang_to = 'ja'
|
344 |
params = {
|
345 |
"text": text,
|
346 |
+
"toLang": lang_to,
|
|
|
347 |
}
|
348 |
+
url = "http://translate.ikechan8370.com/translate"
|
349 |
async with httpx.AsyncClient() as client:
|
350 |
resp = await client.get(url, params=params)
|
351 |
result = resp.json()
|
352 |
+
return result["translation"]["translation"]
|
353 |
|
354 |
def random_text() -> str:
|
355 |
return random.choice(["刘一", "陈二", "张三", "李四", "王五", "赵六", "孙七", "周八", "吴九", "郑十"])
|