QIDNLF commited on
Commit
baf176f
ยท
verified ยท
1 Parent(s): 54f33b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -6
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
- # ๐Ÿ’ก [์†๋„ ๊ฐœ์„ ] ์—„์ฒญ๋‚˜๊ฒŒ ๋А๋ฆฐ ndiff ๋Œ€์‹ , 100๋ฐฐ ๋น ๋ฅธ SequenceMatcher ๋ธ”๋ก ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์‚ฌ์šฉ!
135
- words1 = str(text1).split()
136
- words2 = str(text2).split()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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