Update app.py
Browse files
app.py
CHANGED
@@ -14,8 +14,6 @@ def remove_space(example):
|
|
14 |
return {'Corpus-Delicti': example['Corpus-Delicti'].replace(" ", "").split('一、')[1]}
|
15 |
|
16 |
def download_file(content, filename):
|
17 |
-
# print(filename)
|
18 |
-
# print(content)
|
19 |
with open(filename, "w", encoding="utf-8") as f:
|
20 |
f.write(content)
|
21 |
|
@@ -39,8 +37,8 @@ def random_next(num_examples=5):
|
|
39 |
court_name = random_selected['Court'][0]
|
40 |
case_no = random_selected['CaseNo'][0]
|
41 |
crime_descrip = random_selected['Corpus-Delicti'][0]
|
42 |
-
|
43 |
-
data_tuple = (court_name, case_no, crime_descrip,
|
44 |
return data_tuple
|
45 |
|
46 |
def gen_template(crime_descrip, element, tag):
|
@@ -75,12 +73,13 @@ use_auth_token = os.environ['HUB_TOKEN'] # 下載判決書資料集所需要的
|
|
75 |
login(token = os.environ['HUB_TOKEN'])
|
76 |
dataset = load_dataset("jslin09/Fraud_Case_Verdicts", use_auth_token=use_auth_token, revision="main")
|
77 |
dataset = dataset.map(remove_space)
|
78 |
-
|
|
|
79 |
random_selected = random_next()
|
80 |
court_name = random_selected[0]
|
81 |
case_no = random_selected[1]
|
82 |
crime_descrip = random_selected[2]
|
83 |
-
|
84 |
|
85 |
with gr.Blocks() as demo:
|
86 |
gr.Markdown(
|
@@ -89,22 +88,17 @@ with gr.Blocks() as demo:
|
|
89 |
""")
|
90 |
with gr.Row():
|
91 |
with gr.Column(): # 犯罪事實段
|
92 |
-
# court_name = random_selected[0]
|
93 |
-
# case_no = random_selected[1]
|
94 |
-
# crime_descrip = random_selected[2]
|
95 |
with gr.Row(): # 抬頭段
|
96 |
courtName = gr.Label(label='法院名稱', value=court_name, visible=False)
|
97 |
caseNo = gr.Label(label='案號', value=case_no, visible=False)
|
98 |
-
|
99 |
prompt = gr.components.Textbox(lines=5, label='犯罪事實',value=crime_descrip)
|
100 |
with gr.Row():
|
101 |
with gr.Column():
|
102 |
btn = gr.Button("隨機選擇")
|
103 |
-
# gr.Examples(examples, inputs=[prompt])
|
104 |
with gr.Column():
|
105 |
with gr.Row():
|
106 |
element = gr.components.Textbox(lines=2, label="構成要件要素")
|
107 |
-
# tag = gr.components.Textbox(label="標籤")
|
108 |
tag = gr.Dropdown(
|
109 |
choices = [("被告(犯罪主體)","<LEO_SOC>"), ("主觀犯意", "<LEO_SLE>"), ("不法行為","<LEO_ACT>"), ("因果關係","<LEO_CAU>"),
|
110 |
("被害人/告訴人","<LEO_VIC>"), ("危害結果","<LEO_ROH>"), ("未遂","<LEO_ATP>"), ("既遂","<LEO_ACC>"),
|
@@ -115,7 +109,7 @@ with gr.Blocks() as demo:
|
|
115 |
btn2 = gr.Button("產生標註語料內容")
|
116 |
result = gr.components.Textbox(lines=5, label="語料內容", show_copy_button=True)
|
117 |
# btn3 = gr.Button("下載")
|
118 |
-
btn.click(random_next, inputs=[], outputs=[courtName, caseNo, prompt,
|
119 |
btn2.click(gen_template, inputs=[prompt, element, tag], outputs=[result])
|
120 |
# btn3.click(download_file, inputs=[result, title], outputs=[])
|
121 |
|
|
|
14 |
return {'Corpus-Delicti': example['Corpus-Delicti'].replace(" ", "").split('一、')[1]}
|
15 |
|
16 |
def download_file(content, filename):
|
|
|
|
|
17 |
with open(filename, "w", encoding="utf-8") as f:
|
18 |
f.write(content)
|
19 |
|
|
|
37 |
court_name = random_selected['Court'][0]
|
38 |
case_no = random_selected['CaseNo'][0]
|
39 |
crime_descrip = random_selected['Corpus-Delicti'][0]
|
40 |
+
filename = court_name + "_" + case_no + '.txt'
|
41 |
+
data_tuple = (court_name, case_no, crime_descrip, filename)
|
42 |
return data_tuple
|
43 |
|
44 |
def gen_template(crime_descrip, element, tag):
|
|
|
73 |
login(token = os.environ['HUB_TOKEN'])
|
74 |
dataset = load_dataset("jslin09/Fraud_Case_Verdicts", use_auth_token=use_auth_token, revision="main")
|
75 |
dataset = dataset.map(remove_space)
|
76 |
+
|
77 |
+
# 隨機選取案件
|
78 |
random_selected = random_next()
|
79 |
court_name = random_selected[0]
|
80 |
case_no = random_selected[1]
|
81 |
crime_descrip = random_selected[2]
|
82 |
+
filename = random_selected[3]
|
83 |
|
84 |
with gr.Blocks() as demo:
|
85 |
gr.Markdown(
|
|
|
88 |
""")
|
89 |
with gr.Row():
|
90 |
with gr.Column(): # 犯罪事實段
|
|
|
|
|
|
|
91 |
with gr.Row(): # 抬頭段
|
92 |
courtName = gr.Label(label='法院名稱', value=court_name, visible=False)
|
93 |
caseNo = gr.Label(label='案號', value=case_no, visible=False)
|
94 |
+
filename = gr.components.Textbox(label='案號',value=filename, show_copy_button=True)
|
95 |
prompt = gr.components.Textbox(lines=5, label='犯罪事實',value=crime_descrip)
|
96 |
with gr.Row():
|
97 |
with gr.Column():
|
98 |
btn = gr.Button("隨機選擇")
|
|
|
99 |
with gr.Column():
|
100 |
with gr.Row():
|
101 |
element = gr.components.Textbox(lines=2, label="構成要件要素")
|
|
|
102 |
tag = gr.Dropdown(
|
103 |
choices = [("被告(犯罪主體)","<LEO_SOC>"), ("主觀犯意", "<LEO_SLE>"), ("不法行為","<LEO_ACT>"), ("因果關係","<LEO_CAU>"),
|
104 |
("被害人/告訴人","<LEO_VIC>"), ("危害結果","<LEO_ROH>"), ("未遂","<LEO_ATP>"), ("既遂","<LEO_ACC>"),
|
|
|
109 |
btn2 = gr.Button("產生標註語料內容")
|
110 |
result = gr.components.Textbox(lines=5, label="語料內容", show_copy_button=True)
|
111 |
# btn3 = gr.Button("下載")
|
112 |
+
btn.click(random_next, inputs=[], outputs=[courtName, caseNo, prompt, filename])
|
113 |
btn2.click(gen_template, inputs=[prompt, element, tag], outputs=[result])
|
114 |
# btn3.click(download_file, inputs=[result, title], outputs=[])
|
115 |
|