Srikanthr7 commited on
Commit
cfdc0e6
·
verified ·
1 Parent(s): 19c7c9c

Upload translator.py

Browse files
Files changed (1) hide show
  1. translator.py +18 -0
translator.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+
3
+ # Load the translation pipeline for English to French
4
+ translator = pipeline("translation_en_to_fr")
5
+
6
+ # Define the English text you want to translate
7
+ english_texts = [
8
+ "Hello, how are you?",
9
+ "I love learning new languages!",
10
+ "Transformers make NLP tasks so easy."
11
+ ]
12
+
13
+ # Translate each sentence
14
+ for text in english_texts:
15
+ translated = translator(text)[0]['translation_text']
16
+ print(f"English: {text}")
17
+ print(f"French: {translated}\n")
18
+