jin2li commited on
Commit
bccb076
ยท
verified ยท
1 Parent(s): 31ccc3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +243 -78
app.py CHANGED
@@ -13,15 +13,15 @@
13
  # - Gradio ๋กœ๊ทธ์ธ ์ธ์ฆ / public share link ์ ์šฉ
14
  # - MergedCell column_letter ์˜ค๋ฅ˜ ์ˆ˜์ • ์™„๋ฃŒ
15
  # ============================================================
16
-
17
  # ============================================================
18
  # reBom Regulatory Screening AI
19
  # - ๊ตญ๊ฐ€๋ณ„ ๊ทœ์ œ ํด๋” ์•ˆ์—์„œ๋งŒ ๊ฒ€์ƒ‰
20
  # - FAISS ๋””์Šคํฌ ์บ์‹œ
21
  # - GPT๋Š” ๊ฒ€์ƒ‰๋œ ์›๋ฌธ ์•ˆ์—์„œ๋งŒ ํŒ์ •
22
  # - ์‹์•ฝ์ฒ˜ ์‚ฌ์ดํŠธ ์‹ค์‹œ๊ฐ„ ์กฐํšŒ ์˜ต์…˜
23
- # - Playwright Chromium ์ž๋™ ์„ค์น˜ ์žฌ์‹œ๋„
24
- # - Formular Ingredients Statement ์›๋ณธ ์–‘์‹ ์ถœ๋ ฅ
 
25
  # - ์›๋ณธ TOTAL ํ–‰ ์ œ๊ฑฐ ํ›„ ์ƒˆ TOTAL ํ–‰ 1๊ฐœ๋งŒ ์ƒ์„ฑ
26
  # ============================================================
27
 
@@ -72,9 +72,11 @@ OUTPUT_DIR = (BASE_DIR / "outputs").resolve()
72
  OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
73
 
74
  FAISS_CACHE_DIR = ".faiss_cache"
75
-
76
  MFDS_LIVE_URL = "https://nedrug.mfds.go.kr/pbp/CCBDF01"
 
77
  NO_EVIDENCE_TEXT = "ํ•ด๋‹น ์ž๋ฃŒ ๋‚ด ์ œํ•œ ๊ทผ๊ฑฐ ์—†์Œ"
 
 
78
 
79
  VECTOR_DB_CACHE = {}
80
  EVAL_CACHE = {}
@@ -192,6 +194,11 @@ UV_FILTER_RULES = {
192
  "homosalate": {
193
  "label": "Homosalate",
194
  "aliases": ["homosalate", "ํ˜ธ๋ชจ์‚ด๋ ˆ์ดํŠธ", "118-56-9"],
 
 
 
 
 
195
  "EU": {
196
  "status": "allowed",
197
  "limit": 7.34,
@@ -473,6 +480,7 @@ def get_identity_text(material, component):
473
  component.get("INCI Name", ""),
474
  material.get("Trade name(๊ตญ๋ฌธ)", ""),
475
  material.get("Trade name(์˜๋ฌธ)", ""),
 
476
  ]
477
 
478
  return normalize_text(" ".join([safe_str(x) for x in texts if safe_str(x)]))
@@ -490,6 +498,40 @@ def match_rule_key(material, component, rule_dict):
490
  return None
491
 
492
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
493
  def is_country_result_issue(text):
494
  text = safe_str(text)
495
 
@@ -499,6 +541,7 @@ def is_country_result_issue(text):
499
  keywords = [
500
  "๋ฐฐํ•ฉ๊ธˆ์ง€", "๊ธˆ์ง€", "์ดˆ๊ณผ", "๋ถ€์ ํ•ฉ", "์žฌ๊ฒ€ํ† ", "ํ™•์ธ ํ•„์š”",
501
  "์ž๋ฃŒ ํ™•์ธ", "ํ‘œ์‹œ ํ•„์š”", "๋ผ๋ฒจ๋ง", "๋ถˆ๊ฐ€", "์ฃผ์˜", "๊ฒฝ๊ณ ",
 
502
  ]
503
 
504
  return any(k in text for k in keywords)
@@ -526,6 +569,12 @@ def normalize_formula_country_text(text, country_col="", inci_name="", amount_te
526
 
527
  lower = text.lower()
528
 
 
 
 
 
 
 
529
  if "octocrylene" in inci_norm or "์˜ฅํ† ํฌ๋ฆด๋ Œ" in inci_norm:
530
  if country_col == "EU":
531
  return "๋ฐฐํ•ฉ ํ•œ๋„:\n์Šคํ”„๋ ˆ์ด: 9% /\n๊ธฐํƒ€์ œํ’ˆ: 10%"
@@ -535,6 +584,8 @@ def normalize_formula_country_text(text, country_col="", inci_name="", amount_te
535
  return "๋ฐฐํ•ฉํ•œ๋„: 10%"
536
 
537
  if "homosalate" in inci_norm or "ํ˜ธ๋ชจ์‚ด๋ ˆ์ดํŠธ" in inci_norm:
 
 
538
  if country_col == "EU":
539
  return "๋ฐฐํ•ฉํ•œ๋„: 7.34%"
540
  if country_col == "FDA":
@@ -568,7 +619,7 @@ def normalize_formula_country_text(text, country_col="", inci_name="", amount_te
568
  return "๋ฐฐํ•ฉํ•œ๋„: " + percent_match.group(1).replace(" ", "")
569
 
570
  if "ํ™•์ธ ํ•„์š”" in text or "์ž๋ฃŒ ํ™•์ธ" in text or "์žฌ๊ฒ€ํ† " in text or "๊ฒ€ํ†  ํ•„์š”" in text:
571
- return "ํ™•์ธ ํ•„์š”"
572
 
573
  if "์ด๋‚ด" in text or "ํ†ต๊ณผ" in text or "ํ•œ๋„ ์ด๋‚ด" in text:
574
  return "Pass"
@@ -1551,6 +1602,7 @@ def ingredient_matches_live_row(material, component, row):
1551
  identity_values = [
1552
  component.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""),
1553
  component.get("INCI Name", ""),
 
1554
  material.get("Trade name(๊ตญ๋ฌธ)", ""),
1555
  material.get("Trade name(์˜๋ฌธ)", ""),
1556
  ]
@@ -1578,6 +1630,8 @@ def live_row_country_matches(country, row_country):
1578
  aliases += ["๋ฏธ๊ตญ", "USA", "US", "United States", "FDA"]
1579
  elif col == "EU":
1580
  aliases += ["EU", "์œ ๋Ÿฝ", "์œ ๋Ÿฝ์—ฐํ•ฉ", "European Union", "Europe"]
 
 
1581
 
1582
  aliases_norm = [normalize_compact(x) for x in aliases if safe_str(x)]
1583
  return any(alias and alias in row_country_norm for alias in aliases_norm)
@@ -1633,13 +1687,18 @@ def evaluate_limit_rule(country, material, component, rule_group, rule_type_name
1633
 
1634
  rule = rule_group[key]
1635
  country_rule = rule.get(ckey)
1636
-
1637
- if not country_rule:
1638
- return None
1639
-
1640
  label = rule.get("label", key)
1641
  amount = component.get("amount_float")
1642
  amount_text = format_percent(amount) if amount is not None else "ํ•จ๋Ÿ‰ ํ™•์ธ ํ•„์š”"
 
 
 
 
 
 
 
 
 
1643
  status = country_rule.get("status", "allowed")
1644
  formula_text = country_rule.get("formula_text", "")
1645
 
@@ -1656,21 +1715,23 @@ def evaluate_limit_rule(country, material, component, rule_group, rule_type_name
1656
  if limit is not None:
1657
  if amount is not None and amount > limit:
1658
  result_text = f"{rule_type_name} / {label} ํ˜„์žฌ ํ•จ๋Ÿ‰ {amount_text}%, ํ•œ๋„ {format_percent(limit)}% ์ดˆ๊ณผ(์žฌ๊ฒ€ํ†  ํ•„์š”)"
 
1659
  else:
1660
- result_text = f"{rule_type_name} / {label} ํ˜„์žฌ ํ•จ๋Ÿ‰ {amount_text}%, ํ•œ๋„ {format_percent(limit)}% ์ด๋‚ด(ํ†ต๊ณผ)"
 
1661
 
1662
  return {
1663
  "๋Œ€ํ‘œ INCI": label,
1664
  "๊ฒฐ๊ณผ": result_text,
1665
- "ํ‘œ์‹œ๋ฌธ๊ตฌ": formula_text or f"๋ฐฐํ•ฉํ•œ๋„: {format_percent(limit)}%",
1666
  "๋น„๊ณ ": "-",
1667
  }
1668
 
1669
  return {
1670
  "๋Œ€ํ‘œ INCI": label,
1671
- "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
1672
- "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
1673
- "๋น„๊ณ ": "-",
1674
  }
1675
 
1676
 
@@ -1713,7 +1774,12 @@ def evaluate_local_rules(country, material, component, ingredient_totals, ingred
1713
  continue
1714
 
1715
  if ckey not in ["EU", "EU_FUTURE", "UK", "KOREA"]:
1716
- continue
 
 
 
 
 
1717
 
1718
  total_amount = ingredient_totals.get(fragrance_key, amount)
1719
  total_text = format_percent(total_amount) if total_amount is not None else "ํ•จ๋Ÿ‰ ํ™•์ธ ํ•„์š”"
@@ -1786,7 +1852,7 @@ def clean_json_text(text):
1786
  return text
1787
 
1788
 
1789
- def sanitize_country_result(parsed, country_col="", component=None):
1790
  if not isinstance(parsed, dict):
1791
  parsed = {}
1792
 
@@ -1798,6 +1864,11 @@ def sanitize_country_result(parsed, country_col="", component=None):
1798
 
1799
  display_text = safe_str(parsed.get("ํ‘œ์‹œ๋ฌธ๊ตฌ", ""))
1800
 
 
 
 
 
 
1801
  if not display_text:
1802
  display_text = normalize_formula_country_text(
1803
  result_text,
@@ -1813,7 +1884,7 @@ def sanitize_country_result(parsed, country_col="", component=None):
1813
 
1814
  if any(token in result_text for token in bad_tokens):
1815
  result_text = "ํ™•์ธ ํ•„์š” / ๊ทœ์ œ ์„ธ๋ถ€ ๊ณ„์‚ฐ ์žฌํ™•์ธ ํ•„์š”"
1816
- display_text = "ํ™•์ธ ํ•„์š”"
1817
 
1818
  if note == "-":
1819
  note = "๊ตฌ์ฒด ํ•œ๋„ ๋˜๋Š” ์ด๋Ÿ‰ ๊ณ„์‚ฐ๊ฐ’ ํ™•์ธ ํ•„์š”"
@@ -1836,6 +1907,7 @@ def make_eval_cache_key(country, component):
1836
  str(db_signature),
1837
  safe_str(component.get("INCI Name", "")).lower(),
1838
  safe_str(component.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", "")).lower(),
 
1839
  amount_text,
1840
  )
1841
 
@@ -1867,19 +1939,30 @@ def evaluate_component_with_llm(country, material, component, llm, target_id="")
1867
 
1868
  inci_name = safe_str(component.get("INCI Name", ""))
1869
  korean_name = safe_str(component.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""))
 
1870
  amount = component.get("amount_float")
1871
  amount_text = format_percent(amount) if amount is not None else "ํ•จ๋Ÿ‰ ํ™•์ธ ํ•„์š”"
 
1872
 
1873
  if not inci_name and not korean_name:
1874
  return {"๋Œ€ํ‘œ INCI": "-", "๊ฒฐ๊ณผ": "", "ํ‘œ์‹œ๋ฌธ๊ตฌ": "", "๋น„๊ณ ": "-"}
1875
 
1876
  if not db:
1877
- result = {
1878
- "๋Œ€ํ‘œ INCI": inci_name or "-",
1879
- "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
1880
- "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
1881
- "๋น„๊ณ ": "-",
1882
- }
 
 
 
 
 
 
 
 
 
1883
  log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "NO_DB", "ํ•ด๋‹น ๊ตญ๊ฐ€/์ฑ„๋„ ๊ทœ์ œ DB ์—†์Œ")
1884
  return result
1885
 
@@ -1896,7 +1979,8 @@ def evaluate_component_with_llm(country, material, component, llm, target_id="")
1896
  ์›๋ฃŒ๋ช… ๊ตญ๋ฌธ: {trade_ko}
1897
  ์›๋ฃŒ๋ช… ์˜๋ฌธ: {trade_en}
1898
  ๊ฒ€ํ†  ์„ฑ๋ถ„ ๊ตญ๋ฌธ: {korean_name}
1899
- ๊ฒ€ํ†  ์„ฑ๋ถ„ INCI/CAS: {inci_name}
 
1900
  ์ตœ์ข… ์ œํ’ˆ ๋‚ด ํ•จ๋Ÿ‰: {amount_text}%
1901
  ์ œํ’ˆ์œ ํ˜•: Leave-on ๋ฐ Wash-off ๊ธฐ์ค€ ๋ชจ๋‘ ํ™•์ธ
1902
  """
@@ -1904,17 +1988,26 @@ def evaluate_component_with_llm(country, material, component, llm, target_id="")
1904
  has_hit, pre_context = has_meaningful_search_hit(
1905
  db=db,
1906
  search_text=search_text,
1907
- ingredient_names=[inci_name, korean_name],
1908
  k=MEANINGFUL_HIT_K,
1909
  )
1910
 
1911
  if not has_hit:
1912
- result = {
1913
- "๋Œ€ํ‘œ INCI": inci_name or "-",
1914
- "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
1915
- "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
1916
- "๋น„๊ณ ": "-",
1917
- }
 
 
 
 
 
 
 
 
 
1918
  EVAL_CACHE[cache_key] = result
1919
  log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "NO_MEANINGFUL_HIT", pre_context)
1920
  return result
@@ -1933,11 +2026,14 @@ def evaluate_component_with_llm(country, material, component, llm, target_id="")
1933
  - ๋‹ค๋ฅธ ๊ตญ๊ฐ€ ๊ทœ์ •์„ ํ˜„์žฌ ๊ตญ๊ฐ€์— ์ž„์˜ ์ ์šฉํ•˜์ง€ ๋งˆ.
1934
  - ๊ฒ€์ƒ‰ ์›๋ฌธ์— ๋ช…์‹œ๋˜์ง€ ์•Š์€ ์ œํ•œ, ๋ฐฐํ•ฉ๊ธˆ์ง€, ๋ฐฐํ•ฉํ•œ๋„๋Š” ๋งŒ๋“ค์ง€ ๋งˆ.
1935
  - ๊ฒ€์ƒ‰ ์›๋ฌธ์— ๋ช…์‹œ๋œ ์ œํ•œ/๊ธˆ์ง€/ํ•œ๋„ ๊ทผ๊ฑฐ๊ฐ€ ์—†์œผ๋ฉด ๊ฒฐ๊ณผ๋Š” ์ •ํ™•ํžˆ "{NO_EVIDENCE_TEXT}"์œผ๋กœ ์ž‘์„ฑํ•ด.
 
1936
 
1937
  [๊ฒ€ํ†  ์„ฑ๋ถ„]
1938
  ๊ตญ๋ฌธ๋ช…: {korean_name}
1939
- INCI/CAS: {inci_name}
 
1940
  ์ตœ์ข… ์ œํ’ˆ ๋‚ด ํ•จ๋Ÿ‰: {amount_text}%
 
1941
 
1942
  [๊ฒ€์ƒ‰๋œ {country} ๊ทœ์ œ ์›๋ฌธ]
1943
  {context}
@@ -1959,7 +2055,13 @@ INCI/CAS: {inci_name}
1959
  try:
1960
  response = llm.invoke(prompt).content
1961
  parsed = parse_country_response(response)
1962
- parsed = sanitize_country_result(parsed, country_col=country_col, component=component)
 
 
 
 
 
 
1963
  EVAL_CACHE[cache_key] = parsed
1964
  log_search_context(target_id, country, component, parsed["๊ฒฐ๊ณผ"], "GPT_SINGLE", context)
1965
  return parsed
@@ -1968,7 +2070,7 @@ INCI/CAS: {inci_name}
1968
  result = {
1969
  "๋Œ€ํ‘œ INCI": inci_name or "-",
1970
  "๊ฒฐ๊ณผ": "ํ™•์ธ ํ•„์š”",
1971
- "ํ‘œ๏ฟฝ๏ฟฝ๏ฟฝ๋ฌธ๊ตฌ": "ํ™•์ธ ํ•„์š”",
1972
  "๋น„๊ณ ": str(e),
1973
  }
1974
  log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "GPT_SINGLE_ERROR", str(e))
@@ -1987,16 +2089,35 @@ def evaluate_components_with_llm_batch(country, targets, llm):
1987
  if not db:
1988
  for item in targets:
1989
  comp = item["component"]
 
1990
  inci_name = safe_str(comp.get("INCI Name", ""))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1991
 
1992
- results[item["target_id"]] = {
1993
- "๋Œ€ํ‘œ INCI": inci_name or "-",
1994
- "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
1995
- "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
1996
- "๋น„๊ณ ": "-",
1997
- }
1998
-
1999
- log_search_context(item["target_id"], country, comp, NO_EVIDENCE_TEXT, "NO_DB", "ํ•ด๋‹น ๊ตญ๊ฐ€/์ฑ„๋„ ๊ทœ์ œ DB ์—†์Œ")
 
2000
 
2001
  return results
2002
 
@@ -2019,37 +2140,56 @@ def evaluate_components_with_llm_batch(country, targets, llm):
2019
 
2020
  inci_name = safe_str(comp.get("INCI Name", ""))
2021
  korean_name = safe_str(comp.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""))
 
2022
  amount = comp.get("amount_float")
2023
  amount_text = format_percent(amount) if amount is not None else "ํ•จ๋Ÿ‰ ํ™•์ธ ํ•„์š”"
 
2024
 
2025
  search_text = f"""
2026
  ๊ตญ๊ฐ€/์ฑ„๋„: {country}
2027
  ์›๋ฃŒ๋ช… ๊ตญ๋ฌธ: {material.get("Trade name(๊ตญ๋ฌธ)", "")}
2028
  ์›๋ฃŒ๋ช… ์˜๋ฌธ: {material.get("Trade name(์˜๋ฌธ)", "")}
2029
  ๊ฒ€ํ†  ์„ฑ๋ถ„ ๊ตญ๋ฌธ: {korean_name}
2030
- ๊ฒ€ํ†  ์„ฑ๋ถ„ INCI/CAS: {inci_name}
 
2031
  ์ตœ์ข… ์ œํ’ˆ ๋‚ด ํ•จ๋Ÿ‰: {amount_text}%
2032
  """
2033
 
2034
  has_hit, context = has_meaningful_search_hit(
2035
  db=db,
2036
  search_text=search_text,
2037
- ingredient_names=[inci_name, korean_name],
2038
  k=MEANINGFUL_HIT_K,
2039
  )
2040
 
2041
  if has_hit:
2042
  filtered_targets.append(item)
2043
  else:
2044
- result = {
2045
- "๋Œ€ํ‘œ INCI": inci_name or "-",
2046
- "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
2047
- "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
2048
- "๋น„๊ณ ": "-",
2049
- }
 
 
 
 
 
 
 
 
 
2050
  results[item["target_id"]] = result
2051
  EVAL_CACHE[make_eval_cache_key(country, comp)] = result
2052
- log_search_context(item["target_id"], country, comp, result["๊ฒฐ๊ณผ"], "NO_MEANINGFUL_HIT", context)
 
 
 
 
 
 
 
2053
 
2054
  uncached_targets = filtered_targets
2055
 
@@ -2062,19 +2202,24 @@ def evaluate_components_with_llm_batch(country, targets, llm):
2062
 
2063
  for item in batch:
2064
  comp = item["component"]
 
2065
  inci_name = safe_str(comp.get("INCI Name", ""))
2066
  korean_name = safe_str(comp.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""))
 
2067
  amount = comp.get("amount_float")
2068
  amount_text = format_percent(amount) if amount is not None else "ํ•จ๋Ÿ‰ ํ™•์ธ ํ•„์š”"
 
2069
 
2070
  target_payload.append({
2071
  "target_id": item["target_id"],
2072
  "์„ฑ๋ถ„ ๊ตญ๋ฌธ๋ช…": korean_name,
2073
- "INCI/CAS": inci_name,
 
2074
  "์ตœ์ข… ์ œํ’ˆ ๋‚ด ํ•จ๋Ÿ‰(%)": amount_text,
 
2075
  })
2076
 
2077
- search_blocks.append(f"{inci_name} {korean_name} {amount_text}%")
2078
 
2079
  search_text = f"""
2080
  ๊ตญ๊ฐ€/์ฑ„๋„: {country}
@@ -2095,6 +2240,7 @@ def evaluate_components_with_llm_batch(country, targets, llm):
2095
  - ์•„๋ž˜ ๊ฒ€์ƒ‰ ์›๋ฌธ์€ "{country}" ํด๋”์—์„œ๋งŒ ๊ฒ€์ƒ‰๋œ ๊ทผ๊ฑฐ๋‹ค.
2096
  - ์™ธ๋ถ€ ์ง€์‹, ํ•™์Šต ์ง€์‹, ์ผ๋ฐ˜ ๊ทœ์ œ ์ง€์‹์„ ์‚ฌ์šฉํ•˜์ง€ ๋งˆ.
2097
  - ๊ฒ€์ƒ‰ ์›๋ฌธ์— ๊ทผ๊ฑฐ๊ฐ€ ์—†์œผ๋ฉด ๊ฒฐ๊ณผ๋Š” ์ •ํ™•ํžˆ "{NO_EVIDENCE_TEXT}"์œผ๋กœ ์ž‘์„ฑํ•ด.
 
2098
 
2099
  [๊ฒ€ํ†  ๋Œ€์ƒ JSON]
2100
  {json.dumps(target_payload, ensure_ascii=False, indent=2)}
@@ -2135,12 +2281,24 @@ def evaluate_components_with_llm_batch(country, targets, llm):
2135
  continue
2136
 
2137
  item_comp = None
 
 
2138
  for item in batch:
2139
  if item["target_id"] == target_id:
2140
  item_comp = item["component"]
 
2141
  break
2142
 
2143
- parsed_by_id[target_id] = sanitize_country_result(obj, country_col=country_col, component=item_comp or {})
 
 
 
 
 
 
 
 
 
2144
 
2145
  for item in batch:
2146
  target_id = item["target_id"]
@@ -2552,6 +2710,34 @@ def process(
2552
  gpt_targets = []
2553
 
2554
  for item in row_items:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2555
  local_result = evaluate_local_rules(
2556
  country=country,
2557
  material=item["material"],
@@ -2574,31 +2760,10 @@ def process(
2574
  item["component"],
2575
  local_result.get("๊ฒฐ๊ณผ", ""),
2576
  "LOCAL_RULE",
2577
- note if note and note != "-" else "๋กœ์ปฌ ๊ณ ์ • ๊ทœ์น™ ์šฐ์„  ํŒ์ •",
2578
  )
2579
  continue
2580
 
2581
- mfds_result = None
2582
-
2583
- if use_mfds_live and mfds_df is not None and not mfds_df.empty:
2584
- mfds_result = evaluate_live_detail_rule(
2585
- country=country,
2586
- material=item["material"],
2587
- component=item["component"],
2588
- live_df=mfds_df,
2589
- )
2590
-
2591
- if mfds_result is not None:
2592
- item["row_data"][col_name] = mfds_result.get("๊ฒฐ๊ณผ", "")
2593
- item["row_data"][col_name + "_display"] = mfds_result.get("ํ‘œ์‹œ๋ฌธ๊ตฌ", "ํ™•์ธ ํ•„์š”")
2594
-
2595
- note = safe_str(mfds_result.get("๋น„๊ณ ", "-"))
2596
- if note and note != "-":
2597
- item["notes"].append(f"{col_name}: {note}")
2598
-
2599
- log_search_context(item["target_id"], country, item["component"], mfds_result.get("๊ฒฐ๊ณผ", ""), "MFDS_LIVE", note)
2600
- continue
2601
-
2602
  gpt_targets.append({
2603
  "target_id": item["target_id"],
2604
  "material": item["material"],
@@ -2617,7 +2782,7 @@ def process(
2617
  result = {
2618
  "๋Œ€ํ‘œ INCI": safe_str(item["component"].get("INCI Name", "")) or "-",
2619
  "๊ฒฐ๊ณผ": "ํ™•์ธ ํ•„์š”",
2620
- "ํ‘œ์‹œ๋ฌธ๊ตฌ": "ํ™•์ธ ํ•„์š”",
2621
  "๋น„๊ณ ": "batch ๊ฒฐ๊ณผ ๋ˆ„๋ฝ",
2622
  }
2623
 
@@ -2832,4 +2997,4 @@ except TypeError:
2832
  auth=auth_fn,
2833
  allowed_paths=ALLOWED_PATHS,
2834
  blocked_paths=BLOCKED_PATHS,
2835
- )
 
13
  # - Gradio ๋กœ๊ทธ์ธ ์ธ์ฆ / public share link ์ ์šฉ
14
  # - MergedCell column_letter ์˜ค๋ฅ˜ ์ˆ˜์ • ์™„๋ฃŒ
15
  # ============================================================
 
16
  # ============================================================
17
  # reBom Regulatory Screening AI
18
  # - ๊ตญ๊ฐ€๋ณ„ ๊ทœ์ œ ํด๋” ์•ˆ์—์„œ๋งŒ ๊ฒ€์ƒ‰
19
  # - FAISS ๋””์Šคํฌ ์บ์‹œ
20
  # - GPT๋Š” ๊ฒ€์ƒ‰๋œ ์›๋ฌธ ์•ˆ์—์„œ๋งŒ ํŒ์ •
21
  # - ์‹์•ฝ์ฒ˜ ์‚ฌ์ดํŠธ ์‹ค์‹œ๊ฐ„ ์กฐํšŒ ์˜ต์…˜
22
+ # - COOS ์ œ๊ฑฐ
23
+ # - ๊ณ ์œ„ํ—˜ ์„ฑ๋ถ„ Pass ์ž๋™ ๋ฐฉ์ง€
24
+ # - Formular Ingredients Statement ์–‘์‹ ์ถœ๋ ฅ
25
  # - ์›๋ณธ TOTAL ํ–‰ ์ œ๊ฑฐ ํ›„ ์ƒˆ TOTAL ํ–‰ 1๊ฐœ๋งŒ ์ƒ์„ฑ
26
  # ============================================================
27
 
 
72
  OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
73
 
74
  FAISS_CACHE_DIR = ".faiss_cache"
 
75
  MFDS_LIVE_URL = "https://nedrug.mfds.go.kr/pbp/CCBDF01"
76
+
77
  NO_EVIDENCE_TEXT = "ํ•ด๋‹น ์ž๋ฃŒ ๋‚ด ์ œํ•œ ๊ทผ๊ฑฐ ์—†์Œ"
78
+ NEED_CHECK_TEXT = "ํ™•์ธ ํ•„์š”"
79
+ LIMIT_CHECK_TEXT = "๋ฐฐํ•ฉํ•œ๋„ ํ™•์ธ ํ•„์š”"
80
 
81
  VECTOR_DB_CACHE = {}
82
  EVAL_CACHE = {}
 
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,
 
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
  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 ํ•„ํ„ฐ"
505
+
506
+ preservative_key = match_rule_key(material, component, PRESERVATIVE_RULES)
507
+ if preservative_key:
508
+ return "๋ณด์กด์ œ/์ œํ•œ์„ฑ๋ถ„"
509
+
510
+ functional_key = match_rule_key(material, component, FUNCTIONAL_KOREA_RULES)
511
+ if functional_key:
512
+ return "๊ธฐ๋Šฅ์„ฑ ์„ฑ๋ถ„"
513
+
514
+ identity = get_identity_text(material, component)
515
+ for _, rule in FRAGRANCE_ALLERGEN_RULES.items():
516
+ for alias in rule.get("aliases", []):
517
+ alias_norm = normalize_text(alias)
518
+ if alias_norm and alias_norm in identity:
519
+ return "ํ–ฅ๋ฃŒ ์•Œ๋ ˆ๋ฅด๊ฒ"
520
+
521
+ function_text = normalize_text(component.get("FUNCTION", ""))
522
+ inci_text = normalize_text(component.get("INCI Name", ""))
523
+
524
+ high_risk_words = [
525
+ "sunscreen", "uv filter", "preservative", "colorant", "hair dye",
526
+ "retinol", "retinal", "retinyl", "salicylic acid",
527
+ ]
528
+
529
+ if any(w in function_text for w in high_risk_words) or any(w in inci_text for w in high_risk_words):
530
+ return "์ œํ•œ ๊ฐ€๋Šฅ์„ฑ ์„ฑ๋ถ„"
531
+
532
+ return ""
533
+
534
+
535
  def is_country_result_issue(text):
536
  text = safe_str(text)
537
 
 
541
  keywords = [
542
  "๋ฐฐํ•ฉ๊ธˆ์ง€", "๊ธˆ์ง€", "์ดˆ๊ณผ", "๋ถ€์ ํ•ฉ", "์žฌ๊ฒ€ํ† ", "ํ™•์ธ ํ•„์š”",
543
  "์ž๋ฃŒ ํ™•์ธ", "ํ‘œ์‹œ ํ•„์š”", "๋ผ๋ฒจ๋ง", "๋ถˆ๊ฐ€", "์ฃผ์˜", "๊ฒฝ๊ณ ",
544
+ "๋ฐฐํ•ฉํ•œ๋„ ํ™•์ธ ํ•„์š”",
545
  ]
546
 
547
  return any(k in text for k in keywords)
 
569
 
570
  lower = text.lower()
571
 
572
+ if LIMIT_CHECK_TEXT in text:
573
+ return LIMIT_CHECK_TEXT
574
+
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%"
 
584
  return "๋ฐฐํ•ฉํ•œ๋„: 10%"
585
 
586
  if "homosalate" in inci_norm or "ํ˜ธ๋ชจ์‚ด๋ ˆ์ดํŠธ" in inci_norm:
587
+ if country_col == "ASEAN":
588
+ return "๋ฐฐํ•ฉํ•œ๋„: 10%"
589
  if country_col == "EU":
590
  return "๋ฐฐํ•ฉํ•œ๋„: 7.34%"
591
  if country_col == "FDA":
 
619
  return "๋ฐฐํ•ฉํ•œ๋„: " + percent_match.group(1).replace(" ", "")
620
 
621
  if "ํ™•์ธ ํ•„์š”" in text or "์ž๋ฃŒ ํ™•์ธ" in text or "์žฌ๊ฒ€ํ† " in text or "๊ฒ€ํ†  ํ•„์š”" in text:
622
+ return NEED_CHECK_TEXT
623
 
624
  if "์ด๋‚ด" in text or "ํ†ต๊ณผ" in text or "ํ•œ๋„ ์ด๋‚ด" in text:
625
  return "Pass"
 
1602
  identity_values = [
1603
  component.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""),
1604
  component.get("INCI Name", ""),
1605
+ component.get("CAS.No", ""),
1606
  material.get("Trade name(๊ตญ๋ฌธ)", ""),
1607
  material.get("Trade name(์˜๋ฌธ)", ""),
1608
  ]
 
1630
  aliases += ["๋ฏธ๊ตญ", "USA", "US", "United States", "FDA"]
1631
  elif col == "EU":
1632
  aliases += ["EU", "์œ ๋Ÿฝ", "์œ ๋Ÿฝ์—ฐํ•ฉ", "European Union", "Europe"]
1633
+ elif col == "ASEAN":
1634
+ aliases += ["ASEAN", "์•„์„ธ์•ˆ"]
1635
 
1636
  aliases_norm = [normalize_compact(x) for x in aliases if safe_str(x)]
1637
  return any(alias and alias in row_country_norm for alias in aliases_norm)
 
1687
 
1688
  rule = rule_group[key]
1689
  country_rule = rule.get(ckey)
 
 
 
 
1690
  label = rule.get("label", key)
1691
  amount = component.get("amount_float")
1692
  amount_text = format_percent(amount) if amount is not None else "ํ•จ๋Ÿ‰ ํ™•์ธ ํ•„์š”"
1693
+
1694
+ if not country_rule:
1695
+ return {
1696
+ "๋Œ€ํ‘œ INCI": label,
1697
+ "๊ฒฐ๊ณผ": f"{rule_type_name} / {label} / {display_country(country)} ๋ฐฐํ•ฉํ•œ๋„ ์ž๋ฃŒ ํ™•์ธ ํ•„์š”",
1698
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": LIMIT_CHECK_TEXT,
1699
+ "๋น„๊ณ ": "๋กœ์ปฌ ์ œํ•œ์„ฑ๋ถ„ ๋ชฉ๋ก์—๋Š” ์žˆ์œผ๋‚˜ ํ•ด๋‹น ๊ตญ๊ฐ€ ํ•œ๋„๊ฐ’ ๋ฏธ๋“ฑ๋ก. Pass ์ฒ˜๋ฆฌ ๊ธˆ์ง€.",
1700
+ }
1701
+
1702
  status = country_rule.get("status", "allowed")
1703
  formula_text = country_rule.get("formula_text", "")
1704
 
 
1715
  if limit is not None:
1716
  if amount is not None and amount > limit:
1717
  result_text = f"{rule_type_name} / {label} ํ˜„์žฌ ํ•จ๋Ÿ‰ {amount_text}%, ํ•œ๋„ {format_percent(limit)}% ์ดˆ๊ณผ(์žฌ๊ฒ€ํ†  ํ•„์š”)"
1718
+ display_text = "ํ•œ๋„ ์ดˆ๊ณผ"
1719
  else:
1720
+ result_text = f"{rule_type_name} / {label} ํ˜„์žฌ ํ•จ๋Ÿ‰ {amount_text}%, ํ•œ๋„ {format_percent(limit)}% ์ด๋‚ด"
1721
+ display_text = formula_text or f"๋ฐฐํ•ฉํ•œ๋„: {format_percent(limit)}%"
1722
 
1723
  return {
1724
  "๋Œ€ํ‘œ INCI": label,
1725
  "๊ฒฐ๊ณผ": result_text,
1726
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": display_text,
1727
  "๋น„๊ณ ": "-",
1728
  }
1729
 
1730
  return {
1731
  "๋Œ€ํ‘œ INCI": label,
1732
+ "๊ฒฐ๊ณผ": f"{rule_type_name} / {label} / ํ•œ๋„๊ฐ’ ํ™•์ธ ํ•„์š”",
1733
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": LIMIT_CHECK_TEXT,
1734
+ "๋น„๊ณ ": "๋กœ์ปฌ ๊ทœ์น™์— ์„ฑ๋ถ„์€ ์žˆ์œผ๋‚˜ ํ•œ๋„๊ฐ’์ด ๋น„์–ด ์žˆ์Œ. Pass ์ฒ˜๋ฆฌ ๊ธˆ์ง€.",
1735
  }
1736
 
1737
 
 
1774
  continue
1775
 
1776
  if ckey not in ["EU", "EU_FUTURE", "UK", "KOREA"]:
1777
+ return {
1778
+ "๋Œ€ํ‘œ INCI": rule["label"],
1779
+ "๊ฒฐ๊ณผ": f"ํ–ฅ๋ฃŒ ์•Œ๋ ˆ๋ฅด๊ฒ / {rule['label']} / {display_country(country)} ํ‘œ์‹œ๊ธฐ์ค€ ์ž๋ฃŒ ํ™•์ธ ํ•„์š”",
1780
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
1781
+ "๋น„๊ณ ": "ํ–ฅ๋ฃŒ ์•Œ๋ ˆ๋ฅด๊ฒ ํ›„๋ณด์ด๋‚˜ ํ•ด๋‹น ๊ตญ๊ฐ€ ๊ธฐ์ค€ ๋ฏธ๋“ฑ๋ก. Pass ์ฒ˜๋ฆฌ ๊ธˆ์ง€.",
1782
+ }
1783
 
1784
  total_amount = ingredient_totals.get(fragrance_key, amount)
1785
  total_text = format_percent(total_amount) if total_amount is not None else "ํ•จ๋Ÿ‰ ํ™•์ธ ํ•„์š”"
 
1852
  return text
1853
 
1854
 
1855
+ def sanitize_country_result(parsed, country_col="", component=None, high_risk_reason=""):
1856
  if not isinstance(parsed, dict):
1857
  parsed = {}
1858
 
 
1864
 
1865
  display_text = safe_str(parsed.get("ํ‘œ์‹œ๋ฌธ๊ตฌ", ""))
1866
 
1867
+ if high_risk_reason and result_text == NO_EVIDENCE_TEXT:
1868
+ result_text = f"{high_risk_reason} / {representative} / {country_col} ์ œํ•œ ์—ฌ๋ถ€ ํ™•์ธ ํ•„์š”"
1869
+ display_text = NEED_CHECK_TEXT
1870
+ note = "๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด ์„ฑ๋ถ„์ด๋ฏ€๋กœ ๊ทผ๊ฑฐ ๋ฏธ๊ฒ€์ถœ๋งŒ์œผ๋กœ Pass ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์Œ"
1871
+
1872
  if not display_text:
1873
  display_text = normalize_formula_country_text(
1874
  result_text,
 
1884
 
1885
  if any(token in result_text for token in bad_tokens):
1886
  result_text = "ํ™•์ธ ํ•„์š” / ๊ทœ์ œ ์„ธ๋ถ€ ๊ณ„์‚ฐ ์žฌํ™•์ธ ํ•„์š”"
1887
+ display_text = NEED_CHECK_TEXT
1888
 
1889
  if note == "-":
1890
  note = "๊ตฌ์ฒด ํ•œ๋„ ๋˜๋Š” ์ด๋Ÿ‰ ๊ณ„์‚ฐ๊ฐ’ ํ™•์ธ ํ•„์š”"
 
1907
  str(db_signature),
1908
  safe_str(component.get("INCI Name", "")).lower(),
1909
  safe_str(component.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", "")).lower(),
1910
+ safe_str(component.get("CAS.No", "")).lower(),
1911
  amount_text,
1912
  )
1913
 
 
1939
 
1940
  inci_name = safe_str(component.get("INCI Name", ""))
1941
  korean_name = safe_str(component.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""))
1942
+ cas_no = safe_str(component.get("CAS.No", ""))
1943
  amount = component.get("amount_float")
1944
  amount_text = format_percent(amount) if amount is not None else "ํ•จ๋Ÿ‰ ํ™•์ธ ํ•„์š”"
1945
+ high_risk_reason = get_restricted_candidate_reason(material, component)
1946
 
1947
  if not inci_name and not korean_name:
1948
  return {"๋Œ€ํ‘œ INCI": "-", "๊ฒฐ๊ณผ": "", "ํ‘œ์‹œ๋ฌธ๊ตฌ": "", "๋น„๊ณ ": "-"}
1949
 
1950
  if not db:
1951
+ if high_risk_reason:
1952
+ result = {
1953
+ "๋Œ€ํ‘œ INCI": inci_name or korean_name or "-",
1954
+ "๊ฒฐ๊ณผ": f"{high_risk_reason} / {inci_name or korean_name} / {country_col} ์ œํ•œ ์—ฌ๋ถ€ ํ™•์ธ ํ•„์š”",
1955
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
1956
+ "๋น„๊ณ ": "ํ•ด๋‹น ๊ตญ๊ฐ€/์ฑ„๋„ ๊ทœ์ œ DB ์—†์Œ. ๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด์ด๋ฏ€๋กœ Pass ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์Œ.",
1957
+ }
1958
+ else:
1959
+ result = {
1960
+ "๋Œ€ํ‘œ INCI": inci_name or "-",
1961
+ "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
1962
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
1963
+ "๋น„๊ณ ": "-",
1964
+ }
1965
+
1966
  log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "NO_DB", "ํ•ด๋‹น ๊ตญ๊ฐ€/์ฑ„๋„ ๊ทœ์ œ DB ์—†์Œ")
1967
  return result
1968
 
 
1979
  ์›๋ฃŒ๋ช… ๊ตญ๋ฌธ: {trade_ko}
1980
  ์›๋ฃŒ๋ช… ์˜๋ฌธ: {trade_en}
1981
  ๊ฒ€ํ†  ์„ฑ๋ถ„ ๊ตญ๋ฌธ: {korean_name}
1982
+ ๊ฒ€ํ†  ์„ฑ๋ถ„ INCI: {inci_name}
1983
+ CAS.No: {cas_no}
1984
  ์ตœ์ข… ์ œํ’ˆ ๋‚ด ํ•จ๋Ÿ‰: {amount_text}%
1985
  ์ œํ’ˆ์œ ํ˜•: Leave-on ๋ฐ Wash-off ๊ธฐ์ค€ ๋ชจ๋‘ ํ™•์ธ
1986
  """
 
1988
  has_hit, pre_context = has_meaningful_search_hit(
1989
  db=db,
1990
  search_text=search_text,
1991
+ ingredient_names=[inci_name, korean_name, cas_no],
1992
  k=MEANINGFUL_HIT_K,
1993
  )
1994
 
1995
  if not has_hit:
1996
+ if high_risk_reason:
1997
+ result = {
1998
+ "๋Œ€ํ‘œ INCI": inci_name or korean_name or "-",
1999
+ "๊ฒฐ๊ณผ": f"{high_risk_reason} / {inci_name or korean_name} / {country_col} ์ œํ•œ ์—ฌ๋ถ€ ํ™•์ธ ํ•„์š”",
2000
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
2001
+ "๋น„๊ณ ": "๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด์ด๋‚˜ ๊ตญ๊ฐ€๋ณ„ ๊ทœ์ œํŒŒ์ผ์—์„œ ์ง์ ‘ ๊ทผ๊ฑฐ ๋ฏธ๊ฒ€์ถœ. Pass ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์Œ.",
2002
+ }
2003
+ else:
2004
+ result = {
2005
+ "๋Œ€ํ‘œ INCI": inci_name or "-",
2006
+ "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
2007
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
2008
+ "๋น„๊ณ ": "-",
2009
+ }
2010
+
2011
  EVAL_CACHE[cache_key] = result
2012
  log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "NO_MEANINGFUL_HIT", pre_context)
2013
  return result
 
2026
  - ๋‹ค๋ฅธ ๊ตญ๊ฐ€ ๊ทœ์ •์„ ํ˜„์žฌ ๊ตญ๊ฐ€์— ์ž„์˜ ์ ์šฉํ•˜์ง€ ๋งˆ.
2027
  - ๊ฒ€์ƒ‰ ์›๋ฌธ์— ๋ช…์‹œ๋˜์ง€ ์•Š์€ ์ œํ•œ, ๋ฐฐํ•ฉ๊ธˆ์ง€, ๋ฐฐํ•ฉํ•œ๋„๋Š” ๋งŒ๋“ค์ง€ ๋งˆ.
2028
  - ๊ฒ€์ƒ‰ ์›๋ฌธ์— ๋ช…์‹œ๋œ ์ œํ•œ/๊ธˆ์ง€/ํ•œ๋„ ๊ทผ๊ฑฐ๊ฐ€ ์—†์œผ๋ฉด ๊ฒฐ๊ณผ๋Š” ์ •ํ™•ํžˆ "{NO_EVIDENCE_TEXT}"์œผ๋กœ ์ž‘์„ฑํ•ด.
2029
+ - ๋‹จ, ๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด ์„ฑ๋ถ„์ด๋ฉด Pass๋ผ๊ณ  ๋‹จ์ •ํ•˜์ง€ ๋ง๊ณ  ํ™•์ธ ํ•„์š”๋กœ ํŒ๋‹จํ•  ์ˆ˜ ์žˆ๋‹ค.
2030
 
2031
  [๊ฒ€ํ†  ์„ฑ๋ถ„]
2032
  ๊ตญ๋ฌธ๋ช…: {korean_name}
2033
+ INCI: {inci_name}
2034
+ CAS.No: {cas_no}
2035
  ์ตœ์ข… ์ œํ’ˆ ๋‚ด ํ•จ๋Ÿ‰: {amount_text}%
2036
+ ๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด ์—ฌ๋ถ€: {high_risk_reason or "์•„๋‹˜"}
2037
 
2038
  [๊ฒ€์ƒ‰๋œ {country} ๊ทœ์ œ ์›๋ฌธ]
2039
  {context}
 
2055
  try:
2056
  response = llm.invoke(prompt).content
2057
  parsed = parse_country_response(response)
2058
+ parsed = sanitize_country_result(
2059
+ parsed,
2060
+ country_col=country_col,
2061
+ component=component,
2062
+ high_risk_reason=high_risk_reason,
2063
+ )
2064
+
2065
  EVAL_CACHE[cache_key] = parsed
2066
  log_search_context(target_id, country, component, parsed["๊ฒฐ๊ณผ"], "GPT_SINGLE", context)
2067
  return parsed
 
2070
  result = {
2071
  "๋Œ€ํ‘œ INCI": inci_name or "-",
2072
  "๊ฒฐ๊ณผ": "ํ™•์ธ ํ•„์š”",
2073
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
2074
  "๋น„๊ณ ": str(e),
2075
  }
2076
  log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "GPT_SINGLE_ERROR", str(e))
 
2089
  if not db:
2090
  for item in targets:
2091
  comp = item["component"]
2092
+ material = item["material"]
2093
  inci_name = safe_str(comp.get("INCI Name", ""))
2094
+ korean_name = safe_str(comp.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""))
2095
+ high_risk_reason = get_restricted_candidate_reason(material, comp)
2096
+
2097
+ if high_risk_reason:
2098
+ result = {
2099
+ "๋Œ€ํ‘œ INCI": inci_name or korean_name or "-",
2100
+ "๊ฒฐ๊ณผ": f"{high_risk_reason} / {inci_name or korean_name} / {country_col} ์ œํ•œ ์—ฌ๋ถ€ ํ™•์ธ ํ•„์š”",
2101
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
2102
+ "๋น„๊ณ ": "ํ•ด๋‹น ๊ตญ๊ฐ€/์ฑ„๋„ ๊ทœ์ œ DB ์—†์Œ. ๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด์ด๋ฏ€๋กœ Pass ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์Œ.",
2103
+ }
2104
+ else:
2105
+ result = {
2106
+ "๋Œ€ํ‘œ INCI": inci_name or "-",
2107
+ "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
2108
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
2109
+ "๋น„๊ณ ": "-",
2110
+ }
2111
 
2112
+ results[item["target_id"]] = result
2113
+ log_search_context(
2114
+ item["target_id"],
2115
+ country,
2116
+ comp,
2117
+ result["๊ฒฐ๊ณผ"],
2118
+ "NO_DB",
2119
+ "ํ•ด๋‹น ๊ตญ๊ฐ€/์ฑ„๋„ ๊ทœ์ œ DB ์—†์Œ",
2120
+ )
2121
 
2122
  return results
2123
 
 
2140
 
2141
  inci_name = safe_str(comp.get("INCI Name", ""))
2142
  korean_name = safe_str(comp.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""))
2143
+ cas_no = safe_str(comp.get("CAS.No", ""))
2144
  amount = comp.get("amount_float")
2145
  amount_text = format_percent(amount) if amount is not None else "ํ•จ๋Ÿ‰ ํ™•์ธ ํ•„์š”"
2146
+ high_risk_reason = get_restricted_candidate_reason(material, comp)
2147
 
2148
  search_text = f"""
2149
  ๊ตญ๊ฐ€/์ฑ„๋„: {country}
2150
  ์›๋ฃŒ๋ช… ๊ตญ๋ฌธ: {material.get("Trade name(๊ตญ๋ฌธ)", "")}
2151
  ์›๋ฃŒ๋ช… ์˜๋ฌธ: {material.get("Trade name(์˜๋ฌธ)", "")}
2152
  ๊ฒ€ํ†  ์„ฑ๋ถ„ ๊ตญ๋ฌธ: {korean_name}
2153
+ ๊ฒ€ํ†  ์„ฑ๋ถ„ INCI: {inci_name}
2154
+ CAS.No: {cas_no}
2155
  ์ตœ์ข… ์ œํ’ˆ ๋‚ด ํ•จ๋Ÿ‰: {amount_text}%
2156
  """
2157
 
2158
  has_hit, context = has_meaningful_search_hit(
2159
  db=db,
2160
  search_text=search_text,
2161
+ ingredient_names=[inci_name, korean_name, cas_no],
2162
  k=MEANINGFUL_HIT_K,
2163
  )
2164
 
2165
  if has_hit:
2166
  filtered_targets.append(item)
2167
  else:
2168
+ if high_risk_reason:
2169
+ result = {
2170
+ "๋Œ€ํ‘œ INCI": inci_name or korean_name or "-",
2171
+ "๊ฒฐ๊ณผ": f"{high_risk_reason} / {inci_name or korean_name} / {country_col} ์ œํ•œ ์—ฌ๋ถ€ ํ™•์ธ ํ•„์š”",
2172
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
2173
+ "๋น„๊ณ ": "๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด์ด๋‚˜ ๊ตญ๊ฐ€๋ณ„ ๊ทœ์ œํŒŒ์ผ์—์„œ ์ง์ ‘ ๊ทผ๊ฑฐ ๋ฏธ๊ฒ€์ถœ. Pass ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์Œ.",
2174
+ }
2175
+ else:
2176
+ result = {
2177
+ "๋Œ€ํ‘œ INCI": inci_name or "-",
2178
+ "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
2179
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
2180
+ "๋น„๊ณ ": "-",
2181
+ }
2182
+
2183
  results[item["target_id"]] = result
2184
  EVAL_CACHE[make_eval_cache_key(country, comp)] = result
2185
+ log_search_context(
2186
+ item["target_id"],
2187
+ country,
2188
+ comp,
2189
+ result["๊ฒฐ๊ณผ"],
2190
+ "NO_MEANINGFUL_HIT",
2191
+ context,
2192
+ )
2193
 
2194
  uncached_targets = filtered_targets
2195
 
 
2202
 
2203
  for item in batch:
2204
  comp = item["component"]
2205
+ material = item["material"]
2206
  inci_name = safe_str(comp.get("INCI Name", ""))
2207
  korean_name = safe_str(comp.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""))
2208
+ cas_no = safe_str(comp.get("CAS.No", ""))
2209
  amount = comp.get("amount_float")
2210
  amount_text = format_percent(amount) if amount is not None else "ํ•จ๋Ÿ‰ ํ™•์ธ ํ•„์š”"
2211
+ high_risk_reason = get_restricted_candidate_reason(material, comp)
2212
 
2213
  target_payload.append({
2214
  "target_id": item["target_id"],
2215
  "์„ฑ๋ถ„ ๊ตญ๋ฌธ๋ช…": korean_name,
2216
+ "INCI": inci_name,
2217
+ "CAS.No": cas_no,
2218
  "์ตœ์ข… ์ œํ’ˆ ๋‚ด ํ•จ๋Ÿ‰(%)": amount_text,
2219
+ "๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด": high_risk_reason or "์•„๋‹˜",
2220
  })
2221
 
2222
+ search_blocks.append(f"{inci_name} {korean_name} {cas_no} {amount_text}%")
2223
 
2224
  search_text = f"""
2225
  ๊ตญ๊ฐ€/์ฑ„๋„: {country}
 
2240
  - ์•„๋ž˜ ๊ฒ€์ƒ‰ ์›๋ฌธ์€ "{country}" ํด๋”์—์„œ๋งŒ ๊ฒ€์ƒ‰๋œ ๊ทผ๊ฑฐ๋‹ค.
2241
  - ์™ธ๋ถ€ ์ง€์‹, ํ•™์Šต ์ง€์‹, ์ผ๋ฐ˜ ๊ทœ์ œ ์ง€์‹์„ ์‚ฌ์šฉํ•˜์ง€ ๋งˆ.
2242
  - ๊ฒ€์ƒ‰ ์›๋ฌธ์— ๊ทผ๊ฑฐ๊ฐ€ ์—†์œผ๋ฉด ๊ฒฐ๊ณผ๋Š” ์ •ํ™•ํžˆ "{NO_EVIDENCE_TEXT}"์œผ๋กœ ์ž‘์„ฑํ•ด.
2243
+ - ๋‹จ, ๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด ์„ฑ๋ถ„์ด๋ฉด Pass๋ผ๊ณ  ๋‹จ์ •ํ•˜์ง€ ๋ง๊ณ  ํ™•์ธ ํ•„์š”๋กœ ํŒ๋‹จํ•  ์ˆ˜ ์žˆ๋‹ค.
2244
 
2245
  [๊ฒ€ํ†  ๋Œ€์ƒ JSON]
2246
  {json.dumps(target_payload, ensure_ascii=False, indent=2)}
 
2281
  continue
2282
 
2283
  item_comp = None
2284
+ item_material = None
2285
+
2286
  for item in batch:
2287
  if item["target_id"] == target_id:
2288
  item_comp = item["component"]
2289
+ item_material = item["material"]
2290
  break
2291
 
2292
+ high_risk_reason = ""
2293
+ if item_comp and item_material:
2294
+ high_risk_reason = get_restricted_candidate_reason(item_material, item_comp)
2295
+
2296
+ parsed_by_id[target_id] = sanitize_country_result(
2297
+ obj,
2298
+ country_col=country_col,
2299
+ component=item_comp or {},
2300
+ high_risk_reason=high_risk_reason,
2301
+ )
2302
 
2303
  for item in batch:
2304
  target_id = item["target_id"]
 
2710
  gpt_targets = []
2711
 
2712
  for item in row_items:
2713
+ mfds_result = None
2714
+
2715
+ if use_mfds_live and mfds_df is not None and not mfds_df.empty:
2716
+ mfds_result = evaluate_live_detail_rule(
2717
+ country=country,
2718
+ material=item["material"],
2719
+ component=item["component"],
2720
+ live_df=mfds_df,
2721
+ )
2722
+
2723
+ if mfds_result is not None:
2724
+ item["row_data"][col_name] = mfds_result.get("๊ฒฐ๊ณผ", "")
2725
+ item["row_data"][col_name + "_display"] = mfds_result.get("ํ‘œ์‹œ๋ฌธ๊ตฌ", NEED_CHECK_TEXT)
2726
+
2727
+ note = safe_str(mfds_result.get("๋น„๊ณ ", "-"))
2728
+ if note and note != "-":
2729
+ item["notes"].append(f"{col_name}: {note}")
2730
+
2731
+ log_search_context(
2732
+ item["target_id"],
2733
+ country,
2734
+ item["component"],
2735
+ mfds_result.get("๊ฒฐ๊ณผ", ""),
2736
+ "MFDS_LIVE",
2737
+ note,
2738
+ )
2739
+ continue
2740
+
2741
  local_result = evaluate_local_rules(
2742
  country=country,
2743
  material=item["material"],
 
2760
  item["component"],
2761
  local_result.get("๊ฒฐ๊ณผ", ""),
2762
  "LOCAL_RULE",
2763
+ note if note and note != "-" else "๋กœ์ปฌ ๊ทœ์น™ ํŒ์ •",
2764
  )
2765
  continue
2766
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2767
  gpt_targets.append({
2768
  "target_id": item["target_id"],
2769
  "material": item["material"],
 
2782
  result = {
2783
  "๋Œ€ํ‘œ INCI": safe_str(item["component"].get("INCI Name", "")) or "-",
2784
  "๊ฒฐ๊ณผ": "ํ™•์ธ ํ•„์š”",
2785
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
2786
  "๋น„๊ณ ": "batch ๊ฒฐ๊ณผ ๋ˆ„๋ฝ",
2787
  }
2788
 
 
2997
  auth=auth_fn,
2998
  allowed_paths=ALLOWED_PATHS,
2999
  blocked_paths=BLOCKED_PATHS,
3000
+ )