aokitools commited on
Commit ·
3b42ed4
1
Parent(s): 81665dc
commit
Browse files- app.py +71 -3
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -59,6 +59,7 @@ def f_jsonlines2json(e_text1):
|
|
| 59 |
s1 = e_text1
|
| 60 |
l1 = s1.splitlines()
|
| 61 |
l2 = []
|
|
|
|
| 62 |
for i1 in l1:
|
| 63 |
s2 = None
|
| 64 |
|
|
@@ -68,12 +69,14 @@ def f_jsonlines2json(e_text1):
|
|
| 68 |
s2 = json.dumps(d1, ensure_ascii=False, indent=2)
|
| 69 |
pass
|
| 70 |
except Exception as e:
|
| 71 |
-
s2 = "ERROR: {0}".format(e)
|
| 72 |
|
| 73 |
import traceback
|
| 74 |
print(traceback.format_exc())
|
| 75 |
pass
|
| 76 |
|
|
|
|
|
|
|
| 77 |
l2.append(s2)
|
| 78 |
pass
|
| 79 |
|
|
@@ -92,7 +95,7 @@ def f_jsonlines2json(e_text1):
|
|
| 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 == "降順":
|
|
@@ -106,6 +109,10 @@ def f_sort(e_text1, e_radio1, e_checkbox1, e_checkbox2):
|
|
| 106 |
l1 = map(lambda x: x.strip(), l1)
|
| 107 |
pass
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
if e_checkbox1:
|
| 110 |
l1 = list(set(l1))
|
| 111 |
pass
|
|
@@ -325,6 +332,48 @@ def f_generatepassword(e_number1, e_checkbox1, e_checkbox2, e_checkbox3, e_check
|
|
| 325 |
|
| 326 |
# // ---------------------------------------------- // #
|
| 327 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
import gradio as gr
|
| 329 |
|
| 330 |
with gr.Blocks() as sample01:
|
|
@@ -361,15 +410,34 @@ with gr.Blocks() as sample01:
|
|
| 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 |
|
|
|
|
| 59 |
s1 = e_text1
|
| 60 |
l1 = s1.splitlines()
|
| 61 |
l2 = []
|
| 62 |
+
index1 = 0
|
| 63 |
for i1 in l1:
|
| 64 |
s2 = None
|
| 65 |
|
|
|
|
| 69 |
s2 = json.dumps(d1, ensure_ascii=False, indent=2)
|
| 70 |
pass
|
| 71 |
except Exception as e:
|
| 72 |
+
s2 = "[LINE {1:,}] ERROR: {0}\n{2}".format(e, index1, i1)
|
| 73 |
|
| 74 |
import traceback
|
| 75 |
print(traceback.format_exc())
|
| 76 |
pass
|
| 77 |
|
| 78 |
+
index1 += 1
|
| 79 |
+
|
| 80 |
l2.append(s2)
|
| 81 |
pass
|
| 82 |
|
|
|
|
| 95 |
|
| 96 |
# // ---------------------------------------------- // #
|
| 97 |
|
| 98 |
+
def f_sort(e_text1, e_radio1, e_checkbox1, e_checkbox2, e_checkbox3):
|
| 99 |
try:
|
| 100 |
b_sort1 = False
|
| 101 |
if e_radio1 == "降順":
|
|
|
|
| 109 |
l1 = map(lambda x: x.strip(), l1)
|
| 110 |
pass
|
| 111 |
|
| 112 |
+
if e_checkbox3:
|
| 113 |
+
l1 = list(filter(lambda x: len(x.strip()) > 0, l1))
|
| 114 |
+
pass
|
| 115 |
+
|
| 116 |
if e_checkbox1:
|
| 117 |
l1 = list(set(l1))
|
| 118 |
pass
|
|
|
|
| 332 |
|
| 333 |
# // ---------------------------------------------- // #
|
| 334 |
|
| 335 |
+
def f_formathtml(e_text1):
|
| 336 |
+
|
| 337 |
+
try:
|
| 338 |
+
s1 = e_text1
|
| 339 |
+
|
| 340 |
+
from lxml import etree, html
|
| 341 |
+
tree1 = html.fromstring(s1)
|
| 342 |
+
result = etree.tostring(tree1, encoding="utf-8", pretty_print=True).strip().decode()
|
| 343 |
+
pass
|
| 344 |
+
except Exception as e:
|
| 345 |
+
result = "ERROR: {0}".format(e)
|
| 346 |
+
|
| 347 |
+
import traceback
|
| 348 |
+
print(traceback.format_exc())
|
| 349 |
+
pass
|
| 350 |
+
|
| 351 |
+
return result
|
| 352 |
+
pass
|
| 353 |
+
|
| 354 |
+
# // ---------------------------------------------- // #
|
| 355 |
+
|
| 356 |
+
def f_formatxml(e_text1):
|
| 357 |
+
|
| 358 |
+
try:
|
| 359 |
+
s1 = e_text1.encode()
|
| 360 |
+
|
| 361 |
+
from lxml import etree
|
| 362 |
+
parser = etree.XMLParser(remove_blank_text=True)
|
| 363 |
+
tree1 = etree.fromstring(s1, parser=parser)
|
| 364 |
+
result = etree.tostring(tree1, encoding="utf-8", pretty_print=True, xml_declaration=True).strip().decode()
|
| 365 |
+
pass
|
| 366 |
+
except Exception as e:
|
| 367 |
+
result = "ERROR: {0}".format(e)
|
| 368 |
+
|
| 369 |
+
import traceback
|
| 370 |
+
print(traceback.format_exc())
|
| 371 |
+
pass
|
| 372 |
+
|
| 373 |
+
return result
|
| 374 |
+
pass
|
| 375 |
+
# // ---------------------------------------------- // #
|
| 376 |
+
|
| 377 |
import gradio as gr
|
| 378 |
|
| 379 |
with gr.Blocks() as sample01:
|
|
|
|
| 410 |
pass
|
| 411 |
pass
|
| 412 |
|
| 413 |
+
with gr.Tab("HTML整形"):
|
| 414 |
+
e_text1 = gr.TextArea(show_label=True, label="HTML")
|
| 415 |
+
|
| 416 |
+
with gr.Row():
|
| 417 |
+
e_button1 = gr.Button("HTML整形")
|
| 418 |
+
e_button1.click(f_formathtml, inputs=[e_text1], outputs=[e_text1])
|
| 419 |
+
pass
|
| 420 |
+
pass
|
| 421 |
+
|
| 422 |
+
with gr.Tab("XML整形"):
|
| 423 |
+
e_text1 = gr.TextArea(show_label=True, label="XML")
|
| 424 |
+
|
| 425 |
+
with gr.Row():
|
| 426 |
+
e_button1 = gr.Button("XML整形")
|
| 427 |
+
e_button1.click(f_formatxml, inputs=[e_text1], outputs=[e_text1])
|
| 428 |
+
pass
|
| 429 |
+
pass
|
| 430 |
+
|
| 431 |
with gr.Tab("並べ替え/重複排除"):
|
| 432 |
e_text1 = gr.TextArea(show_label=True, label="TEXT")
|
| 433 |
e_checkbox1 = gr.Checkbox(label="重複排除")
|
| 434 |
e_checkbox2 = gr.Checkbox(label="前後の空白を除去")
|
| 435 |
+
e_checkbox3 = gr.Checkbox(label="空行除去")
|
| 436 |
e_radio1 = gr.Radio(["昇順", "降順"], value="昇順", label="sort order")
|
| 437 |
|
| 438 |
with gr.Row():
|
| 439 |
e_button1 = gr.Button("並べ替え")
|
| 440 |
+
e_button1.click(f_sort, inputs=[e_text1, e_radio1, e_checkbox1, e_checkbox2, e_checkbox3], outputs=[e_text1])
|
| 441 |
pass
|
| 442 |
pass
|
| 443 |
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
janome
|
|
|
|
|
|
| 1 |
janome
|
| 2 |
+
lxml
|