Penut commited on
Commit
2a4860b
1 Parent(s): 355f950

Init Commit

Browse files
Files changed (4) hide show
  1. app.py +36 -0
  2. config.json +16 -0
  3. icon.png +0 -0
  4. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import gradio as gr
4
+ from opencc import OpenCC
5
+
6
+ with open("config.json", "rt", encoding="UTF-8") as fp:
7
+ config: dict = json.load(fp)
8
+
9
+ rev_config = {f"{v} ({k})": k for k, v in config.items()}
10
+ rev_config_keys = list(rev_config.keys())
11
+
12
+ title = "簡繁轉換小工具 OpenCC Converter"
13
+ font = gr.themes.GoogleFont("Noto Sans Mono")
14
+ theme = gr.themes.Soft(font=font)
15
+
16
+ with gr.Blocks(title=title, theme=theme) as app:
17
+ gr.Markdown("# 簡繁轉換小工具 OpenCC Converter")
18
+ with gr.Row():
19
+ with gr.Column():
20
+ inn_text = gr.TextArea(label="Input", show_copy_button=True)
21
+ with gr.Column():
22
+ out_text = gr.TextArea(label="Output", show_copy_button=True)
23
+ options = gr.Dropdown(rev_config_keys, value=rev_config_keys[0])
24
+ gr.Markdown("Powered By [OpenCC](https://github.com/BYVoid/OpenCC)")
25
+
26
+ def convert(inn, opt):
27
+ conv = OpenCC(rev_config[opt])
28
+ return conv.convert(inn)
29
+
30
+ args = (convert, [inn_text, options], [out_text])
31
+ kwargs = {"show_progress": "hidden", "queue": False}
32
+ inn_text.change(*args, **kwargs)
33
+ options.change(*args, **kwargs)
34
+
35
+
36
+ app.launch(favicon_path="icon.png")
config.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "t2s": "繁體到簡體",
3
+ "s2t": "簡體到繁體",
4
+ "tw2s": "臺灣正體到簡體",
5
+ "s2tw": "簡體到臺灣正體",
6
+ "hk2s": "香港繁體到簡體",
7
+ "s2hk": "簡體到香港繁體",
8
+ "tw2sp": "臺灣正體到簡體並轉換爲中國大陸常用詞彙",
9
+ "s2twp": "簡體到臺灣正體並轉換爲臺灣常用詞彙",
10
+ "t2tw": "繁體到臺灣正體",
11
+ "hk2t": "香港繁體到繁體",
12
+ "t2hk": "繁體到香港繁體",
13
+ "t2jp": "繁體到日文新字體",
14
+ "jp2t": "日文新字體到繁體",
15
+ "tw2t": "臺灣正體到繁體"
16
+ }
icon.png ADDED
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ opencc