Spaces:
Sleeping
Sleeping
File size: 750 Bytes
bc3b289 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
from gradio_client import Client
from iso639 import languages
HF_TOKEN = "YOUR-HF-TOKEN-HERE"
class SalamandraTA7bTranslator:
def __init__(self):
self.client = Client("BSC-LT/SalamandraTA-7B-Demo", hf_token=HF_TOKEN)
def translate(self, text, source_lang, target_lang):
# we assume that they are specifying the language by code so we need to convert it to name
lang1 = languages.get(alpha2=source_lang).name
lang2 = languages.get(alpha2=target_lang).name
result = self.client.predict(
task="Translation",
source=lang1,
target=lang2,
input_text=text,
mt_text=None,
api_name="/generate_output"
)
return result[0]
|