freemt
commited on
Commit
·
8289ab0
1
Parent(s):
29e3aa5
Update from_lang logic
Browse files
POST
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
HTTP/1.1 405 Method Not Allowed
|
| 2 |
+
Date: Sat, 06 Aug 2022 01:37:43 GMT
|
| 3 |
+
Content-Type: application/json
|
| 4 |
+
Content-Length: 31
|
| 5 |
+
Connection: keep-alive
|
| 6 |
+
Server: nginx
|
| 7 |
+
X-Powered-By: huggingface-moon
|
| 8 |
+
x-request-id: 23fbb637-9bd3-4eeb-9743-a4f6e73c1802
|
| 9 |
+
allow: POST
|
| 10 |
+
Link: <https://huggingface.co/spaces/mikeee/opus-mt>; rel="canonical"
|
| 11 |
+
Strict-Transport-Security: max-age=31536000; includeSubDomains
|
| 12 |
+
|
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 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
|
|
@@ -12,12 +12,25 @@ translate = EasyNMT("opus-mt").translate
|
|
| 12 |
|
| 13 |
def opusmt(
|
| 14 |
text: str,
|
| 15 |
-
|
| 16 |
to_lang: str = "zh",
|
| 17 |
) -> Union[str, List[str]]:
|
| 18 |
"""Translate via easyntm-opus-mt."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
try:
|
| 20 |
-
res = translate(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
except Exception as e:
|
| 22 |
logger.error(e)
|
| 23 |
res = f"errors: {e}"
|
|
@@ -31,8 +44,8 @@ inputs = [
|
|
| 31 |
lines=7,
|
| 32 |
max_lines=200,
|
| 33 |
),
|
| 34 |
-
|
| 35 |
-
gr.Textbox(label="
|
| 36 |
]
|
| 37 |
outputs = [
|
| 38 |
gr.Textbox(
|
|
@@ -52,8 +65,8 @@ iface = gr.Interface(
|
|
| 52 |
title="opus mt",
|
| 53 |
description=description,
|
| 54 |
examples=[
|
| 55 |
-
["This is a test.", "zh"],
|
| 56 |
-
["This is a test.", "de"],
|
| 57 |
],
|
| 58 |
allow_flagging="never",
|
| 59 |
cache_examples=False,
|
|
|
|
| 1 |
"""Prep gradio API."""
|
| 2 |
# pylint: diable=invalid-name
|
| 3 |
+
from typing import List, Optional, Union
|
| 4 |
|
| 5 |
import gradio as gr
|
| 6 |
from easynmt import EasyNMT
|
|
|
|
| 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 |
+
if to_lang in ["auto"]:
|
| 20 |
+
if from_lang in ["zh"]:
|
| 21 |
+
to_lang = "en"
|
| 22 |
+
else:
|
| 23 |
+
to_lang = "zh"
|
| 24 |
+
|
| 25 |
+
if from_lang in ["auto"]:
|
| 26 |
+
from_lang = None
|
| 27 |
+
|
| 28 |
try:
|
| 29 |
+
res = translate(
|
| 30 |
+
text,
|
| 31 |
+
target_lang=to_lang,
|
| 32 |
+
source_lang=from_lang,
|
| 33 |
+
)
|
| 34 |
except Exception as e:
|
| 35 |
logger.error(e)
|
| 36 |
res = f"errors: {e}"
|
|
|
|
| 44 |
lines=7,
|
| 45 |
max_lines=200,
|
| 46 |
),
|
| 47 |
+
gr.Textbox(label="from-lang", value="auto"),
|
| 48 |
+
gr.Textbox(label="to-lang", value="zh"),
|
| 49 |
]
|
| 50 |
outputs = [
|
| 51 |
gr.Textbox(
|
|
|
|
| 65 |
title="opus mt",
|
| 66 |
description=description,
|
| 67 |
examples=[
|
| 68 |
+
["This is a test.", "en", "zh"],
|
| 69 |
+
["This is a test.", "en", "de"],
|
| 70 |
],
|
| 71 |
allow_flagging="never",
|
| 72 |
cache_examples=False,
|