Update app.py
Browse files
app.py
CHANGED
|
@@ -131,13 +131,29 @@ def fetch_database_records(std, ver, cat, table_type):
|
|
| 131 |
|
| 132 |
def generate_html_diff(text1, text2):
|
| 133 |
try:
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
matcher = difflib.SequenceMatcher(None, words1, words2)
|
| 138 |
|
| 139 |
res1, res2 = [], []
|
| 140 |
-
# get_opcodes()๋ ํ
์คํธ๋ฅผ ํ ๊ธ์์ฉ ๋น๊ตํ์ง ์๊ณ ๋ฉ์ด๋ฆฌ(๋ธ๋ก) ๋จ์๋ก ๋ญํ
์ด๋ก ๋น๊ตํด์ ์๋๊ฐ ๋น์ ์๋์
๋๋ค.
|
| 141 |
for tag, i1, i2, j1, j2 in matcher.get_opcodes():
|
| 142 |
if tag == 'replace':
|
| 143 |
res1.append(f"<span style='color:#ff4d4f; font-weight:bold;'>{' '.join(words1[i1:i2])}</span>")
|
|
@@ -154,8 +170,6 @@ def generate_html_diff(text1, text2):
|
|
| 154 |
except Exception:
|
| 155 |
return text1, text2
|
| 156 |
# ==========================================
|
| 157 |
-
|
| 158 |
-
# ==========================================
|
| 159 |
# 2. UI Component Handlers
|
| 160 |
# ==========================================
|
| 161 |
|
|
|
|
| 131 |
|
| 132 |
def generate_html_diff(text1, text2):
|
| 133 |
try:
|
| 134 |
+
s1, s2 = str(text1), str(text2)
|
| 135 |
+
|
| 136 |
+
# ========================================================
|
| 137 |
+
# ๐ก๏ธ [์์ ์ฅ์น 1] ๊ธ์๊ฐ ๋๋ฌด ๊ธธ๋ฉด (์: 1000์ ์ด์) ์ปดํจํฐ ํฐ์ง ๋ฐฉ์ง
|
| 138 |
+
# ========================================================
|
| 139 |
+
if len(s1) > 1000 or len(s2) > 1000:
|
| 140 |
+
return s1, s2
|
| 141 |
+
|
| 142 |
+
words1, words2 = s1.split(), s2.split()
|
| 143 |
+
if not words1 or not words2:
|
| 144 |
+
return s1, s2
|
| 145 |
+
|
| 146 |
+
# ========================================================
|
| 147 |
+
# ๐ก๏ธ [์์ ์ฅ์น 2] ํ๊ธ vs ์์ด์ฒ๋ผ ๊ฒน์น๋ ๋จ์ด๊ฐ 5%๋ ์ ๋๋ฉด ๋น๊ต ์๋ต
|
| 148 |
+
# ========================================================
|
| 149 |
+
common_words = set(words1) & set(words2)
|
| 150 |
+
if len(common_words) / min(len(words1), len(words2)) < 0.05:
|
| 151 |
+
return s1, s2
|
| 152 |
+
|
| 153 |
+
# ์์ ๊ฒ์ฌ๋ฅผ ํต๊ณผํ ์ง์ง ๋น์ทํ ํ
์คํธ๋ค๋ง ์ด๊ณ ์ ๋น๊ต!
|
| 154 |
matcher = difflib.SequenceMatcher(None, words1, words2)
|
| 155 |
|
| 156 |
res1, res2 = [], []
|
|
|
|
| 157 |
for tag, i1, i2, j1, j2 in matcher.get_opcodes():
|
| 158 |
if tag == 'replace':
|
| 159 |
res1.append(f"<span style='color:#ff4d4f; font-weight:bold;'>{' '.join(words1[i1:i2])}</span>")
|
|
|
|
| 170 |
except Exception:
|
| 171 |
return text1, text2
|
| 172 |
# ==========================================
|
|
|
|
|
|
|
| 173 |
# 2. UI Component Handlers
|
| 174 |
# ==========================================
|
| 175 |
|