Update app.py
Browse files
app.py
CHANGED
@@ -68,6 +68,23 @@ def gen_template(crime_descrip, element, tag):
|
|
68 |
template = blurb + '\n' + descript + '\n' + element + '\n' + tag + '\n' + end
|
69 |
return template
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
# 下載判決書資料集
|
72 |
use_auth_token = os.environ['HUB_TOKEN'] # 下載判決書資料集所需要的 token。
|
73 |
login(token = os.environ['HUB_TOKEN'])
|
@@ -108,10 +125,10 @@ with gr.Blocks() as demo:
|
|
108 |
with gr.Column():
|
109 |
btn2 = gr.Button("產生標註語料內容")
|
110 |
result = gr.components.Textbox(lines=5, label="語料內容", show_copy_button=True)
|
111 |
-
|
112 |
btn.click(random_next, inputs=[], outputs=[courtName, caseNo, prompt, filename])
|
113 |
btn2.click(gen_template, inputs=[prompt, element, tag], outputs=[result])
|
114 |
-
|
115 |
|
116 |
if __name__ == "__main__":
|
117 |
demo.launch() # 在遠端啟動時,需要 share=True 。
|
|
|
68 |
template = blurb + '\n' + descript + '\n' + element + '\n' + tag + '\n' + end
|
69 |
return template
|
70 |
|
71 |
+
js_download = 'function downloadFile(result, filename) {
|
72 |
+
//藉型別陣列建構的 blob 來建立 URL
|
73 |
+
let fileName = filename;
|
74 |
+
const data = result;
|
75 |
+
let blob = new Blob([data], {
|
76 |
+
type: "application/octet-stream",
|
77 |
+
});
|
78 |
+
var href = URL.createObjectURL(blob);
|
79 |
+
// 從 Blob 取出資料
|
80 |
+
var link = document.createElement("a");
|
81 |
+
document.body.appendChild(link);
|
82 |
+
link.href = href;
|
83 |
+
link.download = fileName;
|
84 |
+
link.click();
|
85 |
+
}
|
86 |
+
'
|
87 |
+
|
88 |
# 下載判決書資料集
|
89 |
use_auth_token = os.environ['HUB_TOKEN'] # 下載判決書資料集所需要的 token。
|
90 |
login(token = os.environ['HUB_TOKEN'])
|
|
|
125 |
with gr.Column():
|
126 |
btn2 = gr.Button("產生標註語料內容")
|
127 |
result = gr.components.Textbox(lines=5, label="語料內容", show_copy_button=True)
|
128 |
+
btn3 = gr.Button("下載")
|
129 |
btn.click(random_next, inputs=[], outputs=[courtName, caseNo, prompt, filename])
|
130 |
btn2.click(gen_template, inputs=[prompt, element, tag], outputs=[result])
|
131 |
+
btn3.click(None, inputs=[result, filename], js_=js_download)
|
132 |
|
133 |
if __name__ == "__main__":
|
134 |
demo.launch() # 在遠端啟動時,需要 share=True 。
|