Create client.translation()
Browse files- client.translation() +18 -0
client.translation()
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
|
| 4 |
+
# 1. เชื่อมต่อกับ Hugging Face (ต้องมี HF_TOKEN)
|
| 5 |
+
client = InferenceClient(
|
| 6 |
+
provider="hf-inference",
|
| 7 |
+
api_key=os.environ.get("HF_TOKEN"), # ดึง Token จากเครื่องของคุณ
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
# 2. สั่งแปลภาษา โดยต้องระบุ src_lang และ tgt_lang เพิ่มเข้าไป
|
| 11 |
+
result = client.translation(
|
| 12 |
+
"My name is Omar and I live in Zürich.",
|
| 13 |
+
model="facebook/mbart-large-50-many-to-many-mmt",
|
| 14 |
+
src_lang="en_XX", # ระบุภาษาต้นทาง (อังกฤษ)
|
| 15 |
+
tgt_lang="de_DE" # ระบุภาษาปลายทาง (เยอรมัน)
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
print(result)
|