QIDNLF commited on
Commit
903eee1
ยท
verified ยท
1 Parent(s): 6b68ae5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -28
app.py CHANGED
@@ -25,7 +25,6 @@ def blob_to_base64_html(blob_data):
25
  try:
26
  if isinstance(blob_data, (bytes, bytearray)):
27
  encoded = base64.b64encode(blob_data).decode('utf-8')
28
- # ํ•ต์‹ฌ ์ˆ˜์ •: width๋ฅผ 100%๋กœ ์ฃผ์–ด ์…€ ๊ฐ€๋กœ๋„ˆ๋น„์— ๊ฝ‰ ์ฐจ๊ฒŒ ๋งŒ๋“ค๊ณ , max-height๋ฅผ 600px๋กœ ๋„‰๋„‰ํ•˜๊ฒŒ ๋Š˜๋ฆผ
29
  return f'''
30
  <img src="data:image/png;base64,{encoded}"
31
  style="width: 50%; max-height: 400px; object-fit: contain;
@@ -102,33 +101,21 @@ def update_category_dd(standard, version):
102
  for _, r in df.iterrows():
103
  choices.append(f"{str(r[ch]).strip()}.{str(r[ca]).strip()}")
104
 
105
- # 2. ๐Ÿš€ ํ…Œ์ด๋ธ” ์ด๋ฆ„ ๊น”๋”ํ•˜๊ฒŒ ์ž๋ฅด๊ธฐ (๋Œ€์†Œ๋ฌธ์ž ๋ฌด์‹œ ๋ฐฉ์‹)
106
- # ์˜ˆ: "r171_00series_"
107
- prefix = f"{standard}_{version}_".lower()
108
- prefix_no_under = f"{standard}_{version}".lower()
109
 
110
  for t in tables:
111
  if t == main_t:
112
  continue
113
 
114
- t_lower = t.lower()
115
-
116
- # ํ…Œ์ด๋ธ” ์ด๋ฆ„์ด prefix("r171_00series_")๋กœ ์‹œ์ž‘ํ•˜๋ฉด ๊ทธ ๊ธธ์ด๋งŒํผ ์•ž๋ถ€๋ถ„์„ ์‹น๋‘‘ ์ž๋ฆ„
117
- if t_lower.startswith(prefix):
118
- short_name = t[len(prefix):]
119
- # ํ˜น์‹œ ์–ธ๋”๋ฐ”(_) ์—†์ด "r171_00seriesTableA" ์ฒ˜๋Ÿผ ๋ถ™์–ด์žˆ์„ ๊ฒฝ์šฐ ๋Œ€๋น„
120
- elif t_lower.startswith(prefix_no_under):
121
- short_name = t[len(prefix_no_under):]
122
- else:
123
- short_name = t
124
-
125
- choices.append(f"{short_name.strip()}")
126
 
127
  conn.close()
128
 
129
  except Exception as e:
130
  print(f"[Error in update_category_dd] standard: {standard}, version: {version}")
131
- import traceback
132
  traceback.print_exc()
133
 
134
  return gr.Dropdown(choices=choices)
@@ -197,12 +184,21 @@ def display_data(standard, version, selection):
197
  if main_t not in tables:
198
  main_t = tables[0]
199
 
200
- if selection in tables:
201
- full_table_name = selection
202
- else:
203
- full_table_name = f"{standard}_{version}_{selection}"
204
-
205
- if full_table_name in tables:
 
 
 
 
 
 
 
 
 
206
  df = pd.read_sql(f"SELECT * FROM [{full_table_name}]", conn)
207
  df.columns = [c.strip() for c in df.columns]
208
  df = df.drop(columns=[c for c in df.columns if c.lower() == "version"], errors="ignore")
@@ -214,6 +210,7 @@ def display_data(standard, version, selection):
214
  conn.close()
215
  return df
216
 
 
217
  cols = pd.read_sql(f"PRAGMA table_info([{main_t}])", conn)['name'].tolist()
218
  lower = [c.lower().strip() for c in cols]
219
 
@@ -392,13 +389,13 @@ table {
392
  }
393
 
394
  /* -------------------------- */
395
- /* 2์ปฌ๋Ÿผ */
396
  /* -------------------------- */
397
  table th:nth-last-child(2):first-child, table td:nth-last-child(2):first-child { width: 15% !important; }
398
  table th:nth-last-child(1), table td:nth-last-child(1) { width: 85% !important; }
399
 
400
  /* -------------------------- */
401
- /* 4์ปฌ๋Ÿผ */
402
  /* -------------------------- */
403
  table th:nth-child(1):nth-last-child(4), table td:nth-child(1):nth-last-child(4) { width: 7% !important; }
404
  table th:nth-child(2):nth-last-child(3), table td:nth-child(2):nth-last-child(3) { width: 43% !important; }
@@ -406,7 +403,7 @@ table th:nth-child(3):nth-last-child(2), table td:nth-child(3):nth-last-child(2)
406
  table th:nth-child(4):nth-last-child(1), table td:nth-child(4):nth-last-child(1) { width: 43% !important; }
407
 
408
  /* -------------------------- */
409
- /* 5์ปฌ๋Ÿผ */
410
  /* -------------------------- */
411
  table th:nth-child(1):nth-last-child(5), table td:nth-child(1):nth-last-child(5) { width: 15% !important; }
412
  table th:nth-child(2):nth-last-child(4), table td:nth-child(2):nth-last-child(4) { width: 10% !important; }
@@ -415,7 +412,7 @@ table th:nth-child(4):nth-last-child(2), table td:nth-child(4):nth-last-child(2)
415
  table th:nth-child(5):nth-last-child(1), table td:nth-child(5):nth-last-child(1) { width: 35% !important; }
416
 
417
  /* -------------------------- */
418
- /* 6์ปฌ๋Ÿผ */
419
  /* -------------------------- */
420
  table th:nth-child(1):nth-last-child(6), table td:nth-child(1):nth-last-child(6) { width: 8% !important; }
421
  table th:nth-child(2):nth-last-child(5), table td:nth-child(2):nth-last-child(5) { width: 25% !important; }
 
25
  try:
26
  if isinstance(blob_data, (bytes, bytearray)):
27
  encoded = base64.b64encode(blob_data).decode('utf-8')
 
28
  return f'''
29
  <img src="data:image/png;base64,{encoded}"
30
  style="width: 50%; max-height: 400px; object-fit: contain;
 
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:
108
  if t == main_t:
109
  continue
110
 
111
+ # ๋Œ€์†Œ๋ฌธ์ž, ์–ธ๋”๋ฐ”, ๊ณต๋ฐฑ์„ ์ฐฐ๋–ก๊ฐ™์ด ๋ฌด์‹œํ•˜๊ณ  ๊ธฐ์ค€ ์ ‘๋‘์‚ฌ๋ฅผ ๋‚ ๋ ค๋ฒ„๋ฆผ
112
+ short_name = pattern.sub("", t).strip(" _")
113
+ choices.append(short_name)
 
 
 
 
 
 
 
 
 
114
 
115
  conn.close()
116
 
117
  except Exception as e:
118
  print(f"[Error in update_category_dd] standard: {standard}, version: {version}")
 
119
  traceback.print_exc()
120
 
121
  return gr.Dropdown(choices=choices)
 
184
  if main_t not in tables:
185
  main_t = tables[0]
186
 
187
+ # ๐Ÿš€ ์ž˜๋ฆฐ short_name์œผ๋กœ ์›๋ž˜ ํ’€๋„ค์ž„ ํ…Œ์ด๋ธ” ์ฐพ๊ธฐ (Reverse Lookup)
188
+ full_table_name = None
189
+ pattern = re.compile(f"^{standard}[_\\s-]*{version}[_\\s-]*", re.IGNORECASE)
190
+
191
+ for t in tables:
192
+ if t == selection: # ํ’€๋„ค์ž„์ด ๊ทธ๋Œ€๋กœ ๋งค์นญ๋˜๋Š” ๊ฒฝ์šฐ
193
+ full_table_name = t
194
+ break
195
+ short = pattern.sub("", t).strip(" _")
196
+ if short == selection: # ๋“œ๋กญ๋‹ค์šด์˜ ์งง์€ ์ด๋ฆ„๊ณผ ๋งค์นญ๋˜๋Š” ์‹ค์ œ DB ํ…Œ์ด๋ธ” ์ฐพ๊ธฐ
197
+ full_table_name = t
198
+ break
199
+
200
+ # ํ…Œ์ด๋ธ”(A4/1 ๋“ฑ)์„ ์„ ํƒํ•œ ๊ฒฝ์šฐ
201
+ if full_table_name:
202
  df = pd.read_sql(f"SELECT * FROM [{full_table_name}]", conn)
203
  df.columns = [c.strip() for c in df.columns]
204
  df = df.drop(columns=[c for c in df.columns if c.lower() == "version"], errors="ignore")
 
210
  conn.close()
211
  return df
212
 
213
+ # ALL ๋˜๋Š” ์ฑ•ํ„ฐ.์นดํ…Œ๊ณ ๋ฆฌ ์„ ํƒํ•œ ๊ฒฝ์šฐ
214
  cols = pd.read_sql(f"PRAGMA table_info([{main_t}])", conn)['name'].tolist()
215
  lower = [c.lower().strip() for c in cols]
216
 
 
389
  }
390
 
391
  /* -------------------------- */
392
+ /* 2์ปฌ๋Ÿผ */
393
  /* -------------------------- */
394
  table th:nth-last-child(2):first-child, table td:nth-last-child(2):first-child { width: 15% !important; }
395
  table th:nth-last-child(1), table td:nth-last-child(1) { width: 85% !important; }
396
 
397
  /* -------------------------- */
398
+ /* 4์ปฌ๋Ÿผ */
399
  /* -------------------------- */
400
  table th:nth-child(1):nth-last-child(4), table td:nth-child(1):nth-last-child(4) { width: 7% !important; }
401
  table th:nth-child(2):nth-last-child(3), table td:nth-child(2):nth-last-child(3) { width: 43% !important; }
 
403
  table th:nth-child(4):nth-last-child(1), table td:nth-child(4):nth-last-child(1) { width: 43% !important; }
404
 
405
  /* -------------------------- */
406
+ /* 5์ปฌ๋Ÿผ */
407
  /* -------------------------- */
408
  table th:nth-child(1):nth-last-child(5), table td:nth-child(1):nth-last-child(5) { width: 15% !important; }
409
  table th:nth-child(2):nth-last-child(4), table td:nth-child(2):nth-last-child(4) { width: 10% !important; }
 
412
  table th:nth-child(5):nth-last-child(1), table td:nth-child(5):nth-last-child(1) { width: 35% !important; }
413
 
414
  /* -------------------------- */
415
+ /* 6์ปฌ๋Ÿผ */
416
  /* -------------------------- */
417
  table th:nth-child(1):nth-last-child(6), table td:nth-child(1):nth-last-child(6) { width: 8% !important; }
418
  table th:nth-child(2):nth-last-child(5), table td:nth-child(2):nth-last-child(5) { width: 25% !important; }