kakamond commited on
Commit
4e64d49
·
verified ·
1 Parent(s): 87eb922

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -71
app.py DELETED
@@ -1,71 +0,0 @@
1
- import json
2
- import requests
3
- import gradio as gr
4
- from utils import API_TRANS, KEY_TRANS, EN_US
5
-
6
- ZH2EN = {
7
- "输入文本区域": "Input text area",
8
- "在这里输入文本...": "Type the text here...",
9
- "模式": "Mode",
10
- "翻译结果": "Translation results",
11
- "状态栏": "Status",
12
- "翻译器": "Translator",
13
- }
14
-
15
-
16
- def _L(zh_txt: str):
17
- return ZH2EN[zh_txt] if EN_US else zh_txt
18
-
19
-
20
- def infer(source, direction):
21
- status = "Success"
22
- result = None
23
- try:
24
- if not source or not direction:
25
- raise ValueError("请输入有效文本!")
26
-
27
- response = requests.request(
28
- "POST",
29
- API_TRANS,
30
- data=json.dumps(
31
- {
32
- "source": source,
33
- "trans_type": direction,
34
- "request_id": "demo",
35
- "detect": True,
36
- }
37
- ),
38
- headers={
39
- "content-type": "application/json",
40
- "x-authorization": f"token {KEY_TRANS}",
41
- },
42
- )
43
-
44
- result = json.loads(response.text)["target"]
45
-
46
- except Exception as e:
47
- status = f"{e}"
48
-
49
- return status, result
50
-
51
-
52
- if __name__ == "__main__":
53
- gr.Interface(
54
- fn=infer,
55
- inputs=[
56
- gr.TextArea(label=_L("输入文本区域"), placeholder=_L("在这里输入文本...")),
57
- gr.Textbox(label=_L("模式"), value="auto2en"),
58
- ],
59
- outputs=[
60
- gr.Textbox(label=_L("状态栏"), buttons=["copy"]),
61
- gr.TextArea(label=_L("翻译结果"), buttons=["fullscreen", "copy"]),
62
- ],
63
- flagging_mode="never",
64
- examples=[
65
- ["这是最好的翻译服务。", "auto2ja"],
66
- ["これは最高の翻訳サービスです。", "auto2en"],
67
- ["This is the best translation service.", "auto2zh"],
68
- ],
69
- cache_examples=False,
70
- title=_L("翻译器"),
71
- ).launch(css="#gradio-share-link-button-0 { display: none; }", ssr_mode=False)