Spaces:
Runtime error
Runtime error
File size: 1,089 Bytes
39d4f47 679a546 39d4f47 |
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 |
from multiprocessing import Process, freeze_support
import gradio as gr
import httpx
from logzero import logger
from deepl_fastapi.run_uvicorn import main
def deepl(text, from_lang, to_lang):
# "http://127.0.0.1:8000/text/?q=test%20me&to_lang=zh"
url = "http://127.0.0.1:8000/text/" # ?q=test%20me&to_lang=zh"
try:
resp = httpx.get(f"{url}?q={text}&from_lang={from_lang}&to_lang={to_lang}")
resp.raise_for_status()
except Exception as exc:
logger.error(exc)
return str(exc)
try:
jdata = resp.json()
except Exception as exc:
logger.error(exc)
return str(exc)
return jdata.get("trtext")
if __name__ == "__main__":
freeze_support()
Process(target=main).start()
iface = gr.Interface(
fn=deepl,
inputs=[
gr.Textbox(placeholder="Paste text here (max. 5000 chars)", lines=7,),
gr.Textbox(label="from_lang", value="en", lines=1),
gr.Textbox(label="to_lang", value="zh", lines=1),
],
outputs="textarea"
)
iface.launch()
|