Spaces:
Sleeping
Sleeping
File size: 1,126 Bytes
24cfc7d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# π¦ Install required libraries first (in your Hugging Face Space or Colab, use !pip install ...)
# !pip install transformers sentencepiece
from transformers import pipeline
def main():
# β
Create translation pipeline for t5-small (English β German)
t5_translator = pipeline("translation_en_to_de", model="t5-small")
# β
Create translation pipeline for Helsinki-NLP/opus-mt-en-ta (English β Tamil)
ta_translator = pipeline("translation_en_to_ta", model="Helsinki-NLP/opus-mt-en-ta")
# Example text to translate
text_en1 = "This is a simple text to translate."
text_en2 = "Nature is beautiful and full of wonders."
# Translate using t5-small
result_t5 = t5_translator(text_en1, max_length=40)
print("πΉ T5-small translation (English β German):")
print(result_t5[0]['translation_text'])
print() # blank line
# Translate using Helsinki-NLP/opus-mt-en-ta
result_ta = ta_translator(text_en2, max_length=40)
print("πΉ Helsinki-NLP English β Tamil translation:")
print(result_ta[0]['translation_text'])
if __name__ == "__main__":
main()
|