Spaces:
Running
Running
Update app.py
Browse files127 unmodified lines12812913013113213213313413513684 unmodified lines2212222232232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622633 unmodified lines26726826923827027127214 unmodified lines2872882892592902912922933 unmodified lines2972982992693003013023032 unmodified lines30630730827830931031131217 unmodified lines33033133230233333433533624 unmodified lines36136236333333436436536636733636833836937037137212 unmodified lines385386387357388389359390391392393127 unmodified lines elif tag in['replace', 'insert']: html_parts.append(f'<span style="background-color: #ffe066; font-weight: bold; padding: 2px; border-radius: 3px; color: #000;">{chunk}</span>') # โ
CSS์์ ์ฒ๋ฆฌํ๋ฏ๋ก HTML ํ๊ทธ ๋ด์ padding ๋ฑ์ ์ ๊ฑฐํ๊ณ id๋ง ๋จ๊น๋๋ค. โ
html_output = f''' <div id="prompter_output_div" style="line-height:1.8; font-size:{font_size}px; padding:20px; border:1px solid #ddd; border-radius:8px; background-color:#333; color:#fff; height: 500px; max-height: 500px; overflow-y: auto;"> <div id="prompter_output_div" style="font-size:{font_size}px;"> {"".join(html_parts)} </div> '''84 unmodified lines except Exception as e: return f"โ JSON ํ์ฑ ์๋ฌ: {e}"
# โ
์๋ณธ ์ฐฝ์ ๋์ด๋ฅผ ํ๋กฌํํฐ ์ฐฝ๊ณผ ๋์ผํ '500px'๋ก ๊ฐ์ ๊ณ ์ ํ๋ CSS โ
# โ
์์ชฝ ์ฐฝ์ ๋ด๋ถ ์ฌ๋ฐฑ(padding), ์ค๊ฐ๊ฒฉ(line-height), ํฐํธ ์ฒ๋ฆฌ ๋ฐฉ์์ ํฝ์
๋จ์๋ก ๋๊ฐ์ด ๋ง์ถ๋ ๋ง๋ฒ์ CSS โ
custom_css = """/* ์ผ์ชฝ ์๋ณธ ํ
์คํธ ์ฐฝ */#input_text_area textarea { height: 500px !important; max-height: 500px !important; overflow-y: auto !important; padding: 16px !important; line-height: 1.8 !important; box-sizing: border-box !important; white-space: pre-wrap !important; word-break: break-word !important;}
/* ์ค๋ฅธ์ชฝ ํ๋กฌํํฐ ๋ทฐ ์ฐฝ */#prompter_output_div { height: 500px !important; max-height: 500px !important; overflow-y: auto !important; padding: 16px !important; line-height: 1.8 !important; box-sizing: border-box !important; background-color: #333 !important; color: #fff !important; border: 1px solid #ddd !important; border-radius: 8px !important; font-family: inherit !important; /* ์ผ์ชฝ ์ฐฝ๊ณผ ๊ธ๊ผด ์๋ฒฝ ๋์ผํ */ white-space: pre-wrap !important; /* ์ค๋ฐ๊ฟ ๊ท์น ๋์ผํ */ word-break: break-word !important;}
/* ์ค๋ฅธ์ชฝ ๋ผ๋ฒจ ๊ฐ์ ๋์ด ๋ง์ถค (์ผ์ชฝ ๋ผ๋ฒจ๊ณผ ๊ณต๊ฐ ์ผ์น) */#prompter_label_space { font-size: var(--input-text-size); color: var(--body-text-color-subdued); margin-bottom: 8px; display: block;}"""
3 unmodified lines let ta1 = document.querySelector('#input_text_area textarea'); if(ta1) { ta1.style.fontSize = size + 'px'; ta1.style.lineHeight = '1.8'; } let ta2 = document.querySelector('#output_text_area textarea'); if(ta2) {14 unmodified lines let ta2 = document.querySelector('#output_text_area textarea'); let div3 = document.getElementById('prompter_output_div');
if (!ta1 || !ta2 || !div3) return; if (!ta1 || !div3) return;
if (target === ta1) { if (isSyncing1) { isSyncing1 = false; return; }3 unmodified lines isSyncing3 = true; let percentage = ta1.scrollTop / (ta1.scrollHeight - ta1.clientHeight); if (ta2.scrollHeight - ta2.clientHeight > 0) { if (ta2 && ta2.scrollHeight - ta2.clientHeight > 0) { ta2.scrollTop = percentage * (ta2.scrollHeight - ta2.clientHeight); } if (div3.scrollHeight - div3.clientHeight > 0) {2 unmodified lines } else if (target === ta2) { if (isSyncing2) { isSyncing2 = false; return; } if (ta2.scrollHeight - ta2.clientHeight <= 0) return; if (ta2 && ta2.scrollHeight - ta2.clientHeight <= 0) return; isSyncing1 = true; isSyncing3 = true;17 unmodified lines if (ta1.scrollHeight - ta1.clientHeight > 0) { ta1.scrollTop = percentage * (ta1.scrollHeight - ta1.clientHeight); } if (ta2.scrollHeight - ta2.clientHeight > 0) { if (ta2 && ta2.scrollHeight - ta2.clientHeight > 0) { ta2.scrollTop = percentage * (ta2.scrollHeight - ta2.clientHeight); } }24 unmodified lines btn_clr = gr.Button("๐๏ธ ๋๋ณธ ์ด๊ธฐํ", variant="stop") with gr.Column(): # โ
๋ณ๊ฒฝ๋ ๋ถ๋ถ: ๊น๋ง์ ํ๋กฌํํฐ ๋ทฐ๋ฅผ ๋งจ ์๋ก ์ฌ๋ ธ์ต๋๋ค! โ
output_html = gr.HTML(label="๐บ ํ๋กฌํํฐ ๋ทฐ (๋ณ๊ฒฝ์ ํ์ธ)") # โ
๋ณ๊ฒฝ๋ ๋ถ๋ถ: ์ค๋ฅธ์ชฝ ์ฐฝ ์์ ์ผ์ชฝ(1๏ธโฃ ์๋ณธ...)๊ณผ ์๋ฒฝํ ๋๊ฐ์ ๋์ด๋ฅผ ์ฐจ์งํ๋ ๊ฐ์ง ๋ผ๋ฒจ์ ๋ฌ์์ต๋๋ค! โ
gr.HTML("<div id='prompter_label_space'>๐บ ํ๋กฌํํฐ ๋ทฐ (๋ณ๊ฒฝ์ ํ์ธ)</div>") output_html = gr.HTML() # โ
์์ ํ
์คํธ ๊ฒฐ๊ณผ์ฐฝ์ ๏ฟฝ๏ฟฝ๏ฟฝ๋กฌํํฐ ๋ทฐ ์๋๋ก ๋ด๋ ธ์ต๋๋ค! โ
with gr.Accordion("๐ ์์ ํ
์คํธ ๊ฒฐ๊ณผ (๋ณต์ฌ์ฉ) - ํด๋ฆญํด์ ํผ์น๊ธฐ", open=False): output_text = gr.Textbox(lines=8, label="2๏ธโฃ ๋ณํ๋ ํ
์คํธ", show_copy_button=True, elem_id="output_text_area") output_text = gr.Textbox(lines=8, show_label=False, show_copy_button=True, elem_id="output_text_area") btn_conv.click(fn=process_text, inputs=[input_text, use_g2p, auto_break, font_size], outputs=[output_text, output_html, char_count], api_name=False) btn_clr.click(fn=clear_all, outputs=[input_text, output_text, output_html, char_count], api_name=False)12 unmodified lines inputs=[font_size], js="(size) => { " "let ta1 = document.querySelector('#input_text_area textarea'); " "if(ta1) { ta1.style.fontSize = size + 'px'; ta1.style.lineHeight = '1.8'; } " "if(ta1) { ta1.style.fontSize = size + 'px'; } " "let ta2 = document.querySelector('#output_text_area textarea'); " "if(ta2) { ta2.style.fontSize = size + 'px'; ta2.style.lineHeight = '1.8'; } " "if(ta2) { ta2.style.fontSize = size + 'px'; } " "}" ) app.py+44-13