freemt commited on
Commit
2c9474d
·
1 Parent(s): a5b0d33

first commit

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -1,18 +1,21 @@
1
  """Prep gradio API."""
2
  # pylint: diable=invalid-name
3
- from typing import Optional
4
- from easynmt import EasyNMT
5
  import gradio as gr
 
6
  from logzero import logger
7
 
8
- model = EasyNMT('opus-mt')
9
  translate = model.translate
10
 
 
11
  def opusmt(
12
  text: str,
13
  # from_lang: Optional[str] = None,
14
  to_lang: str = "zh",
15
  ) -> Union[str, List[str]]:
 
16
  try:
17
  res = translate(text, target_lang=to_lang)
18
  except Exception as e:
@@ -33,23 +36,24 @@ inputs = [
33
  ]
34
  outputs = [
35
  gr.Textbox(
36
- label=f"translated",
37
  lines=7,
38
  max_lines=200,
39
  ),
 
40
 
41
- description = """Supported languages: aav, aed, af, alv, am, ar, art, ase, az, bat, bcl, be, bem, ber, bg, bi, bn, bnt, bzs, ca, cau, ccs, ceb, cel, chk, cpf, crs, cs, csg, csn, cus, cy, da, de, dra, ee, efi, el, en, eo, es, et, eu, euq, fi, fj, fr, fse, ga, gaa, gil, gl, grk, guw, gv, ha, he, hi, hil, ho, hr, ht, hu, hy, id, ig, ilo, is, iso, it, ja, jap, ka, kab, kg, kj, kl, ko, kqn, kwn, kwy, lg, ln, loz, lt, lu, lua, lue, lun, luo, lus, lv, map, mfe, mfs, mg, mh, mk, mkh, ml, mos, mr, ms, mt, mul, ng, nic, niu, nl, no, nso, ny, nyk, om, pa, pag, pap, phi, pis, pl, pon, poz, pqe, pqw, prl, pt, rn, rnd, ro, roa, ru, run, rw, sal, sg, sh, sit, sk, sl, sm, sn, sq, srn, ss, ssp, st, sv, sw, swc, taw, tdt, th, ti, tiv, tl, tll, tn, to, toi, tpi, tr, trk, ts, tum, tut, tvl, tw, ty, tzo, uk, umb, ur, ve, vi, vsl, wa, wal, war, wls, xh, yap, yo, yua, zai, zh, zne. Refer to [https://github.com/UKPLab/EasyNMT](https://github.com/UKPLab/EasyNMT) for details.
42
  """
43
 
44
  iface = gr.Interface(
45
  fn=opusmt,
46
  inputs=inputs,
47
- outputs=putputs,
48
  title="opus mt",
49
  description=description,
50
  examples=[
51
  ["This is a test.", "zh"],
52
  ["This is a test.", "de"],
53
- ]
54
- )
55
  iface.launch(enable_queue=True)
 
1
  """Prep gradio API."""
2
  # pylint: diable=invalid-name
3
+ from typing import List, Union
4
+
5
  import gradio as gr
6
+ from easynmt import EasyNMT
7
  from logzero import logger
8
 
9
+ model = EasyNMT("opus-mt")
10
  translate = model.translate
11
 
12
+
13
  def opusmt(
14
  text: str,
15
  # from_lang: Optional[str] = None,
16
  to_lang: str = "zh",
17
  ) -> Union[str, List[str]]:
18
+ """Translate via easyntm-opus-mt."""
19
  try:
20
  res = translate(text, target_lang=to_lang)
21
  except Exception as e:
 
36
  ]
37
  outputs = [
38
  gr.Textbox(
39
+ label="translated",
40
  lines=7,
41
  max_lines=200,
42
  ),
43
+ ]
44
 
45
+ description = """Supported languages: aav, aed, af, alv, am, ar, art, ase, az, bat, bcl, be, bem, ber, bg, bi, bn, bnt, bzs, ca, cau, ccs, ceb, cel, chk, cpf, crs, cs, csg, csn, cus, cy, da, de, dra, ee, efi, el, en, eo, es, et, eu, euq, fi, fj, fr, fse, ga, gaa, gil, gl, grk, guw, gv, ha, he, hi, hil, ho, hr, ht, hu, hy, id, ig, ilo, is, iso, it, ja, jap, ka, kab, kg, kj, kl, ko, kqn, kwn, kwy, lg, ln, loz, lt, lu, lua, lue, lun, luo, lus, lv, map, mfe, mfs, mg, mh, mk, mkh, ml, mos, mr, ms, mt, mul, ng, nic, niu, nl, no, nso, ny, nyk, om, pa, pag, pap, phi, pis, pl, pon, poz, pqe, pqw, prl, pt, rn, rnd, ro, roa, ru, run, rw, sal, sg, sh, sit, sk, sl, sm, sn, sq, srn, ss, ssp, st, sv, sw, swc, taw, tdt, th, ti, tiv, tl, tll, tn, to, toi, tpi, tr, trk, ts, tum, tut, tvl, tw, ty, tzo, uk, umb, ur, ve, vi, vsl, wa, wal, war, wls, xh, yap, yo, yua, zai, zh, zne. Refer to [https://github.com/UKPLab/EasyNMT](https://github.com/UKPLab/EasyNMT) for details. Estimated speed 6-60 sents/sec.
46
  """
47
 
48
  iface = gr.Interface(
49
  fn=opusmt,
50
  inputs=inputs,
51
+ outputs=outputs,
52
  title="opus mt",
53
  description=description,
54
  examples=[
55
  ["This is a test.", "zh"],
56
  ["This is a test.", "de"],
57
+ ],
58
+ )
59
  iface.launch(enable_queue=True)