Spaces:
Sleeping
Sleeping
highlight_diff_texts
Browse files
app.py
CHANGED
@@ -758,27 +758,40 @@ def generate_correct_grammatical_spelling_errors(model, sys_content, eng_level,
|
|
758 |
|
759 |
|
760 |
def highlight_diff_texts(highlight_list, text):
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
782 |
|
783 |
def update_paragraph_correct_grammatical_spelling_errors_input(paragraph):
|
784 |
return paragraph
|
|
|
758 |
|
759 |
|
760 |
def highlight_diff_texts(highlight_list, text):
|
761 |
+
"""
|
762 |
+
將文本中需要高亮的部分用紅色標記出來
|
763 |
+
|
764 |
+
Args:
|
765 |
+
highlight_list: 包含需要高亮的文字列表的 DataFrame
|
766 |
+
text: 原始文本
|
767 |
+
|
768 |
+
Returns:
|
769 |
+
str: 包含高亮標記的 HTML 文本
|
770 |
+
"""
|
771 |
+
try:
|
772 |
+
# 將 DataFrame 轉換為字典
|
773 |
+
highlight_dict = highlight_list.to_dict('records')
|
774 |
+
|
775 |
+
# 初始化 HTML 文本
|
776 |
+
html_text = text
|
777 |
+
|
778 |
+
# 遍歷每個需要高亮的建議
|
779 |
+
for item in highlight_dict:
|
780 |
+
if '原文' in item and item['原文']:
|
781 |
+
original = str(item['原文'])
|
782 |
+
# 使用更簡單的替換方式
|
783 |
+
html_text = html_text.replace(
|
784 |
+
original,
|
785 |
+
f'<span style="color:red;">{original}</span>'
|
786 |
+
)
|
787 |
+
|
788 |
+
# 包裝在段落標籤中
|
789 |
+
return f"<p>{html_text}</p>"
|
790 |
+
|
791 |
+
except Exception as e:
|
792 |
+
print(f"Error in highlight_diff_texts: {str(e)}")
|
793 |
+
# 發生錯誤時返回原始文本
|
794 |
+
return f"<p>{text}</p>"
|
795 |
|
796 |
def update_paragraph_correct_grammatical_spelling_errors_input(paragraph):
|
797 |
return paragraph
|