Spaces:
Sleeping
Sleeping
| # π¦ 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() | |