Spaces:
Running
Running
Update app.py
#1
by easyadaptor - opened
79 unmodified lines8081828383848586878889908591929332 unmodified lines1261271281241251291301311321301331341351341361371381395 unmodified lines1451461471461481491501517 unmodified lines15916016116016216316416520 unmodified lines18618718818718919019119227 unmodified lines220221222221223224225226142 unmodified lines3693703713703723733743755 unmodified lines38138238338238438538679 unmodified lines
def process_text(input_text, ai_mode, auto_break, smart_pause, font_size): if not input_text or not input_text.strip(): return "", "", "입력 글자 수: 0자", "표시된 마커(@@)가 없습니다." return "", "", "공백 포함: 0자 / 공백 제외: 0자", "표시된 마커(@@)가 없습니다." # ★ 정확한 글자 수 계산 로직 clean_text = input_text.replace('\r', '') len_with_spaces = len(clean_text) len_without_spaces = len(clean_text.replace(' ', '').replace('\n', '')) char_count = f"공백 포함: {len_with_spaces}자 / 공백 제외: {len_without_spaces}자" char_count = f"입력 글자 수: {len(input_text)}자" flat_dict = load_dict() if not flat_dict:32 unmodified lines html_parts.append(f'<span style="background-color: #ffe066; font-weight: bold; padding: 2px; border-radius: 3px; color: #000;">{chunk}</span>') raw_html = "".join(html_parts) # ★ 수정됨: 앞/뒤 어디에 있든 @@가 포함된 어절 전체를 빨간색으로 하이라이트 raw_html = re.sub(r'([^\s<]*@@[^\s<]*)', r'<span style="background-color: #ff4d4d; color: white; font-weight: bold; padding: 2px 6px; border-radius: 4px; box-shadow: 0 0 5px #ff4d4d;">\1</span>', raw_html)
html_output = f'<div id="prompter_label_space">📺 프롬프터 뷰 (변경점 확인)</div><div id="prompter_output_div" style="font-size:{font_size}px;">{raw_html}</div>' # ★ 수정됨: 앞/뒤 어디에 있든 @@가 포함된 단어 완벽 추출 markers = re.findall(r'[^\s]*@@[^\s]*', input_text) unique_markers =[] for m in markers: clean_m = m.strip('.,!?\n') # 끝에 붙은 쉼표나 마침표는 제거해서 깔끔하게 표시 clean_m = m.strip('.,!?\n') if clean_m and clean_m not in unique_markers: unique_markers.append(clean_m) 5 unmodified lines return final_text, html_output, char_count, marker_result
def clear_all(): return "", "", "", "입력 글자 수: 0자", "표시된 마커(@@)가 없습니다." return "", "", "", "공백 포함: 0자 / 공백 제외: 0자", "표시된 마커(@@)가 없습니다."
def add_and_update(word, pronun, current_input, ai_mode, auto_break, smart_pause, font_size): if not word or not pronun:7 unmodified lines if current_input and current_input.strip(): final_text, html_output, char_count, marker_result = process_text(current_input, ai_mode, auto_break, smart_pause, font_size) return error_msg, final_text, html_output, char_count, marker_result return error_msg, "", "", "입력 글자 수: 0자", "표시된 마커(@@)가 없습니다." return error_msg, "", "", "공백 포함: 0자 / 공백 제외: 0자", "표시된 마커(@@)가 없습니다." try: with open(dict_path, "r", encoding="utf-8") as f:20 unmodified lines if current_input and current_input.strip(): final_text, html_output, char_count, marker_result = process_text(current_input, ai_mode, auto_break, smart_pause, font_size) return status_msg, final_text, html_output, char_count, marker_result return status_msg, "", "", "입력 글자 수: 0자", "표시된 마커(@@)가 없습니다." return status_msg, "", "", "공백 포함: 0자 / 공백 제외: 0자", "표시된 마커(@@)가 없습니다."
def load_current_json_to_text(): try:27 unmodified lines with open(dict_path, "w", encoding="utf-8") as f: json.dump(final_data, f, ensure_ascii=False, indent=2) return f"🚨 [덮어쓰기 완료] 수정한 내용({len(new_items)}개)으로 사전을 완벽히 교체했습니다!" return f"🚨[덮어쓰기 완료] 수정한 내용({len(new_items)}개)으로 사전을 완벽히 교체했습니다!" except Exception as e: return f"❌ JSON 파싱 에러 (따옴표나 쉼표가 빠졌는지 확인하세요): {e}"
142 unmodified lines btn_insert_marker = gr.Button("🚨 커서 위치에 마커(@@) 삽입하기", variant="secondary", size="sm") font_size = gr.Slider(minimum=16, maximum=40, value=22, step=2, label="🔍 결과창 글자 크기 조절") char_count = gr.Textbox(label="글자 수 확인", value="입력 글자 수: 0자", interactive=False) char_count = gr.Textbox(label="글자 수 확인", value="공백 포함: 0자 / 공백 제외: 0자", interactive=False) with gr.Row(): btn_conv = gr.Button("✨ 변환하기", variant="primary") btn_copy = gr.Button("📋 변환복사", variant="secondary")5 unmodified lines with gr.Accordion("📂 순수 텍스트 결과 (복사용) - 클릭해서 펼치기", open=False): output_text = gr.Textbox(lines=8, show_label=False, show_copy_button=True, elem_id="output_text_area") # ★ 마커 모아보기 창 marker_collection = gr.Textbox(label="🚨 수정 필요 단어 모아보기 (@@)", interactive=False, lines=2) gr.Markdown("---")app.py+13-12