razent commited on
Commit
1335053
1 Parent(s): 501291b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -23
app.py CHANGED
@@ -5,9 +5,13 @@ from transformers import pipeline
5
 
6
  translater = pipeline("translation", model="VietAI/envit5-translation")
7
 
8
-
9
- def translate(inp):
10
- text = "en: " + inp
 
 
 
 
11
  res = translater(
12
  text,
13
  max_length=512,
@@ -15,23 +19,34 @@ def translate(inp):
15
  )[0]['translation_text'][3:]
16
  return res
17
 
18
-
19
-
20
- sample_url = [['VietAI is a non-profit organization with the mission of nurturing AI talents and building a community of world-class AI experts in Vietnam.'],]
21
-
22
- article = "<p style='text-align: center'><a href='https://vietai.org' target='_blank'>by VietAI Research</a> | <a href='https://github.com/vietai/mtet' target='_blank'>Github</a> | Contact: <a href='mailto:heraclex12@gmail.com' target='_blank'>Hieu Tran</a></p></center></p>"
23
-
24
-
25
- iface = gr.Interface(fn=translate,
26
- inputs = gr.inputs.Textbox(
27
- lines = 5,
28
- label = 'Enter an article...'
29
- ),
30
- outputs = 'text',
31
- title = 'En<->Vi MTet Translation',
32
- theme = 'grass',
33
- layout = 'horizontal',
34
- article=article,
35
- examples=sample_url)
36
-
37
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  translater = pipeline("translation", model="VietAI/envit5-translation")
7
 
8
+
9
+ def translate(inp, direction):
10
+ if direction == 'en->vi':
11
+ text = "en: " + inp
12
+ else:
13
+ text = "vi: " + inp
14
+
15
  res = translater(
16
  text,
17
  max_length=512,
 
19
  )[0]['translation_text'][3:]
20
  return res
21
 
22
+ description = """
23
+ <p>
24
+ <center>
25
+ Multi-domain Translation Between English and Vietnamese
26
+ </center>
27
+ </p>
28
+ """
29
+ article = "<p style='text-align: center'><a href='http://translate.vietai.org' target='_blank'>by VietAI Research</a> | <a href='https://github.com/vietai/mTet' target='_blank'>Github</a> | Contact: <a href='mailto:heraclex12@gmail.com' target='_blank'>Hieu Tran</a></p></center></p>"
30
+ examples = [
31
+ ["Dear God, thank you for granting us the evergreen garden of this world", "en->vi"],
32
+ ["Thuốc này đã bị cấm sử dụng trong ngành thú y tại Ấn Độ.", "vi->en"]
33
+ ]
34
+ iface = gr.Interface(
35
+ fn=translate,
36
+
37
+ title="🌸MTet Translation🌸",
38
+ description=description,
39
+ article=article,
40
+ examples=examples,
41
+ inputs=[
42
+ gr.inputs.Textbox(lines=5, placeholder="Enter text (maximum 5 lines)", label="Input"),
43
+ gr.inputs.Radio(
44
+ choices=[
45
+ 'en->vi',
46
+ 'vi->en'],
47
+ default='en->vi',
48
+ label='Direction'),
49
+ ],
50
+ outputs="text")
51
+
52
+ iface.launch(enable_queue=True)