jin2li commited on
Commit
88191d0
Β·
verified Β·
1 Parent(s): f57aedb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -121,15 +121,16 @@ def find_main_columns(df):
121
  "content", "amount", "concentration", "%"
122
  ]
123
 
124
- # 1) μ›λ£Œλͺ… 컬럼 μ°ΎκΈ°
125
  raw_scores = []
126
 
127
  for idx, col in enumerate(df.columns):
128
  values = df[col].dropna().astype(str).str.strip()
 
129
  if values.empty:
130
  continue
131
 
132
  numeric_ratio = values.apply(is_numeric_like).mean()
 
133
  if numeric_ratio > 0.7:
134
  continue
135
 
@@ -147,7 +148,6 @@ def find_main_columns(df):
147
  if any(k.lower() in header for k in ingredient_keywords):
148
  score -= 5
149
 
150
- # 병합 μ…€ μ›λ£Œλͺ…은 보톡 일뢀 ν–‰λ§Œ 값이 있음
151
  if 0 < non_null_ratio < 0.7:
152
  score += 4
153
 
@@ -167,7 +167,6 @@ def find_main_columns(df):
167
  else:
168
  raw_col = df.columns[0]
169
 
170
- # 2) ꡬ성 μ„±λΆ„ 컬럼 μ°ΎκΈ°
171
  ingredient_scores = []
172
 
173
  known_ingredients = [
@@ -181,10 +180,12 @@ def find_main_columns(df):
181
  continue
182
 
183
  values = df[col].dropna().astype(str).str.strip()
 
184
  if values.empty:
185
  continue
186
 
187
  numeric_ratio = values.apply(is_numeric_like).mean()
 
188
  if numeric_ratio > 0.5:
189
  continue
190
 
@@ -213,7 +214,6 @@ def find_main_columns(df):
213
  else:
214
  ingredient_col = df.columns[1] if len(df.columns) > 1 else raw_col
215
 
216
- # 3) 숫자 컬럼 찾기
217
  numeric_candidates = []
218
 
219
  for idx, col in enumerate(df.columns):
@@ -222,7 +222,6 @@ def find_main_columns(df):
222
 
223
  header = str(col).lower()
224
 
225
- # 번호/순번 컬럼 μ œμ™Έ
226
  if header in ["no", "번호", "순번", "index", "#"]:
227
  continue
228
 
@@ -259,14 +258,12 @@ def find_main_columns(df):
259
  final_amount_col = None
260
 
261
  if numeric_candidates:
262
- # μ΅œμ’… ꡬ성 μ„±λΆ„ ν•¨λŸ‰μ€ 보톡 값이 많이 μ±„μ›Œμ§„ 숫자 컬럼
263
  final_amount_col = sorted(
264
  numeric_candidates,
265
  key=lambda x: (x["non_null_count"], x["idx"]),
266
  reverse=True
267
  )[0]["col"]
268
 
269
- # μ›λ£Œ νˆ¬μž…λŸ‰μ€ 보톡 병합 셀이라 값이 적게 있음
270
  low_fill_candidates = [
271
  c for c in numeric_candidates
272
  if c["col"] != final_amount_col
@@ -318,6 +315,7 @@ def build_database(country_folders):
318
  with pdfplumber.open(os.path.join(folder, filename)) as pdf:
319
  for page in pdf.pages:
320
  text = page.extract_text()
 
321
  if text:
322
  chunks = splitter.split_text(
323
  f"[κ΅­κ°€/폴더: {folder}] [좜처: {filename}] {text}"
@@ -351,12 +349,16 @@ def parse_response(text):
351
 
352
  if line.startswith("규제 λŒ€μƒ:"):
353
  result["규제 λŒ€μƒ"] = line.split(":", 1)[1].strip() or "-"
 
354
  elif line.startswith("μ›λ£Œ νˆ¬μž…λŸ‰:"):
355
  result["μ›λ£Œ νˆ¬μž…λŸ‰"] = line.split(":", 1)[1].strip() or "-"
 
356
  elif line.startswith("적합 μ—¬λΆ€:"):
357
  result["적합 μ—¬λΆ€"] = line.split(":", 1)[1].strip() or "확인 ν•„μš”"
 
358
  elif line.startswith("뢀적합 μ‚¬μœ :"):
359
  result["뢀적합 μ‚¬μœ "] = line.split(":", 1)[1].strip() or "-"
 
360
  elif line.startswith("규제 정도:"):
361
  result["규제 정도"] = line.split(":", 1)[1].strip() or "정보 μ—†μŒ"
362
 
@@ -388,12 +390,10 @@ def style_excel(path):
388
  status = str(ws.cell(row, status_col).value or "")
389
  reg = str(ws.cell(row, reg_col).value or "")
390
 
391
- # λΆ€μ ν•©λ§Œ 빨간색
392
  if "뢀적합" in status:
393
  for col in range(1, ws.max_column + 1):
394
  ws.cell(row, col).fill = red
395
 
396
- # 규제 μžˆλŠ” κ²ƒλ§Œ λ…Έλž€μƒ‰
397
  elif (
398
  reg.strip()
399
  and "정보 μ—†μŒ" not in reg
@@ -440,7 +440,6 @@ def process(country_folders, file):
440
 
441
  raw_col, ingredient_col, amount_col, final_amount_col = find_main_columns(df)
442
 
443
- # 병합 μ…€ λ•Œλ¬Έμ— λΉ„μ–΄ μžˆλŠ” μ›λ£Œλͺ…을 μœ„ κ°’μœΌλ‘œ 채움
444
  df[raw_col] = df[raw_col].ffill()
445
 
446
  llm = ChatOpenAI(
@@ -469,6 +468,7 @@ def process(country_folders, file):
469
 
470
  if final_amount_col:
471
  val = row.get(final_amount_col)
 
472
  if not pd.isna(val):
473
  final_amounts.append(str(val))
474
 
@@ -476,6 +476,7 @@ def process(country_folders, file):
476
 
477
  if amount_col:
478
  raw_amount_values = group[amount_col].dropna().tolist()
 
479
  if raw_amount_values:
480
  raw_amount = raw_amount_values[0]
481
 
@@ -597,7 +598,7 @@ def process(country_folders, file):
597
  # =========================
598
  # UI
599
  # =========================
600
- with gr.Blocks(css=custom_css) as demo:
601
  gr.Markdown("# 🌍 reBom Regulatory Screening AI")
602
  gr.Markdown("### κΈ€λ‘œλ²Œ ν™”μž₯ν’ˆ 규제 기반 μ „μ„±λΆ„ μŠ€ν¬λ¦¬λ‹")
603
 
@@ -646,4 +647,7 @@ with gr.Blocks(css=custom_css) as demo:
646
  )
647
 
648
 
649
- demo.launch(ssr_mode=False)
 
 
 
 
121
  "content", "amount", "concentration", "%"
122
  ]
123
 
 
124
  raw_scores = []
125
 
126
  for idx, col in enumerate(df.columns):
127
  values = df[col].dropna().astype(str).str.strip()
128
+
129
  if values.empty:
130
  continue
131
 
132
  numeric_ratio = values.apply(is_numeric_like).mean()
133
+
134
  if numeric_ratio > 0.7:
135
  continue
136
 
 
148
  if any(k.lower() in header for k in ingredient_keywords):
149
  score -= 5
150
 
 
151
  if 0 < non_null_ratio < 0.7:
152
  score += 4
153
 
 
167
  else:
168
  raw_col = df.columns[0]
169
 
 
170
  ingredient_scores = []
171
 
172
  known_ingredients = [
 
180
  continue
181
 
182
  values = df[col].dropna().astype(str).str.strip()
183
+
184
  if values.empty:
185
  continue
186
 
187
  numeric_ratio = values.apply(is_numeric_like).mean()
188
+
189
  if numeric_ratio > 0.5:
190
  continue
191
 
 
214
  else:
215
  ingredient_col = df.columns[1] if len(df.columns) > 1 else raw_col
216
 
 
217
  numeric_candidates = []
218
 
219
  for idx, col in enumerate(df.columns):
 
222
 
223
  header = str(col).lower()
224
 
 
225
  if header in ["no", "번호", "순번", "index", "#"]:
226
  continue
227
 
 
258
  final_amount_col = None
259
 
260
  if numeric_candidates:
 
261
  final_amount_col = sorted(
262
  numeric_candidates,
263
  key=lambda x: (x["non_null_count"], x["idx"]),
264
  reverse=True
265
  )[0]["col"]
266
 
 
267
  low_fill_candidates = [
268
  c for c in numeric_candidates
269
  if c["col"] != final_amount_col
 
315
  with pdfplumber.open(os.path.join(folder, filename)) as pdf:
316
  for page in pdf.pages:
317
  text = page.extract_text()
318
+
319
  if text:
320
  chunks = splitter.split_text(
321
  f"[κ΅­κ°€/폴더: {folder}] [좜처: {filename}] {text}"
 
349
 
350
  if line.startswith("규제 λŒ€μƒ:"):
351
  result["규제 λŒ€μƒ"] = line.split(":", 1)[1].strip() or "-"
352
+
353
  elif line.startswith("μ›λ£Œ νˆ¬μž…λŸ‰:"):
354
  result["μ›λ£Œ νˆ¬μž…λŸ‰"] = line.split(":", 1)[1].strip() or "-"
355
+
356
  elif line.startswith("적합 μ—¬λΆ€:"):
357
  result["적합 μ—¬λΆ€"] = line.split(":", 1)[1].strip() or "확인 ν•„μš”"
358
+
359
  elif line.startswith("뢀적합 μ‚¬μœ :"):
360
  result["뢀적합 μ‚¬μœ "] = line.split(":", 1)[1].strip() or "-"
361
+
362
  elif line.startswith("규제 정도:"):
363
  result["규제 정도"] = line.split(":", 1)[1].strip() or "정보 μ—†μŒ"
364
 
 
390
  status = str(ws.cell(row, status_col).value or "")
391
  reg = str(ws.cell(row, reg_col).value or "")
392
 
 
393
  if "뢀적합" in status:
394
  for col in range(1, ws.max_column + 1):
395
  ws.cell(row, col).fill = red
396
 
 
397
  elif (
398
  reg.strip()
399
  and "정보 μ—†μŒ" not in reg
 
440
 
441
  raw_col, ingredient_col, amount_col, final_amount_col = find_main_columns(df)
442
 
 
443
  df[raw_col] = df[raw_col].ffill()
444
 
445
  llm = ChatOpenAI(
 
468
 
469
  if final_amount_col:
470
  val = row.get(final_amount_col)
471
+
472
  if not pd.isna(val):
473
  final_amounts.append(str(val))
474
 
 
476
 
477
  if amount_col:
478
  raw_amount_values = group[amount_col].dropna().tolist()
479
+
480
  if raw_amount_values:
481
  raw_amount = raw_amount_values[0]
482
 
 
598
  # =========================
599
  # UI
600
  # =========================
601
+ with gr.Blocks() as demo:
602
  gr.Markdown("# 🌍 reBom Regulatory Screening AI")
603
  gr.Markdown("### κΈ€λ‘œλ²Œ ν™”μž₯ν’ˆ 규제 기반 μ „μ„±λΆ„ μŠ€ν¬λ¦¬λ‹")
604
 
 
647
  )
648
 
649
 
650
+ demo.launch(
651
+ ssr_mode=False,
652
+ css=custom_css
653
+ )