aokitools commited on
Commit
46d5ba7
·
1 Parent(s): c446a62
Files changed (2) hide show
  1. app.py +87 -35
  2. requirements.txt +1 -0
app.py CHANGED
@@ -175,7 +175,8 @@ def f_wordcount(e_text1):
175
  l1 = s1.splitlines()
176
 
177
  result = {}
178
- result["output1"] = "{0}".format(len(s1))
 
179
 
180
  l2 = []
181
  for i1 in l1:
@@ -183,7 +184,7 @@ def f_wordcount(e_text1):
183
  l2.append(s2)
184
  pass
185
 
186
- result["output2"] = "\n".join(l2)
187
  pass
188
  except Exception as e:
189
  result = "ERROR: {0}".format(e)
@@ -192,7 +193,7 @@ def f_wordcount(e_text1):
192
  print(traceback.format_exc())
193
  pass
194
 
195
- return (result["output1"], result["output2"])
196
  pass
197
 
198
 
@@ -313,34 +314,6 @@ def f_generatepassword(e_number1, e_checkbox1, e_checkbox2, e_checkbox3, e_check
313
 
314
  # // ---------------------------------------------- // #
315
 
316
- def f_formattext(e_text1):
317
-
318
- try:
319
- s1 = e_text1
320
-
321
- import bunkai
322
- from bunkai import Bunkai
323
- bunkai = Bunkai()
324
-
325
- l1 = []
326
- for token in bunkai(e_text1):
327
- l1.append(token.strip())
328
- pass
329
-
330
- result = "\n".join(l1)
331
- pass
332
- except Exception as e:
333
- result = "ERROR: {0}".format(e)
334
-
335
- import traceback
336
- print(traceback.format_exc())
337
- pass
338
-
339
- return result
340
- pass
341
-
342
- # // ---------------------------------------------- // #
343
-
344
  def f_formathtml(e_text1):
345
 
346
  try:
@@ -432,6 +405,74 @@ def f_formatunicode(e_text1, e_radio1):
432
 
433
  # // ---------------------------------------------- // #
434
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
435
  def f_janome(e_text1):
436
  result = {}
437
  result["output1"] = ""
@@ -978,10 +1019,20 @@ with gr.Blocks() as sample01:
978
 
979
  with gr.Row():
980
  e_button1 = gr.Button("日本語整形")
981
- e_button1.click(f_formattext, inputs=[e_text1], outputs=[e_text1])
982
  pass
983
  pass
984
 
 
 
 
 
 
 
 
 
 
 
985
  with gr.Tab("XML整形"):
986
  e_text1 = gr.TextArea(show_label=True, label="XML")
987
 
@@ -1008,12 +1059,13 @@ with gr.Blocks() as sample01:
1008
 
1009
  with gr.Tab("文字数カウント"):
1010
  e_text1 = gr.TextArea(show_label=True, label="TEXT")
1011
- e_text2 = gr.Textbox(show_label=True, label="全体の文字数(改行コードを含む)")
1012
- e_text3 = gr.Textbox(show_label=True, label="1行ごとの文字数(改行コードを除く)")
 
1013
 
1014
  with gr.Row():
1015
  e_button1 = gr.Button("文字数カウント")
1016
- e_button1.click(f_wordcount, inputs=[e_text1], outputs=[e_text2, e_text3])
1017
  pass
1018
  pass
1019
 
 
175
  l1 = s1.splitlines()
176
 
177
  result = {}
178
+ result["output1"] = "{0}".format(len(l1))
179
+ result["output2"] = "{0}".format(len(s1))
180
 
181
  l2 = []
182
  for i1 in l1:
 
184
  l2.append(s2)
185
  pass
186
 
187
+ result["output3"] = "\n".join(l2)
188
  pass
189
  except Exception as e:
190
  result = "ERROR: {0}".format(e)
 
193
  print(traceback.format_exc())
194
  pass
195
 
196
+ return (result["output1"], result["output2"], result["output3"])
197
  pass
198
 
199
 
 
314
 
315
  # // ---------------------------------------------- // #
316
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
317
  def f_formathtml(e_text1):
318
 
319
  try:
 
405
 
406
  # // ---------------------------------------------- // #
407
 
408
+ def f_formattext_en(e_text1):
409
+ result = {}
410
+ result["output1"] = ""
411
+ result["output2"] = ""
412
+
413
+ try:
414
+ s1 = e_text1
415
+ s1 = " ".join(s1.split())
416
+
417
+ import nltk
418
+ from nltk.tokenize import sent_tokenize, word_tokenize
419
+
420
+ nltk.data.path.append("/opt/tmp_nltk")
421
+ nltk.download("punkt")
422
+
423
+ l1 = []
424
+ for token in sent_tokenize(s1):
425
+ l1.append(token.strip())
426
+ pass
427
+
428
+ s2 = "\n".join(l1)
429
+
430
+ import urllib.parse
431
+ s3 = "https://translate.google.co.jp/?sl=auto&text={0}".format(urllib.parse.quote_plus(s2[:3000]))
432
+
433
+ result["output1"] = s2
434
+ result["output2"] = s3
435
+ pass
436
+ except Exception as e:
437
+ result["output1"] = "ERROR: {0}".format(e)
438
+
439
+ import traceback
440
+ print(traceback.format_exc())
441
+ pass
442
+
443
+ return (result["output1"], result["output2"])
444
+ pass
445
+
446
+ # // ---------------------------------------------- // #
447
+
448
+ def f_formattext_ja(e_text1):
449
+
450
+ try:
451
+ s1 = e_text1
452
+
453
+ import bunkai
454
+ from bunkai import Bunkai
455
+ bunkai = Bunkai()
456
+
457
+ l1 = []
458
+ for token in bunkai(s1):
459
+ l1.append(token.strip())
460
+ pass
461
+
462
+ result = "\n".join(l1)
463
+ pass
464
+ except Exception as e:
465
+ result = "ERROR: {0}".format(e)
466
+
467
+ import traceback
468
+ print(traceback.format_exc())
469
+ pass
470
+
471
+ return result
472
+ pass
473
+
474
+ # // ---------------------------------------------- // #
475
+
476
  def f_janome(e_text1):
477
  result = {}
478
  result["output1"] = ""
 
1019
 
1020
  with gr.Row():
1021
  e_button1 = gr.Button("日本語整形")
1022
+ e_button1.click(f_formattext_ja, inputs=[e_text1], outputs=[e_text1])
1023
  pass
1024
  pass
1025
 
1026
+ with gr.Tab("英語整形"):
1027
+ e_text1 = gr.TextArea(show_label=True, label="TEXT")
1028
+ e_button1 = gr.Button("英語整形")
1029
+ e_text2 = gr.Textbox(show_label=True, label="Google Translate")
1030
+ e_button2 = gr.Button("翻訳")
1031
+
1032
+ e_button1.click(f_formattext_en, inputs=[e_text1], outputs=[e_text1, e_text2])
1033
+ e_button2.click(fn=None, inputs=[e_text2], _js="(e_text2) => {window.open(e_text2, '_blank', 'noreferrer')}")
1034
+ pass
1035
+
1036
  with gr.Tab("XML整形"):
1037
  e_text1 = gr.TextArea(show_label=True, label="XML")
1038
 
 
1059
 
1060
  with gr.Tab("文字数カウント"):
1061
  e_text1 = gr.TextArea(show_label=True, label="TEXT")
1062
+ e_text2 = gr.Textbox(show_label=True, label="行数")
1063
+ e_text3 = gr.Textbox(show_label=True, label="全体の文字数(改行コードを含む)")
1064
+ e_text4 = gr.Textbox(show_label=True, label="1行ごとの文字数(改行コードを除く)")
1065
 
1066
  with gr.Row():
1067
  e_button1 = gr.Button("文字数カウント")
1068
+ e_button1.click(f_wordcount, inputs=[e_text1], outputs=[e_text2, e_text3, e_text4])
1069
  pass
1070
  pass
1071
 
requirements.txt CHANGED
@@ -1,6 +1,7 @@
1
  tzlocal
2
  bunkai
3
  janome
 
4
  lxml
5
  jsbeautifier
6
  jaconv
 
1
  tzlocal
2
  bunkai
3
  janome
4
+ nltk
5
  lxml
6
  jsbeautifier
7
  jaconv