sara musaeva commited on
Commit
014a8e5
1 Parent(s): 8b4d624

Upload 3 files

Browse files
Files changed (2) hide show
  1. appic.py +34 -0
  2. requirements.txt +5 -0
appic.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import T5ForConditionalGeneration, T5Tokenizer
3
+
4
+
5
+ model_name = 'jbochi/madlad400-3b-mt'
6
+ model = T5ForConditionalGeneration.from_pretrained(model_name, device_map="auto")
7
+ tokenizer = T5Tokenizer.from_pretrained(model_name)
8
+
9
+ def translate_to_russian(input_text):
10
+ full_input_text = "<2ru>" + input_text
11
+ input_ids = tokenizer(full_input_text, return_tensors="pt").input_ids.to(model.device)
12
+
13
+ outputs = model.generate(
14
+ input_ids=input_ids,
15
+ max_length=256,
16
+ num_beams=4,
17
+ no_repeat_ngram_size=2,
18
+ length_penalty=1.2
19
+ )
20
+
21
+ translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
22
+ return translated_text
23
+
24
+ # Define Gradio interface
25
+ iface = gr.Interface(
26
+ fn=translate_to_russian,
27
+ inputs=[gr.Textbox(lines=10, placeholder="Enter text to translate")],
28
+ outputs="textbox",
29
+ title="Translate to Russian",
30
+ description="Enter text in English and get the Russian translation.",
31
+ )
32
+
33
+ # Launch the interface
34
+ iface.launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ sentencepiece
4
+ accelerate
5
+ gradio