aokitools commited on
Commit ·
54f47d8
1
Parent(s): 9f4ae20
commit
Browse files
app.py
CHANGED
|
@@ -459,7 +459,7 @@ def f_janome(e_text1):
|
|
| 459 |
|
| 460 |
global_google_encoder = None
|
| 461 |
|
| 462 |
-
def f_googlesentenceencoder(e_text1):
|
| 463 |
result = {}
|
| 464 |
result["output1"] = ""
|
| 465 |
result["output2"] = ""
|
|
@@ -467,9 +467,26 @@ def f_googlesentenceencoder(e_text1):
|
|
| 467 |
|
| 468 |
s1 = e_text1
|
| 469 |
|
|
|
|
| 470 |
list1 = []
|
|
|
|
| 471 |
for i1 in s1.splitlines()[:1000]:
|
| 472 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
pass
|
| 474 |
|
| 475 |
global global_google_encoder
|
|
@@ -505,7 +522,7 @@ def f_googlesentenceencoder(e_text1):
|
|
| 505 |
s3 = json.dumps(d1, ensure_ascii=False)
|
| 506 |
list_vector1.append(s3)
|
| 507 |
|
| 508 |
-
s4 = "{0
|
| 509 |
list_text1.append(s4)
|
| 510 |
pass
|
| 511 |
|
|
@@ -935,13 +952,14 @@ with gr.Blocks() as sample01:
|
|
| 935 |
|
| 936 |
with gr.Tab("文章ベクトル"):
|
| 937 |
e_text1 = gr.TextArea(show_label=True, label="TEXT")
|
|
|
|
| 938 |
|
| 939 |
e_button1 = gr.Button("変換")
|
| 940 |
|
| 941 |
e_text2 = gr.TextArea(show_label=True, label="JSON LINES")
|
| 942 |
e_text3 = gr.TextArea(show_label=True, label="ベクトル")
|
| 943 |
|
| 944 |
-
e_button1.click(f_googlesentenceencoder, inputs=[e_text1], outputs=[e_text2, e_text3])
|
| 945 |
pass
|
| 946 |
|
| 947 |
|
|
|
|
| 459 |
|
| 460 |
global_google_encoder = None
|
| 461 |
|
| 462 |
+
def f_googlesentenceencoder(e_text1, e_checkbox1):
|
| 463 |
result = {}
|
| 464 |
result["output1"] = ""
|
| 465 |
result["output2"] = ""
|
|
|
|
| 467 |
|
| 468 |
s1 = e_text1
|
| 469 |
|
| 470 |
+
list_labels = []
|
| 471 |
list1 = []
|
| 472 |
+
index1 = 0
|
| 473 |
for i1 in s1.splitlines()[:1000]:
|
| 474 |
+
s1 = i1.strip()
|
| 475 |
+
|
| 476 |
+
if e_checkbox1:
|
| 477 |
+
ss1 = s1.split()
|
| 478 |
+
s2 = ss1[0]
|
| 479 |
+
s1 = " ".join(ss1[1:])
|
| 480 |
+
pass
|
| 481 |
+
else:
|
| 482 |
+
s2 = "{0:08}".format(index1)
|
| 483 |
+
s1 = " ".join(s1.split())
|
| 484 |
+
pass
|
| 485 |
+
|
| 486 |
+
list1.append(s1)
|
| 487 |
+
list_labels.append(s2)
|
| 488 |
+
|
| 489 |
+
index1 += 1
|
| 490 |
pass
|
| 491 |
|
| 492 |
global global_google_encoder
|
|
|
|
| 522 |
s3 = json.dumps(d1, ensure_ascii=False)
|
| 523 |
list_vector1.append(s3)
|
| 524 |
|
| 525 |
+
s4 = "{0}\t{1}".format(list_labels[i1], s2)
|
| 526 |
list_text1.append(s4)
|
| 527 |
pass
|
| 528 |
|
|
|
|
| 952 |
|
| 953 |
with gr.Tab("文章ベクトル"):
|
| 954 |
e_text1 = gr.TextArea(show_label=True, label="TEXT")
|
| 955 |
+
e_checkbox1 = gr.Checkbox(label="1カラム目をラベルとして設定")
|
| 956 |
|
| 957 |
e_button1 = gr.Button("変換")
|
| 958 |
|
| 959 |
e_text2 = gr.TextArea(show_label=True, label="JSON LINES")
|
| 960 |
e_text3 = gr.TextArea(show_label=True, label="ベクトル")
|
| 961 |
|
| 962 |
+
e_button1.click(f_googlesentenceencoder, inputs=[e_text1, e_checkbox1], outputs=[e_text2, e_text3])
|
| 963 |
pass
|
| 964 |
|
| 965 |
|