nnmthuw commited on
Commit
3f54dd3
·
1 Parent(s): 165a970

update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -23
app.py CHANGED
@@ -1,11 +1,16 @@
1
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
- import gradio as gr
 
 
 
3
 
4
  def envit5_translation(text):
5
- inputs = [f"en: {text}"]
6
- outputs = model.generate(tokenizer(inputs, return_tensors="pt", padding=True).input_ids, max_length=512)
7
- results = tokenizer.batch_decode(outputs, skip_special_tokens=True)
8
- return results[0][4:]
 
 
9
 
10
  def my_translation(text):
11
  return "My Translation"
@@ -20,20 +25,27 @@ def translation(text):
20
 
21
  return (output1, output2, output3)
22
 
23
- if __name__ == "__main__":
24
- model_name = "VietAI/envit5-translation"
25
- tokenizer = AutoTokenizer.from_pretrained(model_name)
26
- model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
27
-
28
- inputs = [
29
- "textbox"
30
- ]
31
-
32
- with gr.Blocks() as app:
33
- gr.Interface(
34
- fn=translation,
35
- inputs=inputs,
36
- outputs=["textbox", "textbox", "textbox"]
37
- )
38
-
39
- app.launch(enable_queue=True)
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio.mix import Parallel, Series
3
+ from transformers import pipeline
4
+
5
+ envit5_translater = pipeline("translation", model="VietAI/envit5-translation")
6
 
7
  def envit5_translation(text):
8
+ res = envit5_translater(
9
+ text,
10
+ max_length=512,
11
+ early_stopping=True,
12
+ )[0]['translation_text'][3:]
13
+ return res
14
 
15
  def my_translation(text):
16
  return "My Translation"
 
25
 
26
  return (output1, output2, output3)
27
 
28
+ description = """
29
+ <p>
30
+ <center>
31
+ Multi-domain Translation Between English and Vietnamese
32
+ Using VietAI Translation
33
+ </center>
34
+ </p>
35
+ """
36
+ examples = [
37
+ ["Dear God, thank you for granting us the evergreen garden of this world", "en->vi"],
38
+ ["Thuốc này đã bị cấm sử dụng trong ngành thú y tại Ấn Độ.", "vi->en"]
39
+ ]
40
+
41
+ iface = gr.Interface(
42
+ fn=translation,
43
+ title="Co Gai Mo Duong",
44
+ description=description,
45
+ examples=examples,
46
+ inputs=[
47
+ gr.inputs.Textbox(lines=5, placeholder="Enter text (maximum 5 lines)", label="Input"),
48
+ ],
49
+ outputs=["text", "text", "text"])
50
+
51
+ iface.launch(enable_queue=True)