QIDNLF commited on
Commit
c5aa224
ยท
verified ยท
1 Parent(s): 58b3f67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -13
app.py CHANGED
@@ -36,6 +36,14 @@ def blob_to_base64_html(blob_data):
36
  except Exception as e:
37
  return str(blob_data)
38
 
 
 
 
 
 
 
 
 
39
  def natural_sort_key(s):
40
  if s is None:
41
  return []
@@ -82,6 +90,9 @@ def update_category_dd(standard, version):
82
  try:
83
  target = next(d for d in db_registry if d["standard"] == standard and d["version"] == version)
84
  conn = sqlite3.connect(target["path"])
 
 
 
85
 
86
  tables = pd.read_sql("SELECT name FROM sqlite_master WHERE type='table';", conn)['name'].tolist()
87
  main_t = f"{standard}_{version}"
@@ -101,7 +112,7 @@ def update_category_dd(standard, version):
101
  for _, r in df.iterrows():
102
  choices.append(f"{str(r[ch]).strip()}.{str(r[ca]).strip()}")
103
 
104
- # 2. ๐Ÿš€ ํ…Œ์ด๋ธ” ์ด๋ฆ„ ๊น”๋”ํ•˜๊ฒŒ ์ž๋ฅด๊ธฐ (๊ฐ•๋ ฅํ•œ ์ •๊ทœ์‹ ์ ์šฉ)
105
  pattern = re.compile(f"^{standard}[_\\s-]*{version}[_\\s-]*", re.IGNORECASE)
106
 
107
  for t in tables:
@@ -141,7 +152,7 @@ def highlight_diff(base, comp):
141
 
142
  d = list(difflib.ndiff(b_words, c_words))
143
 
144
- b_res, c_res = [], []
145
  i = 0
146
 
147
  while i < len(d):
@@ -178,6 +189,9 @@ def display_data(standard, version, selection):
178
  try:
179
  target = next(d for d in db_registry if d["standard"] == standard and d["version"] == version)
180
  conn = sqlite3.connect(target["path"])
 
 
 
181
 
182
  tables = pd.read_sql(
183
  "SELECT name FROM sqlite_master WHERE type='table';",
@@ -245,14 +259,8 @@ def display_data(standard, version, selection):
245
  # ๐Ÿ”น ALL ์„ ํƒ
246
  # --------------------------
247
  if selection == "ALL":
248
- query = f"SELECT * FROM [{main_t}]"
249
-
250
- if real_cat:
251
- query += f"""
252
- WHERE IFNULL(UPPER(TRIM(CAST([{real_cat}] AS TEXT))), '') != 'TABLE'
253
- """
254
-
255
- cursor.execute(query)
256
 
257
  # --------------------------
258
  # ๐Ÿ”น chapter.category
@@ -309,7 +317,7 @@ def apply_diff_row(row, base_col, comp_col):
309
  if "<img" in base_val or "<img" in comp_val:
310
  return pd.Series([base_val, comp_val])
311
 
312
- # ๐Ÿš€ 2. [ํ•ต์‹ฌ] ๋‘ ํ…์ŠคํŠธ๊ฐ€ ์™„์ „ํžˆ ๋˜‘๊ฐ™์œผ๋ฉด ๋ฌด๊ฑฐ์šด diff ์—ฐ์‚ฐ ์ƒ๋žต (Fast-path)
313
  if base_val == comp_val:
314
  return pd.Series([base_val, comp_val])
315
 
@@ -359,7 +367,7 @@ def unified_search(bs, bv, bc, cs, cv, cc):
359
  # NaN ๊ฐ’์„ ๋นˆ ๋ฌธ์ž์—ด๋กœ ์ฒ˜๋ฆฌ
360
  merged = merged.fillna("")
361
 
362
- # ๐Ÿš€ ์ตœ์ ํ™” ํฌ์ธํŠธ: iterrows() ๋Œ€์‹  apply() ์‚ฌ์šฉ
363
  merged[[base_col, comp_col]] = merged.apply(
364
  lambda row: apply_diff_row(row, base_col, comp_col),
365
  axis=1
@@ -423,7 +431,7 @@ with gr.Blocks() as demo:
423
  comp_reset_btn.click(reset_comp, None, [comp_standard, comp_version, comp_category])
424
 
425
  # --------------------------
426
- # CSS (์—๋Ÿฌ ์ˆ˜์ •๋จ)
427
  # --------------------------
428
  css = """
429
  table {
 
36
  except Exception as e:
37
  return str(blob_data)
38
 
39
+ # ๐Ÿš€ [ํ•ต์‹ฌ ์ถ”๊ฐ€] ํ…์ŠคํŠธ ๋””์ฝ”๋”ฉ ์—๋Ÿฌ ๋ฐฉ์ง€์šฉ ํŒฉํ† ๋ฆฌ ํ•จ์ˆ˜
40
+ def safe_text_factory(x):
41
+ """ํ…์ŠคํŠธ ๋””์ฝ”๋”ฉ์„ ์‹œ๋„ํ•˜๊ณ , ์‹คํŒจํ•˜๋ฉด(PNG ๋“ฑ ์ด๋ฏธ์ง€์ผ ๊ฒฝ์šฐ) ์›๋ณธ ๋ฐ”์ดํŠธ๋ฅผ ๊ทธ๋Œ€๋กœ ๋ฐ˜ํ™˜"""
42
+ try:
43
+ return x.decode('utf-8')
44
+ except UnicodeDecodeError:
45
+ return x
46
+
47
  def natural_sort_key(s):
48
  if s is None:
49
  return []
 
90
  try:
91
  target = next(d for d in db_registry if d["standard"] == standard and d["version"] == version)
92
  conn = sqlite3.connect(target["path"])
93
+
94
+ # ๐Ÿš€ [ํ•ต์‹ฌ ์ถ”๊ฐ€] ์นดํ…Œ๊ณ ๋ฆฌ ๋ถˆ๋Ÿฌ์˜ฌ ๋•Œ๋„ ์ด๋ฏธ์ง€ ์—๋Ÿฌ ์ฐจ๋‹จ
95
+ conn.text_factory = safe_text_factory
96
 
97
  tables = pd.read_sql("SELECT name FROM sqlite_master WHERE type='table';", conn)['name'].tolist()
98
  main_t = f"{standard}_{version}"
 
112
  for _, r in df.iterrows():
113
  choices.append(f"{str(r[ch]).strip()}.{str(r[ca]).strip()}")
114
 
115
+ # 2. ํ…Œ์ด๋ธ” ์ด๋ฆ„ ๊น”๋”ํ•˜๊ฒŒ ์ž๋ฅด๊ธฐ (๊ฐ•๋ ฅํ•œ ์ •๊ทœ์‹ ์ ์šฉ)
116
  pattern = re.compile(f"^{standard}[_\\s-]*{version}[_\\s-]*", re.IGNORECASE)
117
 
118
  for t in tables:
 
152
 
153
  d = list(difflib.ndiff(b_words, c_words))
154
 
155
+ b_res, c_res = []
156
  i = 0
157
 
158
  while i < len(d):
 
189
  try:
190
  target = next(d for d in db_registry if d["standard"] == standard and d["version"] == version)
191
  conn = sqlite3.connect(target["path"])
192
+
193
+ # ๐Ÿš€ [ํ•ต์‹ฌ ์ถ”๊ฐ€] ๋ฐ์ดํ„ฐ ์กฐํšŒ ์‹œ ์ด๋ฏธ์ง€ ์—๋Ÿฌ ์™„๋ฒฝ ์ฐจ๋‹จ!
194
+ conn.text_factory = safe_text_factory
195
 
196
  tables = pd.read_sql(
197
  "SELECT name FROM sqlite_master WHERE type='table';",
 
259
  # ๐Ÿ”น ALL ์„ ํƒ
260
  # --------------------------
261
  if selection == "ALL":
262
+ # ๐Ÿš€ [์ˆ˜์ •] ํ…์ŠคํŠธ ํŒฉํ† ๋ฆฌ๋กœ ์—๋Ÿฌ๋ฅผ ์žก์•˜์œผ๋ฏ€๋กœ, ๋ถˆํ•„์š”ํ•œ ํ•„ํ„ฐ ์กฐ๊ฑด ์‚ญ์ œ
263
+ cursor.execute(f"SELECT * FROM [{main_t}]")
 
 
 
 
 
 
264
 
265
  # --------------------------
266
  # ๐Ÿ”น chapter.category
 
317
  if "<img" in base_val or "<img" in comp_val:
318
  return pd.Series([base_val, comp_val])
319
 
320
+ # 2. [ํ•ต์‹ฌ] ๋‘ ํ…์ŠคํŠธ๊ฐ€ ์™„์ „ํžˆ ๋˜‘๊ฐ™์œผ๋ฉด ๋ฌด๊ฑฐ์šด diff ์—ฐ์‚ฐ ์ƒ๋žต (Fast-path)
321
  if base_val == comp_val:
322
  return pd.Series([base_val, comp_val])
323
 
 
367
  # NaN ๊ฐ’์„ ๋นˆ ๋ฌธ์ž์—ด๋กœ ์ฒ˜๋ฆฌ
368
  merged = merged.fillna("")
369
 
370
+ # ์ตœ์ ํ™” ํฌ์ธํŠธ: iterrows() ๋Œ€์‹  apply() ์‚ฌ์šฉ
371
  merged[[base_col, comp_col]] = merged.apply(
372
  lambda row: apply_diff_row(row, base_col, comp_col),
373
  axis=1
 
431
  comp_reset_btn.click(reset_comp, None, [comp_standard, comp_version, comp_category])
432
 
433
  # --------------------------
434
+ # CSS
435
  # --------------------------
436
  css = """
437
  table {