aokitools commited on
Commit ·
bb60b0f
1
Parent(s): 1af42bd
commit
Browse files- app.py +161 -75
- requirements.txt +3 -0
app.py
CHANGED
|
@@ -260,59 +260,6 @@ def f_hash(e_text1):
|
|
| 260 |
|
| 261 |
# // ---------------------------------------------- // #
|
| 262 |
|
| 263 |
-
def f_janome(e_text1):
|
| 264 |
-
result = {}
|
| 265 |
-
result["output1"] = ""
|
| 266 |
-
result["output2"] = ""
|
| 267 |
-
try:
|
| 268 |
-
b_sort1 = False
|
| 269 |
-
if e_radio1 == "降順":
|
| 270 |
-
b_sort1 = True
|
| 271 |
-
pass
|
| 272 |
-
|
| 273 |
-
s1 = e_text1
|
| 274 |
-
s1 = " ".join(s1.split())[:10000]
|
| 275 |
-
|
| 276 |
-
l2 = []
|
| 277 |
-
l3 = []
|
| 278 |
-
|
| 279 |
-
from janome.tokenizer import Tokenizer
|
| 280 |
-
tokenizer = Tokenizer()
|
| 281 |
-
for token in tokenizer.tokenize(s1):
|
| 282 |
-
d1 = {}
|
| 283 |
-
d1["token"] = "{0}".format(token.surface)
|
| 284 |
-
d1["label"] = "{0}".format(token.part_of_speech.split(",")[0])
|
| 285 |
-
|
| 286 |
-
s3 = "{0}".format(token.reading)
|
| 287 |
-
|
| 288 |
-
if s3 == "*":
|
| 289 |
-
s3 = d1["token"]
|
| 290 |
-
pass
|
| 291 |
-
|
| 292 |
-
d1["reading"] = s3
|
| 293 |
-
|
| 294 |
-
import json
|
| 295 |
-
s2 = json.dumps(d1, ensure_ascii=False)
|
| 296 |
-
|
| 297 |
-
l2.append(s2)
|
| 298 |
-
l3.append(d1["token"])
|
| 299 |
-
pass
|
| 300 |
-
|
| 301 |
-
result["output1"] = "\n".join(l2)
|
| 302 |
-
result["output2"] = " ".join(l3)
|
| 303 |
-
pass
|
| 304 |
-
except Exception as e:
|
| 305 |
-
result["output1"] = "ERROR: {0}".format(e)
|
| 306 |
-
|
| 307 |
-
import traceback
|
| 308 |
-
print(traceback.format_exc())
|
| 309 |
-
pass
|
| 310 |
-
|
| 311 |
-
return (result["output1"], result["output2"])
|
| 312 |
-
pass
|
| 313 |
-
|
| 314 |
-
# // ---------------------------------------------- // #
|
| 315 |
-
|
| 316 |
def f_generatepassword(e_number1, e_checkbox1, e_checkbox2, e_checkbox3, e_checkbox4, e_slider1):
|
| 317 |
|
| 318 |
try:
|
|
@@ -457,6 +404,130 @@ def f_formatunicode(e_text1, e_radio1):
|
|
| 457 |
|
| 458 |
# // ---------------------------------------------- // #
|
| 459 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 460 |
def f_tsne(e_text1, e_checkbox1, e_radio1, e_radio2):
|
| 461 |
result = {}
|
| 462 |
result["output1"] = e_text1
|
|
@@ -735,6 +806,35 @@ with gr.Blocks() as sample01:
|
|
| 735 |
pass
|
| 736 |
pass
|
| 737 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 738 |
with gr.Tab("JSON整形"):
|
| 739 |
e_text1 = gr.TextArea(show_label=True, label="JSON LINES")
|
| 740 |
e_text2 = gr.TextArea(show_label=True, label="JSON")
|
|
@@ -783,6 +883,7 @@ with gr.Blocks() as sample01:
|
|
| 783 |
pass
|
| 784 |
pass
|
| 785 |
|
|
|
|
| 786 |
with gr.Tab("並べ替え/重複排除"):
|
| 787 |
e_text1 = gr.TextArea(show_label=True, label="TEXT")
|
| 788 |
e_checkbox1 = gr.Checkbox(label="重複排除")
|
|
@@ -832,32 +933,15 @@ with gr.Blocks() as sample01:
|
|
| 832 |
pass
|
| 833 |
|
| 834 |
|
| 835 |
-
with gr.Tab("
|
| 836 |
e_text1 = gr.TextArea(show_label=True, label="TEXT")
|
| 837 |
|
| 838 |
-
|
| 839 |
-
e_text3 = gr.Textbox(show_label=True, label="SHA1")
|
| 840 |
-
e_text4 = gr.Textbox(show_label=True, label="SHA256")
|
| 841 |
-
e_text5 = gr.Textbox(show_label=True, label="SHA512")
|
| 842 |
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
e_button1.click(f_hash, inputs=[e_text1], outputs=[e_text2, e_text3, e_text4, e_text5])
|
| 846 |
-
pass
|
| 847 |
-
pass
|
| 848 |
-
|
| 849 |
-
|
| 850 |
-
with gr.Tab("base64"):
|
| 851 |
-
e_text1 = gr.TextArea(show_label=True, label="TEXT")
|
| 852 |
-
e_text2 = gr.TextArea(show_label=True, label="BASE64")
|
| 853 |
|
| 854 |
-
|
| 855 |
-
e_button1 = gr.Button("エンコード text >> base64")
|
| 856 |
-
e_button1.click(f_base64_encode, inputs=[e_text1], outputs=[e_text2])
|
| 857 |
-
|
| 858 |
-
e_button1 = gr.Button("デコード base64 >> text")
|
| 859 |
-
e_button1.click(f_base64_decode, inputs=[e_text2], outputs=[e_text1])
|
| 860 |
-
pass
|
| 861 |
pass
|
| 862 |
|
| 863 |
|
|
@@ -876,7 +960,9 @@ with gr.Blocks() as sample01:
|
|
| 876 |
e_checkbox1 = gr.Checkbox(label="1カラム目をラベルとして設定")
|
| 877 |
e_radio1 = gr.Radio(["2D", "3D"], value="2D", label="dimension")
|
| 878 |
e_radio2 = gr.Radio(["TSNE", "UMAP"], value="TSNE", label="algorithm")
|
|
|
|
| 879 |
e_button1 = gr.Button("プロット")
|
|
|
|
| 880 |
e_plot1 = gr.Plot(show_label=True, label="プロット")
|
| 881 |
e_plot2 = gr.Plot(show_label=True, label="クラスタ数の推定")
|
| 882 |
e_text2 = gr.TextArea(show_label=True, label="次元削減後のベクトル")
|
|
|
|
| 260 |
|
| 261 |
# // ---------------------------------------------- // #
|
| 262 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
def f_generatepassword(e_number1, e_checkbox1, e_checkbox2, e_checkbox3, e_checkbox4, e_slider1):
|
| 264 |
|
| 265 |
try:
|
|
|
|
| 404 |
|
| 405 |
# // ---------------------------------------------- // #
|
| 406 |
|
| 407 |
+
def f_janome(e_text1):
|
| 408 |
+
result = {}
|
| 409 |
+
result["output1"] = ""
|
| 410 |
+
result["output2"] = ""
|
| 411 |
+
try:
|
| 412 |
+
b_sort1 = False
|
| 413 |
+
if e_radio1 == "降順":
|
| 414 |
+
b_sort1 = True
|
| 415 |
+
pass
|
| 416 |
+
|
| 417 |
+
s1 = e_text1
|
| 418 |
+
s1 = " ".join(s1.split())[:10000]
|
| 419 |
+
|
| 420 |
+
l2 = []
|
| 421 |
+
l3 = []
|
| 422 |
+
|
| 423 |
+
from janome.tokenizer import Tokenizer
|
| 424 |
+
tokenizer = Tokenizer()
|
| 425 |
+
for token in tokenizer.tokenize(s1):
|
| 426 |
+
d1 = {}
|
| 427 |
+
d1["token"] = "{0}".format(token.surface)
|
| 428 |
+
d1["label"] = "{0}".format(token.part_of_speech.split(",")[0])
|
| 429 |
+
|
| 430 |
+
s3 = "{0}".format(token.reading)
|
| 431 |
+
|
| 432 |
+
if s3 == "*":
|
| 433 |
+
s3 = d1["token"]
|
| 434 |
+
pass
|
| 435 |
+
|
| 436 |
+
d1["reading"] = s3
|
| 437 |
+
|
| 438 |
+
import json
|
| 439 |
+
s2 = json.dumps(d1, ensure_ascii=False)
|
| 440 |
+
|
| 441 |
+
l2.append(s2)
|
| 442 |
+
l3.append(d1["token"])
|
| 443 |
+
pass
|
| 444 |
+
|
| 445 |
+
result["output1"] = "\n".join(l2)
|
| 446 |
+
result["output2"] = " ".join(l3)
|
| 447 |
+
pass
|
| 448 |
+
except Exception as e:
|
| 449 |
+
result["output1"] = "ERROR: {0}".format(e)
|
| 450 |
+
|
| 451 |
+
import traceback
|
| 452 |
+
print(traceback.format_exc())
|
| 453 |
+
pass
|
| 454 |
+
|
| 455 |
+
return (result["output1"], result["output2"])
|
| 456 |
+
pass
|
| 457 |
+
|
| 458 |
+
# // ---------------------------------------------- // #
|
| 459 |
+
|
| 460 |
+
global_google_encoder = None
|
| 461 |
+
|
| 462 |
+
def f_googlesentenceencoder(e_text1):
|
| 463 |
+
result = {}
|
| 464 |
+
result["output1"] = ""
|
| 465 |
+
result["output2"] = ""
|
| 466 |
+
try:
|
| 467 |
+
|
| 468 |
+
s1 = e_text1
|
| 469 |
+
|
| 470 |
+
list1 = []
|
| 471 |
+
for i1 in s1.splitlines()[:1000]:
|
| 472 |
+
list1.append(i1.strip())
|
| 473 |
+
pass
|
| 474 |
+
|
| 475 |
+
global global_google_encoder
|
| 476 |
+
if global_google_encoder is None:
|
| 477 |
+
import tensorflow_hub
|
| 478 |
+
global_google_encoder = tensorflow_hub.load("https://tfhub.dev/google/universal-sentence-encoder/4")
|
| 479 |
+
pass
|
| 480 |
+
|
| 481 |
+
import tensorflow
|
| 482 |
+
import tensorflow_text
|
| 483 |
+
vectors = None
|
| 484 |
+
|
| 485 |
+
with tensorflow.device("/CPU:0"):
|
| 486 |
+
vectors = global_google_encoder(list1)
|
| 487 |
+
pass
|
| 488 |
+
|
| 489 |
+
list_text1 = []
|
| 490 |
+
list_vector1 = []
|
| 491 |
+
|
| 492 |
+
for i1 in range(len(list1)):
|
| 493 |
+
import io
|
| 494 |
+
buf = io.StringIO()
|
| 495 |
+
|
| 496 |
+
import numpy
|
| 497 |
+
numpy.savetxt(buf, vectors[i1])
|
| 498 |
+
|
| 499 |
+
s2 = "\t".join(buf.getvalue().split())
|
| 500 |
+
d1 = {}
|
| 501 |
+
d1["text"] = list1[i1]
|
| 502 |
+
d1["vector"] = s2
|
| 503 |
+
|
| 504 |
+
import json
|
| 505 |
+
s3 = json.dumps(d1, ensure_ascii=False)
|
| 506 |
+
list_vector1.append(s3)
|
| 507 |
+
|
| 508 |
+
s4 = "{0:08}\t{1}".format(i1, s2)
|
| 509 |
+
list_text1.append(s4)
|
| 510 |
+
pass
|
| 511 |
+
|
| 512 |
+
if len(list_vector1) > 0:
|
| 513 |
+
result["output1"] = "\n".join(list_vector1)
|
| 514 |
+
pass
|
| 515 |
+
|
| 516 |
+
if len(list_text1) > 0:
|
| 517 |
+
result["output2"] = "\n".join(list_text1)
|
| 518 |
+
pass
|
| 519 |
+
pass
|
| 520 |
+
except Exception as e:
|
| 521 |
+
result["output1"] = "ERROR: {0}".format(e)
|
| 522 |
+
|
| 523 |
+
import traceback
|
| 524 |
+
print(traceback.format_exc())
|
| 525 |
+
pass
|
| 526 |
+
|
| 527 |
+
return (result["output1"], result["output2"])
|
| 528 |
+
pass
|
| 529 |
+
# // ---------------------------------------------- // #
|
| 530 |
+
|
| 531 |
def f_tsne(e_text1, e_checkbox1, e_radio1, e_radio2):
|
| 532 |
result = {}
|
| 533 |
result["output1"] = e_text1
|
|
|
|
| 806 |
pass
|
| 807 |
pass
|
| 808 |
|
| 809 |
+
with gr.Tab("hash"):
|
| 810 |
+
e_text1 = gr.TextArea(show_label=True, label="TEXT")
|
| 811 |
+
|
| 812 |
+
e_text2 = gr.Textbox(show_label=True, label="MD5")
|
| 813 |
+
e_text3 = gr.Textbox(show_label=True, label="SHA1")
|
| 814 |
+
e_text4 = gr.Textbox(show_label=True, label="SHA256")
|
| 815 |
+
e_text5 = gr.Textbox(show_label=True, label="SHA512")
|
| 816 |
+
|
| 817 |
+
with gr.Row():
|
| 818 |
+
e_button1 = gr.Button("hashを計算")
|
| 819 |
+
e_button1.click(f_hash, inputs=[e_text1], outputs=[e_text2, e_text3, e_text4, e_text5])
|
| 820 |
+
pass
|
| 821 |
+
pass
|
| 822 |
+
|
| 823 |
+
|
| 824 |
+
with gr.Tab("base64"):
|
| 825 |
+
e_text1 = gr.TextArea(show_label=True, label="TEXT")
|
| 826 |
+
e_text2 = gr.TextArea(show_label=True, label="BASE64")
|
| 827 |
+
|
| 828 |
+
with gr.Row():
|
| 829 |
+
e_button1 = gr.Button("エンコード text >> base64")
|
| 830 |
+
e_button1.click(f_base64_encode, inputs=[e_text1], outputs=[e_text2])
|
| 831 |
+
|
| 832 |
+
e_button1 = gr.Button("デコード base64 >> text")
|
| 833 |
+
e_button1.click(f_base64_decode, inputs=[e_text2], outputs=[e_text1])
|
| 834 |
+
pass
|
| 835 |
+
pass
|
| 836 |
+
|
| 837 |
+
|
| 838 |
with gr.Tab("JSON整形"):
|
| 839 |
e_text1 = gr.TextArea(show_label=True, label="JSON LINES")
|
| 840 |
e_text2 = gr.TextArea(show_label=True, label="JSON")
|
|
|
|
| 883 |
pass
|
| 884 |
pass
|
| 885 |
|
| 886 |
+
|
| 887 |
with gr.Tab("並べ替え/重複排除"):
|
| 888 |
e_text1 = gr.TextArea(show_label=True, label="TEXT")
|
| 889 |
e_checkbox1 = gr.Checkbox(label="重複排除")
|
|
|
|
| 933 |
pass
|
| 934 |
|
| 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 |
|
|
|
|
| 960 |
e_checkbox1 = gr.Checkbox(label="1カラム目をラベルとして設定")
|
| 961 |
e_radio1 = gr.Radio(["2D", "3D"], value="2D", label="dimension")
|
| 962 |
e_radio2 = gr.Radio(["TSNE", "UMAP"], value="TSNE", label="algorithm")
|
| 963 |
+
|
| 964 |
e_button1 = gr.Button("プロット")
|
| 965 |
+
|
| 966 |
e_plot1 = gr.Plot(show_label=True, label="プロット")
|
| 967 |
e_plot2 = gr.Plot(show_label=True, label="クラスタ数の推定")
|
| 968 |
e_text2 = gr.TextArea(show_label=True, label="次元削減後のベクトル")
|
requirements.txt
CHANGED
|
@@ -8,6 +8,9 @@ numpy
|
|
| 8 |
sklearn
|
| 9 |
umap-learn
|
| 10 |
scipy
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
|
|
|
|
| 8 |
sklearn
|
| 9 |
umap-learn
|
| 10 |
scipy
|
| 11 |
+
tensorflow
|
| 12 |
+
tensorflow_hub
|
| 13 |
+
tensorflow_text
|
| 14 |
|
| 15 |
|
| 16 |
|