ffreemt commited on
Commit
df320fd
·
1 Parent(s): 807fa51

Update app.py

Browse files
Files changed (2) hide show
  1. app.py +41 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Copy from gradio-deepl app.py.
2
+ # """
3
+ from textwrap import dedent
4
+
5
+ import gradio as gr
6
+ from itranslate import itranslate as itrans
7
+ from logzero import logger
8
+
9
+
10
+ def gtr(text, from_lang, to_lang):
11
+ try:
12
+ text = str(text).strip()
13
+ except Exception:
14
+ text = ""
15
+ if not text:
16
+ return "Put something there, man."
17
+
18
+ try:
19
+ trtext = itrans(text, from_lang, to_lang)
20
+ except Exception as exc:
21
+ logger.error(exc)
22
+ trtext = str(exc)
23
+
24
+ return trtext
25
+
26
+
27
+ if __name__ == "__main__":
28
+ _ = dedent("""
29
+ Paste text here (max. 5000 chars)
30
+ (this interface can be accessed via curl -XPOST -d'{"hello you", "en", "zh"}'
31
+ """).strip()
32
+ iface = gr.Interface(
33
+ fn=gtr,
34
+ inputs=[
35
+ gr.Textbox(placeholder=_, lines=7,),
36
+ gr.Textbox(label="from_lang", value="en", lines=1),
37
+ gr.Textbox(label="to_lang", value="zh", lines=1),
38
+ ],
39
+ outputs="textarea"
40
+ )
41
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ logzero
3
+ itranslate