Spaces:
Runtime error
Runtime error
File size: 1,125 Bytes
df320fd b02b23b df320fd 0c2094b df320fd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
"""Copy from gradio-deepl app.py.
# """
from textwrap import dedent
import gradio as gr
from itranslate import itranslate as itrans
from logzero import logger
def gtr(text, from_lang, to_lang):
try:
text = str(text).strip()
except Exception:
text = ""
if not text:
return "Put something there, man."
try:
trtext = itrans(text, from_lang, to_lang)
except Exception as exc:
logger.error(exc)
trtext = str(exc)
return trtext
if __name__ == "__main__":
_ = dedent("""
Paste text here (max. 5000 chars)
(this interface can be accessed via `import requests; print(requests.post("https://hf.space/embed/mikeee/gradio-gtr/+/api/predict", json={"data": ["hello world", "en", "zh"]}).json()["data"][0]) # '你好世界')`
""").strip()
iface = gr.Interface(
fn=gtr,
inputs=[
gr.Textbox(placeholder=_, lines=7,),
gr.Textbox(label="from_lang", value="en", lines=1),
gr.Textbox(label="to_lang", value="zh", lines=1),
],
outputs="textarea"
)
iface.launch()
|