Spaces:
Runtime error
Runtime error
"""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() | |