aokitools commited on
Commit
81665dc
·
1 Parent(s): be85558
Files changed (1) hide show
  1. app.py +88 -33
app.py CHANGED
@@ -3,8 +3,9 @@ print("START")
3
 
4
  # // ---------------------------------------------- // #
5
 
6
- def f_base64_encode(s1):
7
  try:
 
8
  import base64
9
  result = base64.b64encode(s1.encode()).decode()
10
  pass
@@ -18,8 +19,9 @@ def f_base64_encode(s1):
18
  return result
19
  pass
20
 
21
- def f_base64_decode(s1):
22
  try:
 
23
  import base64
24
  result = base64.b64decode(s1.encode()).decode()
25
  pass
@@ -35,8 +37,9 @@ def f_base64_decode(s1):
35
 
36
  # // ---------------------------------------------- // #
37
 
38
- def f_json2jsonlines(s1):
39
  try:
 
40
  import json
41
  d1 = json.loads(s1)
42
  result = json.dumps(d1, ensure_ascii=False)
@@ -51,8 +54,9 @@ def f_json2jsonlines(s1):
51
  return result
52
  pass
53
 
54
- def f_jsonlines2json(s1):
55
  try:
 
56
  l1 = s1.splitlines()
57
  l2 = []
58
  for i1 in l1:
@@ -88,13 +92,14 @@ def f_jsonlines2json(s1):
88
 
89
  # // ---------------------------------------------- // #
90
 
91
- def f_sort(s1, e_radio1, e_checkbox1, e_checkbox2):
92
  try:
93
  b_sort1 = False
94
  if e_radio1 == "降順":
95
  b_sort1 = True
96
  pass
97
 
 
98
  l1 = s1.splitlines()
99
 
100
  if e_checkbox2:
@@ -119,11 +124,48 @@ def f_sort(s1, e_radio1, e_checkbox1, e_checkbox2):
119
  return result
120
  pass
121
 
 
122
  # // ---------------------------------------------- // #
123
 
124
- def f_hash(s1):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  result = {}
126
 
 
 
127
  try:
128
  import hashlib
129
 
@@ -135,7 +177,7 @@ def f_hash(s1):
135
  import traceback
136
  print(traceback.format_exc())
137
  pass
138
- result["e_output1"] = s2
139
 
140
  try:
141
  import hashlib
@@ -148,7 +190,7 @@ def f_hash(s1):
148
  import traceback
149
  print(traceback.format_exc())
150
  pass
151
- result["e_output2"] = s2
152
 
153
  try:
154
  import hashlib
@@ -161,7 +203,7 @@ def f_hash(s1):
161
  import traceback
162
  print(traceback.format_exc())
163
  pass
164
- result["e_output3"] = s2
165
 
166
  try:
167
  import hashlib
@@ -174,14 +216,14 @@ def f_hash(s1):
174
  import traceback
175
  print(traceback.format_exc())
176
  pass
177
- result["e_output4"] = s2
178
 
179
- return (result["e_output1"], result["e_output2"], result["e_output3"], result["e_output4"])
180
  pass
181
 
182
  # // ---------------------------------------------- // #
183
 
184
- def f_janome(s1):
185
 
186
  try:
187
  b_sort1 = False
@@ -189,6 +231,7 @@ def f_janome(s1):
189
  b_sort1 = True
190
  pass
191
 
 
192
  l1 = s1.splitlines()
193
  l2 = []
194
 
@@ -297,76 +340,88 @@ with gr.Blocks() as sample01:
297
 
298
  e_slider1 = gr.Slider(value=100, minimum=100, maximum=10000, step=100, label="生成する数", interactive=True)
299
 
300
- e_output = gr.TextArea(show_label=True, label="TEXT")
301
 
302
  with gr.Row():
303
  e_button1 = gr.Button("生成")
304
- e_button1.click(f_generatepassword, inputs=[e_number1, e_checkbox1, e_checkbox2, e_checkbox3, e_checkbox4, e_slider1], outputs=[e_output])
305
  pass
306
  pass
307
 
308
  with gr.Tab("JSON整形"):
309
- e_input = gr.TextArea(show_label=True, label="JSON LINES")
310
- e_output = gr.TextArea(show_label=True, label="JSON")
311
 
312
  with gr.Row():
313
  e_button1 = gr.Button("JSON に変換")
314
- e_button1.click(f_jsonlines2json, inputs=[e_input], outputs=[e_output])
315
 
316
  e_button1 = gr.Button("JSON LINES に変換")
317
- e_button1.click(f_json2jsonlines, inputs=[e_output], outputs=[e_input])
318
  pass
319
  pass
320
 
321
  with gr.Tab("並べ替え/重複排除"):
322
- e_input = gr.TextArea(show_label=True, label="TEXT")
323
  e_checkbox1 = gr.Checkbox(label="重複排除")
324
  e_checkbox2 = gr.Checkbox(label="前後の空白を除去")
325
  e_radio1 = gr.Radio(["昇順", "降順"], value="昇順", label="sort order")
326
 
327
  with gr.Row():
328
  e_button1 = gr.Button("並べ替え")
329
- e_button1.click(f_sort, inputs=[e_input, e_radio1, e_checkbox1, e_checkbox2], outputs=[e_input])
 
 
 
 
 
 
 
 
 
 
 
 
330
  pass
331
  pass
332
 
333
 
334
  with gr.Tab("形態素解析"):
335
- e_input = gr.TextArea(show_label=True, label="TEXT")
336
- e_output = gr.TextArea(show_label=True, label="JSON")
337
 
338
  with gr.Row():
339
  e_button1 = gr.Button("形態素解析")
340
- e_button1.click(f_janome, inputs=[e_input], outputs=[e_output])
341
  pass
342
  pass
343
 
344
 
345
  with gr.Tab("hash"):
346
- e_input = gr.TextArea(show_label=True, label="TEXT")
347
 
348
- e_output1 = gr.Textbox(show_label=True, label="MD5")
349
- e_output2 = gr.Textbox(show_label=True, label="SHA1")
350
- e_output3 = gr.Textbox(show_label=True, label="SHA256")
351
- e_output4 = gr.Textbox(show_label=True, label="SHA512")
352
 
353
  with gr.Row():
354
  e_button1 = gr.Button("hashを計算")
355
- e_button1.click(f_hash, inputs=[e_input], outputs=[e_output1, e_output2, e_output3, e_output4])
356
  pass
357
  pass
358
 
359
 
360
  with gr.Tab("base64"):
361
- e_input = gr.TextArea(show_label=True, label="TEXT")
362
- e_output = gr.TextArea(show_label=True, label="BASE64")
363
 
364
  with gr.Row():
365
  e_button1 = gr.Button("エンコード text >> base64")
366
- e_button1.click(f_base64_encode, inputs=[e_input], outputs=[e_output])
367
 
368
  e_button1 = gr.Button("デコード base64 >> text")
369
- e_button1.click(f_base64_decode, inputs=[e_output], outputs=[e_input])
370
  pass
371
  pass
372
 
 
3
 
4
  # // ---------------------------------------------- // #
5
 
6
+ def f_base64_encode(e_text1):
7
  try:
8
+ s1 = e_text1
9
  import base64
10
  result = base64.b64encode(s1.encode()).decode()
11
  pass
 
19
  return result
20
  pass
21
 
22
+ def f_base64_decode(e_text1):
23
  try:
24
+ s1 = e_text1
25
  import base64
26
  result = base64.b64decode(s1.encode()).decode()
27
  pass
 
37
 
38
  # // ---------------------------------------------- // #
39
 
40
+ def f_json2jsonlines(e_text1):
41
  try:
42
+ s1 = e_text1
43
  import json
44
  d1 = json.loads(s1)
45
  result = json.dumps(d1, ensure_ascii=False)
 
54
  return result
55
  pass
56
 
57
+ def f_jsonlines2json(e_text1):
58
  try:
59
+ s1 = e_text1
60
  l1 = s1.splitlines()
61
  l2 = []
62
  for i1 in l1:
 
92
 
93
  # // ---------------------------------------------- // #
94
 
95
+ def f_sort(e_text1, e_radio1, e_checkbox1, e_checkbox2):
96
  try:
97
  b_sort1 = False
98
  if e_radio1 == "降順":
99
  b_sort1 = True
100
  pass
101
 
102
+ s1 = e_text1
103
  l1 = s1.splitlines()
104
 
105
  if e_checkbox2:
 
124
  return result
125
  pass
126
 
127
+
128
  # // ---------------------------------------------- // #
129
 
130
+ def f_wordcount(e_text1):
131
+ try:
132
+ b_sort1 = False
133
+ if e_radio1 == "降順":
134
+ b_sort1 = True
135
+ pass
136
+
137
+ s1 = e_text1
138
+ l1 = s1.splitlines()
139
+
140
+ result = {}
141
+ result["output1"] = "{0}".format(len(s1))
142
+
143
+ l2 = []
144
+ for i1 in l1:
145
+ s2 = "{0}".format(len(i1))
146
+ l2.append(s2)
147
+ pass
148
+
149
+ result["output2"] = "\n".join(l2)
150
+ pass
151
+ except Exception as e:
152
+ result = "ERROR: {0}".format(e)
153
+
154
+ import traceback
155
+ print(traceback.format_exc())
156
+ pass
157
+
158
+ return (result["output1"], result["output2"])
159
+ pass
160
+
161
+
162
+ # // ---------------------------------------------- // #
163
+
164
+ def f_hash(e_text1):
165
  result = {}
166
 
167
+ s1 = e_text1
168
+
169
  try:
170
  import hashlib
171
 
 
177
  import traceback
178
  print(traceback.format_exc())
179
  pass
180
+ result["output1"] = s2
181
 
182
  try:
183
  import hashlib
 
190
  import traceback
191
  print(traceback.format_exc())
192
  pass
193
+ result["output2"] = s2
194
 
195
  try:
196
  import hashlib
 
203
  import traceback
204
  print(traceback.format_exc())
205
  pass
206
+ result["output3"] = s2
207
 
208
  try:
209
  import hashlib
 
216
  import traceback
217
  print(traceback.format_exc())
218
  pass
219
+ result["output4"] = s2
220
 
221
+ return (result["output1"], result["output2"], result["output3"], result["output4"])
222
  pass
223
 
224
  # // ---------------------------------------------- // #
225
 
226
+ def f_janome(e_text1):
227
 
228
  try:
229
  b_sort1 = False
 
231
  b_sort1 = True
232
  pass
233
 
234
+ s1 = e_text1
235
  l1 = s1.splitlines()
236
  l2 = []
237
 
 
340
 
341
  e_slider1 = gr.Slider(value=100, minimum=100, maximum=10000, step=100, label="生成する数", interactive=True)
342
 
343
+ e_text1 = gr.TextArea(show_label=True, label="TEXT")
344
 
345
  with gr.Row():
346
  e_button1 = gr.Button("生成")
347
+ e_button1.click(f_generatepassword, inputs=[e_number1, e_checkbox1, e_checkbox2, e_checkbox3, e_checkbox4, e_slider1], outputs=[e_text1])
348
  pass
349
  pass
350
 
351
  with gr.Tab("JSON整形"):
352
+ e_text1 = gr.TextArea(show_label=True, label="JSON LINES")
353
+ e_text2 = gr.TextArea(show_label=True, label="JSON")
354
 
355
  with gr.Row():
356
  e_button1 = gr.Button("JSON に変換")
357
+ e_button1.click(f_jsonlines2json, inputs=[e_text1], outputs=[e_text2])
358
 
359
  e_button1 = gr.Button("JSON LINES に変換")
360
+ e_button1.click(f_json2jsonlines, inputs=[e_text2], outputs=[e_text1])
361
  pass
362
  pass
363
 
364
  with gr.Tab("並べ替え/重複排除"):
365
+ e_text1 = gr.TextArea(show_label=True, label="TEXT")
366
  e_checkbox1 = gr.Checkbox(label="重複排除")
367
  e_checkbox2 = gr.Checkbox(label="前後の空白を除去")
368
  e_radio1 = gr.Radio(["昇順", "降順"], value="昇順", label="sort order")
369
 
370
  with gr.Row():
371
  e_button1 = gr.Button("並べ替え")
372
+ e_button1.click(f_sort, inputs=[e_text1, e_radio1, e_checkbox1, e_checkbox2], outputs=[e_text1])
373
+ pass
374
+ pass
375
+
376
+
377
+ with gr.Tab("文字数カウント"):
378
+ e_text1 = gr.TextArea(show_label=True, label="TEXT")
379
+ e_text2 = gr.Textbox(show_label=True, label="全体の文字数(改行コードを含む)")
380
+ e_text3 = gr.Textbox(show_label=True, label="1行ごとの文字数(改行コードを除く)")
381
+
382
+ with gr.Row():
383
+ e_button1 = gr.Button("文字数カウント")
384
+ e_button1.click(f_wordcount, inputs=[e_text1], outputs=[e_text2, e_text3])
385
  pass
386
  pass
387
 
388
 
389
  with gr.Tab("形態素解析"):
390
+ e_text1 = gr.TextArea(show_label=True, label="TEXT")
391
+ e_text2 = gr.TextArea(show_label=True, label="JSON")
392
 
393
  with gr.Row():
394
  e_button1 = gr.Button("形態素解析")
395
+ e_button1.click(f_janome, inputs=[e_text1], outputs=[e_text2])
396
  pass
397
  pass
398
 
399
 
400
  with gr.Tab("hash"):
401
+ e_text1 = gr.TextArea(show_label=True, label="TEXT")
402
 
403
+ e_text2 = gr.Textbox(show_label=True, label="MD5")
404
+ e_text3 = gr.Textbox(show_label=True, label="SHA1")
405
+ e_text4 = gr.Textbox(show_label=True, label="SHA256")
406
+ e_text5 = gr.Textbox(show_label=True, label="SHA512")
407
 
408
  with gr.Row():
409
  e_button1 = gr.Button("hashを計算")
410
+ e_button1.click(f_hash, inputs=[e_text1], outputs=[e_text2, e_text3, e_text4, e_text5])
411
  pass
412
  pass
413
 
414
 
415
  with gr.Tab("base64"):
416
+ e_text1 = gr.TextArea(show_label=True, label="TEXT")
417
+ e_text2 = gr.TextArea(show_label=True, label="BASE64")
418
 
419
  with gr.Row():
420
  e_button1 = gr.Button("エンコード text >> base64")
421
+ e_button1.click(f_base64_encode, inputs=[e_text1], outputs=[e_text2])
422
 
423
  e_button1 = gr.Button("デコード base64 >> text")
424
+ e_button1.click(f_base64_decode, inputs=[e_text2], outputs=[e_text1])
425
  pass
426
  pass
427