Untitled

mail@pastecode.io avatar
unknown
ruby
25 days ago
1.0 kB
1
Indexable
Never
#include <HuggingFaceAPI UDF.au3>

$AccessToken = 'hf_...' ;ĐIỀN ACCESS_TOKEN HUGGINGFACE CỦA BẠN VÀO ĐÂY

$text = '我叫沃尔夫冈,我住在柏林。'
MsgBox(0, 'ZhToEng', ZhToEng($text, $AccessToken))

$text = 'I like to study Data Science and Machine Learning.'
MsgBox(0, 'EngToZh', EngToZh($text, $AccessToken))


Func ZhToEng($text, $AccessToken)
	$Model = 'Helsinki-NLP/opus-mt-zh-en'
	$callAPI = _HuggingFaceAPI($Model, '{"inputs":"' & _HTMLEncode($text) & '","parameters":{}}', $AccessToken)
	$TransText = StringRegExp($callAPI, '"translation_text":"([^"]+)"', 1)
	If @error Then Return SetError(1, 0, $callAPI)
	Return $TransText[0]
EndFunc

Func EngToZh($text, $AccessToken)
	$Model = 'liam168/trans-opus-mt-en-zh'
	$callAPI = _HuggingFaceAPI($Model, '{"inputs":"' & _HTMLEncode($text) & '","parameters":{}}', $AccessToken)
	$TransText = StringRegExp($callAPI, '"translation_text":"([^"]+)"', 1)
	If @error Then Return SetError(1, 0, $callAPI)
	Return $TransText[0]
EndFunc
Leave a Comment