Files changed (1) hide show
  1. app.py +210 -194
app.py CHANGED
@@ -13,6 +13,7 @@
13
  # - Gradio 로그인 인증 / public share link 적용
14
  # - MergedCell column_letter 오류 수정 완료
15
  # ============================================================
 
16
  # ============================================================
17
  # reBom Regulatory Screening AI
18
  # - 국가별 규제 폴더 안에서만 검색
@@ -20,6 +21,9 @@
20
  # - GPT는 검색된 원문 안에서만 판정
21
  # - 식약처 사이트 실시간 조회 옵션
22
  # - COOS 제거
 
 
 
23
  # - 고위험 성분 Pass 자동 방지
24
  # - Formular Ingredients Statement 양식 출력
25
  # - 원본 TOTAL 행 제거 후 새 TOTAL 행 1개만 생성
@@ -166,102 +170,35 @@ UV_FILTER_RULES = {
166
  "octocrylene": {
167
  "label": "Octocrylene",
168
  "aliases": ["octocrylene", "옥토크릴렌", "6197-30-4"],
169
- "EU": {
170
- "status": "allowed",
171
- "limit": 10,
172
- "formula_text": "배합 한도:\n스프레이: 9% /\n기타제품: 10%",
173
- },
174
- "FDA": {
175
- "status": "allowed",
176
- "limit": 10,
177
- "formula_text": "라벨링 필수",
178
- },
179
- "KOREA": {
180
- "status": "allowed",
181
- "limit": 10,
182
- "formula_text": "배합한도: 10%",
183
- },
184
- "JAPAN": {
185
- "status": "allowed",
186
- "limit": 10,
187
- "formula_text": "배합한도: 10%",
188
- },
189
- "SEPHORA": {
190
- "status": "prohibited",
191
- "formula_text": "배합금지",
192
- },
193
  },
194
  "homosalate": {
195
  "label": "Homosalate",
196
  "aliases": ["homosalate", "호모살레이트", "118-56-9"],
197
- "ASEAN": {
198
- "status": "allowed",
199
- "limit": 10,
200
- "formula_text": "배합한도: 10%",
201
- },
202
- "EU": {
203
- "status": "allowed",
204
- "limit": 7.34,
205
- "formula_text": "배합한도: 7.34%",
206
- },
207
- "FDA": {
208
- "status": "allowed",
209
- "limit": 15,
210
- "formula_text": "배합한도: 15%",
211
- },
212
- "KOREA": {
213
- "status": "allowed",
214
- "limit": 10,
215
- "formula_text": "배합한도: 10%",
216
- },
217
- "JAPAN": {
218
- "status": "allowed",
219
- "limit": 10,
220
- "formula_text": "배합한도: 10%",
221
- },
222
  },
223
  "octisalate": {
224
  "label": "Octisalate / Ethylhexyl Salicylate",
225
  "aliases": ["octisalate", "ethylhexyl salicylate", "옥티살레이트", "118-60-5"],
226
- "EU": {
227
- "status": "allowed",
228
- "limit": 5,
229
- "formula_text": "배합한도: 5%",
230
- },
231
- "FDA": {
232
- "status": "allowed",
233
- "limit": 5,
234
- "formula_text": "배합한도: 5%",
235
- },
236
- "KOREA": {
237
- "status": "allowed",
238
- "limit": 5,
239
- "formula_text": "배합한도: 5%",
240
- },
241
- "JAPAN": {
242
- "status": "allowed",
243
- "limit": 5,
244
- "formula_text": "배합한도: 5%",
245
- },
246
  },
247
  "avobenzone": {
248
  "label": "Avobenzone",
249
  "aliases": ["avobenzone", "butyl methoxydibenzoylmethane", "아보벤존", "70356-09-1"],
250
- "EU": {
251
- "status": "allowed",
252
- "limit": 5,
253
- "formula_text": "배합한도: 5%",
254
- },
255
- "FDA": {
256
- "status": "allowed",
257
- "limit": 3,
258
- "formula_text": "배합한도: 3%",
259
- },
260
- "KOREA": {
261
- "status": "allowed",
262
- "limit": 5,
263
- "formula_text": "배합한도: 5%",
264
- },
265
  },
266
  }
267
 
@@ -269,21 +206,9 @@ PRESERVATIVE_RULES = {
269
  "phenoxyethanol": {
270
  "label": "Phenoxyethanol",
271
  "aliases": ["phenoxyethanol", "페녹시에탄올", "122-99-6"],
272
- "EU": {
273
- "status": "allowed",
274
- "limit": 1,
275
- "formula_text": "배합한도: 1%",
276
- },
277
- "KOREA": {
278
- "status": "allowed",
279
- "limit": 1,
280
- "formula_text": "배합한도: 1%",
281
- },
282
- "JAPAN": {
283
- "status": "allowed",
284
- "limit": 1,
285
- "formula_text": "배합한도: 1%",
286
- },
287
  },
288
  }
289
 
@@ -365,33 +290,15 @@ def country_key(country):
365
  text = re.sub(r"\s+", " ", text).strip()
366
 
367
  mapping = {
368
- "한국": "KOREA",
369
- "KOREA": "KOREA",
370
- "KR": "KOREA",
371
- "EU": "EU",
372
- "E.U.": "EU",
373
- "EUROPE": "EU",
374
- "유럽": "EU",
375
- "EU FUTURE": "EU_FUTURE",
376
- "EU (FUTURE)": "EU_FUTURE",
377
- "JAPAN": "JAPAN",
378
- "JP": "JAPAN",
379
- "일본": "JAPAN",
380
- "CHINA": "CHINA",
381
- "CN": "CHINA",
382
- "중국": "CHINA",
383
- "USA": "FDA",
384
- "US": "FDA",
385
- "미국": "FDA",
386
- "FDA": "FDA",
387
- "ASEAN": "ASEAN",
388
- "아세안": "ASEAN",
389
- "UK": "UK",
390
- "UNITED KINGDOM": "UK",
391
- "영국": "UK",
392
- "SEPHORA": "SEPHORA",
393
- "TARGET": "TARGET",
394
- "ULTA": "ULTA",
395
  }
396
 
397
  return mapping.get(text, text)
@@ -478,9 +385,10 @@ def get_identity_text(material, component):
478
  texts = [
479
  component.get("한글 성분명", ""),
480
  component.get("INCI Name", ""),
 
 
481
  material.get("Trade name(국문)", ""),
482
  material.get("Trade name(영문)", ""),
483
- component.get("CAS.No", ""),
484
  ]
485
 
486
  return normalize_text(" ".join([safe_str(x) for x in texts if safe_str(x)]))
@@ -498,7 +406,44 @@ def match_rule_key(material, component, rule_dict):
498
  return None
499
 
500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
501
  def get_restricted_candidate_reason(material, component):
 
 
 
502
  uv_key = match_rule_key(material, component, UV_FILTER_RULES)
503
  if uv_key:
504
  return "UV 필터"
@@ -575,6 +520,9 @@ def normalize_formula_country_text(text, country_col="", inci_name="", amount_te
575
  if NEED_CHECK_TEXT in text:
576
  return NEED_CHECK_TEXT
577
 
 
 
 
578
  if "octocrylene" in inci_norm or "옥토크릴렌" in inci_norm:
579
  if country_col == "EU":
580
  return "배합 한도:\n스프레이: 9% /\n기타제품: 10%"
@@ -1265,20 +1213,73 @@ def install_playwright_chromium_once():
1265
 
1266
 
1267
  def extract_terms_for_live_lookup(row_items):
1268
- terms = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1269
 
1270
  for item in row_items:
 
1271
  comp = item["component"]
1272
- for value in [comp.get("INCI Name", ""), comp.get("한글 성분명", "")]:
 
 
 
 
 
 
 
 
 
 
 
 
1273
  value = safe_str(value)
1274
- if value and len(normalize_compact(value)) >= 3:
1275
- terms.append(value)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1276
 
1277
  seen = set()
1278
  unique = []
1279
 
1280
- for term in terms:
1281
  key = normalize_compact(term)
 
1282
  if key and key not in seen:
1283
  seen.add(key)
1284
  unique.append(term)
@@ -1523,33 +1524,58 @@ def mfds_live_lookup_terms(terms, max_terms=30, headless=True):
1523
 
1524
  with sync_playwright() as p:
1525
  browser = p.chromium.launch(
1526
- headless=True,
1527
- args=[
1528
- "--no-sandbox",
1529
- "--disable-setuid-sandbox",
1530
- "--disable-dev-shm-usage",
1531
- "--disable-gpu",
1532
- "--disable-software-rasterizer",
1533
- "--disable-extensions",
1534
- "--disable-background-networking",
1535
- "--disable-default-apps",
1536
- "--disable-sync",
1537
- "--metrics-recording-only",
1538
- "--mute-audio",
1539
- ],
1540
- )
 
1541
  context = browser.new_context(
1542
- viewport={"width": 1400, "height": 1000},
1543
- user_agent="Mozilla/5.0 reBom Regulatory Screening",
 
 
 
 
 
1544
  )
 
1545
  page = context.new_page()
1546
 
1547
  for idx, term in enumerate(terms, start=1):
1548
  try:
1549
  print(f"MFDS 실시간 조회 {idx}/{len(terms)}: {term}")
1550
 
1551
- page.goto(MFDS_LIVE_URL, wait_until="domcontentloaded", timeout=30000)
1552
- page.wait_for_timeout(2500)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1553
 
1554
  if not mfds_fill_search_input(page, term):
1555
  local_errors.append(f"{term}: 검색 입력창 찾기 실패")
@@ -1754,6 +1780,10 @@ def evaluate_local_rules(country, material, component, ingredient_totals, ingred
1754
  ckey = country_key(country)
1755
  amount = component.get("amount_float")
1756
 
 
 
 
 
1757
  uv_result = evaluate_limit_rule(country, material, component, UV_FILTER_RULES, "UV 필터")
1758
  if uv_result is not None:
1759
  return uv_result
@@ -1788,28 +1818,11 @@ def evaluate_local_rules(country, material, component, ingredient_totals, ingred
1788
  if not matched:
1789
  continue
1790
 
1791
- if ckey not in ["EU", "EU_FUTURE", "UK", "KOREA"]:
1792
- return {
1793
- "대표 INCI": rule["label"],
1794
- "결과": f"향료 알레르겐 / {rule['label']} / {display_country(country)} 표시기준 자료 확인 필요",
1795
- "표시문구": NEED_CHECK_TEXT,
1796
- "비고": "향료 알레르겐 후보이나 해당 국가 기준 미등록. Pass 처리 금지.",
1797
- }
1798
-
1799
- total_amount = ingredient_totals.get(fragrance_key, amount)
1800
- total_text = format_percent(total_amount) if total_amount is not None else "함량 확인 필요"
1801
-
1802
- result_text = (
1803
- f"향료 알레르겐 / {rule['label']} 총 {total_text}%, "
1804
- f"Leave-on 기준 {format_percent(rule['leave_on'])}%, "
1805
- f"Wash-off 기준 {format_percent(rule['wash_off'])}% 확인 필요"
1806
- )
1807
-
1808
  return {
1809
  "대표 INCI": rule["label"],
1810
- "결과": result_text,
1811
- "표시문구": "표시기준 확인",
1812
- "비고": "-",
1813
  }
1814
 
1815
  if amount is None:
@@ -2058,13 +2071,6 @@ CAS.No: {cas_no}
2058
  결과:
2059
  표시문구:
2060
  비고:
2061
-
2062
- 표시문구 작성 규칙:
2063
- - 문제 없으면 "Pass"
2064
- - 배합한도가 있으면 "배합한도: 10%"처럼 짧게 작성
2065
- - 스프레이/기타제품처럼 조건이 있으면 줄바꿈으로 작성
2066
- - 라벨 표시가 필요하면 "라벨링 필수"
2067
- - 정확한 판단이 어려우면 "확인 필요"
2068
  """
2069
 
2070
  try:
@@ -2125,14 +2131,7 @@ def evaluate_components_with_llm_batch(country, targets, llm):
2125
  }
2126
 
2127
  results[item["target_id"]] = result
2128
- log_search_context(
2129
- item["target_id"],
2130
- country,
2131
- comp,
2132
- result["결과"],
2133
- "NO_DB",
2134
- "해당 국가/채널 규제 DB 없음",
2135
- )
2136
 
2137
  return results
2138
 
@@ -2197,14 +2196,7 @@ CAS.No: {cas_no}
2197
 
2198
  results[item["target_id"]] = result
2199
  EVAL_CACHE[make_eval_cache_key(country, comp)] = result
2200
- log_search_context(
2201
- item["target_id"],
2202
- country,
2203
- comp,
2204
- result["결과"],
2205
- "NO_MEANINGFUL_HIT",
2206
- context,
2207
- )
2208
 
2209
  uncached_targets = filtered_targets
2210
 
@@ -2725,6 +2717,30 @@ def process(
2725
  gpt_targets = []
2726
 
2727
  for item in row_items:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2728
  mfds_result = None
2729
 
2730
  if use_mfds_live and mfds_df is not None and not mfds_df.empty:
 
13
  # - Gradio 로그인 인증 / public share link 적용
14
  # - MergedCell column_letter 오류 수정 완료
15
  # ============================================================
16
+
17
  # ============================================================
18
  # reBom Regulatory Screening AI
19
  # - 국가별 규제 폴더 안에서만 검색
 
21
  # - GPT는 검색된 원문 안에서만 판정
22
  # - 식약처 사이트 실시간 조회 옵션
23
  # - COOS 제거
24
+ # - Water 등 일반 성분은 식약처 조회 후순위/제외
25
+ # - 식약처 접속 실패 시 3회 재시도
26
+ # - 향료는 국가 상관없이 확인 필요
27
  # - 고위험 성분 Pass 자동 방지
28
  # - Formular Ingredients Statement 양식 출력
29
  # - 원본 TOTAL 행 제거 후 새 TOTAL 행 1개만 생성
 
170
  "octocrylene": {
171
  "label": "Octocrylene",
172
  "aliases": ["octocrylene", "옥토크릴렌", "6197-30-4"],
173
+ "EU": {"status": "allowed", "limit": 10, "formula_text": "배합 한도:\n스프레이: 9% /\n기타제품: 10%"},
174
+ "FDA": {"status": "allowed", "limit": 10, "formula_text": "라벨링 필수"},
175
+ "KOREA": {"status": "allowed", "limit": 10, "formula_text": "배합한도: 10%"},
176
+ "JAPAN": {"status": "allowed", "limit": 10, "formula_text": "배합한도: 10%"},
177
+ "SEPHORA": {"status": "prohibited", "formula_text": "배합금지"},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  },
179
  "homosalate": {
180
  "label": "Homosalate",
181
  "aliases": ["homosalate", "호모살레이트", "118-56-9"],
182
+ "ASEAN": {"status": "allowed", "limit": 10, "formula_text": "배합한도: 10%"},
183
+ "EU": {"status": "allowed", "limit": 7.34, "formula_text": "배합한도: 7.34%"},
184
+ "FDA": {"status": "allowed", "limit": 15, "formula_text": "배합한도: 15%"},
185
+ "KOREA": {"status": "allowed", "limit": 10, "formula_text": "배합한도: 10%"},
186
+ "JAPAN": {"status": "allowed", "limit": 10, "formula_text": "배합한도: 10%"},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  },
188
  "octisalate": {
189
  "label": "Octisalate / Ethylhexyl Salicylate",
190
  "aliases": ["octisalate", "ethylhexyl salicylate", "옥티살레이트", "118-60-5"],
191
+ "EU": {"status": "allowed", "limit": 5, "formula_text": "배합한도: 5%"},
192
+ "FDA": {"status": "allowed", "limit": 5, "formula_text": "배합한도: 5%"},
193
+ "KOREA": {"status": "allowed", "limit": 5, "formula_text": "배합한도: 5%"},
194
+ "JAPAN": {"status": "allowed", "limit": 5, "formula_text": "배합한도: 5%"},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  },
196
  "avobenzone": {
197
  "label": "Avobenzone",
198
  "aliases": ["avobenzone", "butyl methoxydibenzoylmethane", "아보벤존", "70356-09-1"],
199
+ "EU": {"status": "allowed", "limit": 5, "formula_text": "배합한도: 5%"},
200
+ "FDA": {"status": "allowed", "limit": 3, "formula_text": "배합한도: 3%"},
201
+ "KOREA": {"status": "allowed", "limit": 5, "formula_text": "배합한도: 5%"},
 
 
 
 
 
 
 
 
 
 
 
 
202
  },
203
  }
204
 
 
206
  "phenoxyethanol": {
207
  "label": "Phenoxyethanol",
208
  "aliases": ["phenoxyethanol", "페녹시에탄올", "122-99-6"],
209
+ "EU": {"status": "allowed", "limit": 1, "formula_text": "배합한도: 1%"},
210
+ "KOREA": {"status": "allowed", "limit": 1, "formula_text": "배합한도: 1%"},
211
+ "JAPAN": {"status": "allowed", "limit": 1, "formula_text": "배합한도: 1%"},
 
 
 
 
 
 
 
 
 
 
 
 
212
  },
213
  }
214
 
 
290
  text = re.sub(r"\s+", " ", text).strip()
291
 
292
  mapping = {
293
+ "한국": "KOREA", "KOREA": "KOREA", "KR": "KOREA",
294
+ "EU": "EU", "E.U.": "EU", "EUROPE": "EU", "유럽": "EU",
295
+ "EU FUTURE": "EU_FUTURE", "EU (FUTURE)": "EU_FUTURE",
296
+ "JAPAN": "JAPAN", "JP": "JAPAN", "일본": "JAPAN",
297
+ "CHINA": "CHINA", "CN": "CHINA", "중국": "CHINA",
298
+ "USA": "FDA", "US": "FDA", "미국": "FDA", "FDA": "FDA",
299
+ "ASEAN": "ASEAN", "아세안": "ASEAN",
300
+ "UK": "UK", "UNITED KINGDOM": "UK", "영국": "UK",
301
+ "SEPHORA": "SEPHORA", "TARGET": "TARGET", "ULTA": "ULTA",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
  }
303
 
304
  return mapping.get(text, text)
 
385
  texts = [
386
  component.get("한글 성분명", ""),
387
  component.get("INCI Name", ""),
388
+ component.get("CAS.No", ""),
389
+ component.get("FUNCTION", ""),
390
  material.get("Trade name(국문)", ""),
391
  material.get("Trade name(영문)", ""),
 
392
  ]
393
 
394
  return normalize_text(" ".join([safe_str(x) for x in texts if safe_str(x)]))
 
406
  return None
407
 
408
 
409
+ def is_plain_fragrance_component(material, component):
410
+ texts = [
411
+ component.get("한글 성분명", ""),
412
+ component.get("INCI Name", ""),
413
+ component.get("FUNCTION", ""),
414
+ material.get("Trade name(국문)", ""),
415
+ material.get("Trade name(영문)", ""),
416
+ ]
417
+
418
+ compact = normalize_compact(" ".join([safe_str(x) for x in texts if safe_str(x)]))
419
+
420
+ fragrance_words = [
421
+ "향료",
422
+ "fragrance",
423
+ "parfum",
424
+ "perfume",
425
+ "aroma",
426
+ ]
427
+
428
+ return any(normalize_compact(w) in compact for w in fragrance_words)
429
+
430
+
431
+ def evaluate_plain_fragrance_rule(country, material, component):
432
+ if not is_plain_fragrance_component(material, component):
433
+ return None
434
+
435
+ return {
436
+ "대표 INCI": safe_str(component.get("INCI Name", "")) or "Fragrance",
437
+ "결과": f"향료 / {display_country(country)} 알레르겐 표시성분 및 세부 조성 확인 필요",
438
+ "표시문구": NEED_CHECK_TEXT,
439
+ "비고": "향료는 세부 구성성분 및 알레르겐 표시대상 여부 확인 필요. 자동 Pass 처리 금지.",
440
+ }
441
+
442
+
443
  def get_restricted_candidate_reason(material, component):
444
+ if is_plain_fragrance_component(material, component):
445
+ return "향료"
446
+
447
  uv_key = match_rule_key(material, component, UV_FILTER_RULES)
448
  if uv_key:
449
  return "UV 필터"
 
520
  if NEED_CHECK_TEXT in text:
521
  return NEED_CHECK_TEXT
522
 
523
+ if "향료" in text or "fragrance" in lower or "parfum" in lower:
524
+ return NEED_CHECK_TEXT
525
+
526
  if "octocrylene" in inci_norm or "옥토크릴렌" in inci_norm:
527
  if country_col == "EU":
528
  return "배합 한도:\n스프레이: 9% /\n기타제품: 10%"
 
1213
 
1214
 
1215
  def extract_terms_for_live_lookup(row_items):
1216
+ """
1217
+ 식약처 실시간 조회용 검색어 추출.
1218
+ Water, Glycerin 같은 일반 성분은 제외하고,
1219
+ UV 필터/보존제/기능성/제한 가능성 성분을 우선 조회한다.
1220
+ """
1221
+
1222
+ skip_words = {
1223
+ "water", "aqua", "정제수",
1224
+ "glycerin", "글리세린",
1225
+ "butylene glycol", "부틸렌글라이콜",
1226
+ "dipropylene glycol", "다이프로필렌글라이콜",
1227
+ "1,2-hexanediol", "1,2-헥산다이올",
1228
+ "xanthan gum", "잔탄검",
1229
+ "cellulose", "셀룰로오스",
1230
+ "silica", "실리카",
1231
+ "arginine", "알지닌",
1232
+ "sodium hyaluronate", "소듐하이알루로네이트",
1233
+ "ethylhexylglycerin", "에틸헥실글리세린",
1234
+ }
1235
+
1236
+ priority_terms = []
1237
+ normal_terms = []
1238
 
1239
  for item in row_items:
1240
+ material = item["material"]
1241
  comp = item["component"]
1242
+
1243
+ high_risk_reason = get_restricted_candidate_reason(material, comp)
1244
+
1245
+ if is_plain_fragrance_component(material, comp):
1246
+ continue
1247
+
1248
+ candidate_values = [
1249
+ comp.get("INCI Name", ""),
1250
+ comp.get("한글 성분명", ""),
1251
+ comp.get("CAS.No", ""),
1252
+ ]
1253
+
1254
+ for value in candidate_values:
1255
  value = safe_str(value)
1256
+
1257
+ if not value or value == "-":
1258
+ continue
1259
+
1260
+ key = normalize_compact(value)
1261
+
1262
+ if len(key) < 3:
1263
+ continue
1264
+
1265
+ is_skip = any(normalize_compact(w) == key for w in skip_words)
1266
+
1267
+ if is_skip and not high_risk_reason:
1268
+ continue
1269
+
1270
+ if high_risk_reason:
1271
+ priority_terms.append(value)
1272
+ else:
1273
+ normal_terms.append(value)
1274
+
1275
+ merged = priority_terms + normal_terms
1276
 
1277
  seen = set()
1278
  unique = []
1279
 
1280
+ for term in merged:
1281
  key = normalize_compact(term)
1282
+
1283
  if key and key not in seen:
1284
  seen.add(key)
1285
  unique.append(term)
 
1524
 
1525
  with sync_playwright() as p:
1526
  browser = p.chromium.launch(
1527
+ headless=True,
1528
+ args=[
1529
+ "--no-sandbox",
1530
+ "--disable-setuid-sandbox",
1531
+ "--disable-dev-shm-usage",
1532
+ "--disable-gpu",
1533
+ "--disable-software-rasterizer",
1534
+ "--disable-extensions",
1535
+ "--disable-background-networking",
1536
+ "--disable-default-apps",
1537
+ "--disable-sync",
1538
+ "--metrics-recording-only",
1539
+ "--mute-audio",
1540
+ ],
1541
+ )
1542
+
1543
  context = browser.new_context(
1544
+ viewport={"width": 1280, "height": 900},
1545
+ user_agent=(
1546
+ "Mozilla/5.0 (X11; Linux x86_64) "
1547
+ "AppleWebKit/537.36 (KHTML, like Gecko) "
1548
+ "Chrome/120.0.0.0 Safari/537.36"
1549
+ ),
1550
+ ignore_https_errors=True,
1551
  )
1552
+
1553
  page = context.new_page()
1554
 
1555
  for idx, term in enumerate(terms, start=1):
1556
  try:
1557
  print(f"MFDS 실시간 조회 {idx}/{len(terms)}: {term}")
1558
 
1559
+ goto_success = False
1560
+ last_goto_error = ""
1561
+
1562
+ for attempt in range(3):
1563
+ try:
1564
+ page.goto(
1565
+ MFDS_LIVE_URL,
1566
+ wait_until="domcontentloaded",
1567
+ timeout=45000,
1568
+ )
1569
+ page.wait_for_timeout(3000)
1570
+ goto_success = True
1571
+ break
1572
+ except Exception as e:
1573
+ last_goto_error = str(e)
1574
+ page.wait_for_timeout(3000)
1575
+
1576
+ if not goto_success:
1577
+ local_errors.append(f"{term}: 식약처 접속 실패: {last_goto_error}")
1578
+ continue
1579
 
1580
  if not mfds_fill_search_input(page, term):
1581
  local_errors.append(f"{term}: 검색 입력창 찾기 실패")
 
1780
  ckey = country_key(country)
1781
  amount = component.get("amount_float")
1782
 
1783
+ plain_fragrance = evaluate_plain_fragrance_rule(country, material, component)
1784
+ if plain_fragrance is not None:
1785
+ return plain_fragrance
1786
+
1787
  uv_result = evaluate_limit_rule(country, material, component, UV_FILTER_RULES, "UV 필터")
1788
  if uv_result is not None:
1789
  return uv_result
 
1818
  if not matched:
1819
  continue
1820
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1821
  return {
1822
  "대표 INCI": rule["label"],
1823
+ "결과": f"향료 알레르겐 / {rule['label']} / {display_country(country)} 표시기준 확인 필요",
1824
+ "표시문구": NEED_CHECK_TEXT,
1825
+ "비고": "향료 알레르겐 후보. 세부 표시기준 및 제품 유형 확인 필요.",
1826
  }
1827
 
1828
  if amount is None:
 
2071
  결과:
2072
  표시문구:
2073
  비고:
 
 
 
 
 
 
 
2074
  """
2075
 
2076
  try:
 
2131
  }
2132
 
2133
  results[item["target_id"]] = result
2134
+ log_search_context(item["target_id"], country, comp, result["결과"], "NO_DB", "해당 국가/채널 규제 DB 없음")
 
 
 
 
 
 
 
2135
 
2136
  return results
2137
 
 
2196
 
2197
  results[item["target_id"]] = result
2198
  EVAL_CACHE[make_eval_cache_key(country, comp)] = result
2199
+ log_search_context(item["target_id"], country, comp, result["결과"], "NO_MEANINGFUL_HIT", context)
 
 
 
 
 
 
 
2200
 
2201
  uncached_targets = filtered_targets
2202
 
 
2717
  gpt_targets = []
2718
 
2719
  for item in row_items:
2720
+ fragrance_result = evaluate_plain_fragrance_rule(
2721
+ country=country,
2722
+ material=item["material"],
2723
+ component=item["component"],
2724
+ )
2725
+
2726
+ if fragrance_result is not None:
2727
+ item["row_data"][col_name] = fragrance_result.get("결과", "")
2728
+ item["row_data"][col_name + "_display"] = fragrance_result.get("표시문구", NEED_CHECK_TEXT)
2729
+
2730
+ note = safe_str(fragrance_result.get("비고", "-"))
2731
+ if note and note != "-":
2732
+ item["notes"].append(f"{col_name}: {note}")
2733
+
2734
+ log_search_context(
2735
+ item["target_id"],
2736
+ country,
2737
+ item["component"],
2738
+ fragrance_result.get("결과", ""),
2739
+ "FRAGRANCE_RULE",
2740
+ note,
2741
+ )
2742
+ continue
2743
+
2744
  mfds_result = None
2745
 
2746
  if use_mfds_live and mfds_df is not None and not mfds_df.empty: