admin commited on
Commit
ed3849d
1 Parent(s): af12ce1
Files changed (3) hide show
  1. .gitignore +1 -0
  2. README.md +2 -2
  3. app.py +85 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ rename.sh
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
  title: Data Converter
3
- emoji: 😻
4
  colorFrom: indigo
5
  colorTo: pink
6
  sdk: gradio
7
- sdk_version: 4.16.0
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
 
1
  ---
2
  title: Data Converter
3
+ emoji: 🔢
4
  colorFrom: indigo
5
  colorTo: pink
6
  sdk: gradio
7
+ sdk_version: 4.36.0
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ from utils import *
4
+
5
+
6
+ def infer(input_file: str):
7
+ clean_cache()
8
+ try:
9
+ data_list = eval(f'encoder_{MODE["from"]}')(input_file)
10
+ output_file = eval(f'decoder_{MODE["to"]}')(data_list)
11
+ return output_file, pd.DataFrame(data_list)
12
+
13
+ except Exception as e:
14
+ return None, pd.DataFrame([{"请上传标准的数据文件": f"{e}"}])
15
+
16
+
17
+ if __name__ == "__main__":
18
+ with gr.Blocks() as demo:
19
+ for item in TAB_CONFIG:
20
+ types = item.split(" ⇆ ")
21
+ with gr.Tab(item) as tab:
22
+ with gr.Row():
23
+ with gr.Column():
24
+ option = gr.Dropdown(
25
+ choices=[
26
+ f"{types[0]} → {types[1]}",
27
+ f"{types[0]} ← {types[1]}",
28
+ ],
29
+ label="模式 Mode",
30
+ value=f"{types[0]} → {types[1]}",
31
+ )
32
+ input_file = gr.components.File(
33
+ type="filepath",
34
+ label="上传原数据 Upload input file",
35
+ file_types=[f".{types[0]}", f".{types[1]}"],
36
+ )
37
+ convert_btn = gr.Button("转换 Convert")
38
+
39
+ with gr.Column():
40
+ output_file = gr.components.File(
41
+ type="filepath", label="下载转换数据 Download output file"
42
+ )
43
+ data_viewer = gr.Dataframe(label="数据预览 Data viewer")
44
+
45
+ option.change(change_mode, inputs=option)
46
+ tab.select(change_mode, inputs=option)
47
+ convert_btn.click(
48
+ infer, inputs=input_file, outputs=[output_file, data_viewer]
49
+ )
50
+
51
+ gr.Markdown(
52
+ """
53
+ ## 支持的 JSON 格式 (Supported JSON format)
54
+ ```
55
+ [
56
+ {
57
+ "key1": "val11",
58
+ "key2": "val12",
59
+ ...
60
+ },
61
+ {
62
+ "key1": "val21",
63
+ "key2": "val22",
64
+ ...
65
+ },
66
+ ...
67
+ ]
68
+ ```
69
+ ## 支持的 JSON Lines 格式 (Supported jsonl format)
70
+ ```
71
+ {"key1": "val11", "key2": "val12", ...}
72
+ {"key1": "val21", "key2": "val22", ...}
73
+ ...
74
+ ```
75
+ ## 支持的 CSV 格式 (Supported CSV format)
76
+ ```
77
+ key1, key2, ...
78
+ val11, val12, ...
79
+ val21, val22, ...
80
+ ...
81
+ ```
82
+ """
83
+ )
84
+
85
+ demo.launch()