rewited funcs
This commit is contained in:
@@ -1,44 +1,20 @@
|
||||
#!/usr/bin/pyhton3
|
||||
import requests
|
||||
import time
|
||||
from random import randint
|
||||
|
||||
|
||||
|
||||
def translate(_input, lang='RU'):
|
||||
url = "https://www2.deepl.com/jsonrpc"
|
||||
_id = randint(10000000, 99999999)
|
||||
def translate(_input, lang='ru'):
|
||||
url = "http://192.168.8.3:5000/translate"
|
||||
|
||||
r = requests.post(
|
||||
url,
|
||||
json={
|
||||
"jsonrpc": "2.0",
|
||||
"method": "LMT_handle_jobs",
|
||||
"params": {
|
||||
"jobs": [{
|
||||
"kind": "default",
|
||||
"raw_en_sentence": _input,
|
||||
"raw_en_context_before": [],
|
||||
"raw_en_context_after": [],
|
||||
"preferred_num_beams": 4,
|
||||
"quality": "fast"
|
||||
}],
|
||||
"lang": {
|
||||
"user_preferred_langs": [lang],
|
||||
"source_lang_user_selected": "auto",
|
||||
"target_lang": "RU"
|
||||
},
|
||||
"priority": -1,
|
||||
"commonJobParams": {},
|
||||
"timestamp": int(round(time.time() * 1000))
|
||||
},
|
||||
"id": _id
|
||||
}
|
||||
)
|
||||
try:
|
||||
return r.json()['result']['translations'][0]['beams'][0]['postprocessed_sentence']
|
||||
except:
|
||||
print(r.json())
|
||||
|
||||
"q": _input,
|
||||
"source": "en",
|
||||
"target": lang,
|
||||
},
|
||||
headers={"Content-Type": "application/json"}
|
||||
|
||||
)
|
||||
return r.json()['translatedText']
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user