jin2li commited on
Commit
f1284ec
ยท
verified ยท
1 Parent(s): a543412

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +298 -270
app.py CHANGED
@@ -13,13 +13,17 @@
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๊ฐœ๋งŒ ์ƒ์„ฑ
@@ -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,50 @@ 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 +526,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%"
@@ -1268,17 +1222,42 @@ 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 +1502,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 +1758,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 +1796,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:
@@ -1959,20 +1950,20 @@ def evaluate_component_with_llm(country, material, component, llm, target_id="")
1959
  amount_text = format_percent(amount) if amount is not None else "ํ•จ๋Ÿ‰ ํ™•์ธ ํ•„์š”"
1960
  high_risk_reason = get_restricted_candidate_reason(material, component)
1961
 
1962
- if not inci_name and not korean_name:
1963
  return {"๋Œ€ํ‘œ INCI": "-", "๊ฒฐ๊ณผ": "", "ํ‘œ์‹œ๋ฌธ๊ตฌ": "", "๋น„๊ณ ": "-"}
1964
 
1965
  if not db:
1966
  if high_risk_reason:
1967
  result = {
1968
- "๋Œ€ํ‘œ INCI": inci_name or korean_name or "-",
1969
- "๊ฒฐ๊ณผ": f"{high_risk_reason} / {inci_name or korean_name} / {country_col} ์ œํ•œ ์—ฌ๋ถ€ ํ™•์ธ ํ•„์š”",
1970
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
1971
  "๋น„๊ณ ": "ํ•ด๋‹น ๊ตญ๊ฐ€/์ฑ„๋„ ๊ทœ์ œ DB ์—†์Œ. ๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด์ด๋ฏ€๋กœ Pass ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์Œ.",
1972
  }
1973
  else:
1974
  result = {
1975
- "๋Œ€ํ‘œ INCI": inci_name or "-",
1976
  "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
1977
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
1978
  "๋น„๊ณ ": "-",
@@ -2010,14 +2001,14 @@ CAS.No: {cas_no}
2010
  if not has_hit:
2011
  if high_risk_reason:
2012
  result = {
2013
- "๋Œ€ํ‘œ INCI": inci_name or korean_name or "-",
2014
- "๊ฒฐ๊ณผ": f"{high_risk_reason} / {inci_name or korean_name} / {country_col} ์ œํ•œ ์—ฌ๋ถ€ ํ™•์ธ ํ•„์š”",
2015
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
2016
  "๋น„๊ณ ": "๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด์ด๋‚˜ ๊ตญ๊ฐ€๋ณ„ ๊ทœ์ œํŒŒ์ผ์—์„œ ์ง์ ‘ ๊ทผ๊ฑฐ ๋ฏธ๊ฒ€์ถœ. Pass ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์Œ.",
2017
  }
2018
  else:
2019
  result = {
2020
- "๋Œ€ํ‘œ INCI": inci_name or "-",
2021
  "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
2022
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
2023
  "๋น„๊ณ ": "-",
@@ -2058,13 +2049,6 @@ CAS.No: {cas_no}
2058
  ๊ฒฐ๊ณผ:
2059
  ํ‘œ์‹œ๋ฌธ๊ตฌ:
2060
  ๋น„๊ณ :
2061
-
2062
- ํ‘œ์‹œ๋ฌธ๊ตฌ ์ž‘์„ฑ ๊ทœ์น™:
2063
- - ๋ฌธ์ œ ์—†์œผ๋ฉด "Pass"
2064
- - ๋ฐฐํ•ฉํ•œ๋„๊ฐ€ ์žˆ์œผ๋ฉด "๋ฐฐํ•ฉํ•œ๋„: 10%"์ฒ˜๋Ÿผ ์งง๊ฒŒ ์ž‘์„ฑ
2065
- - ์Šคํ”„๋ ˆ์ด/๊ธฐํƒ€์ œํ’ˆ์ฒ˜๋Ÿผ ์กฐ๊ฑด์ด ์žˆ์œผ๋ฉด ์ค„๋ฐ”๊ฟˆ์œผ๋กœ ์ž‘์„ฑ
2066
- - ๋ผ๋ฒจ ํ‘œ์‹œ๊ฐ€ ํ•„์š”ํ•˜๋ฉด "๋ผ๋ฒจ๋ง ํ•„์ˆ˜"
2067
- - ์ •ํ™•ํ•œ ํŒ๋‹จ์ด ์–ด๋ ค์šฐ๋ฉด "ํ™•์ธ ํ•„์š”"
2068
  """
2069
 
2070
  try:
@@ -2083,7 +2067,7 @@ CAS.No: {cas_no}
2083
 
2084
  except Exception as e:
2085
  result = {
2086
- "๋Œ€ํ‘œ INCI": inci_name or "-",
2087
  "๊ฒฐ๊ณผ": "ํ™•์ธ ํ•„์š”",
2088
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
2089
  "๋น„๊ณ ": str(e),
@@ -2107,32 +2091,26 @@ def evaluate_components_with_llm_batch(country, targets, llm):
2107
  material = item["material"]
2108
  inci_name = safe_str(comp.get("INCI Name", ""))
2109
  korean_name = safe_str(comp.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""))
 
2110
  high_risk_reason = get_restricted_candidate_reason(material, comp)
2111
 
2112
  if high_risk_reason:
2113
  result = {
2114
- "๋Œ€ํ‘œ INCI": inci_name or korean_name or "-",
2115
- "๊ฒฐ๊ณผ": f"{high_risk_reason} / {inci_name or korean_name} / {country_col} ์ œํ•œ ์—ฌ๋ถ€ ํ™•์ธ ํ•„์š”",
2116
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
2117
  "๋น„๊ณ ": "ํ•ด๋‹น ๊ตญ๊ฐ€/์ฑ„๋„ ๊ทœ์ œ DB ์—†์Œ. ๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด์ด๋ฏ€๋กœ Pass ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์Œ.",
2118
  }
2119
  else:
2120
  result = {
2121
- "๋Œ€ํ‘œ INCI": inci_name or "-",
2122
  "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
2123
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
2124
  "๋น„๊ณ ": "-",
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
 
@@ -2182,14 +2160,14 @@ CAS.No: {cas_no}
2182
  else:
2183
  if high_risk_reason:
2184
  result = {
2185
- "๋Œ€ํ‘œ INCI": inci_name or korean_name or "-",
2186
- "๊ฒฐ๊ณผ": f"{high_risk_reason} / {inci_name or korean_name} / {country_col} ์ œํ•œ ์—ฌ๋ถ€ ํ™•์ธ ํ•„์š”",
2187
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
2188
  "๋น„๊ณ ": "๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด์ด๋‚˜ ๊ตญ๊ฐ€๋ณ„ ๊ทœ์ œํŒŒ์ผ์—์„œ ์ง์ ‘ ๊ทผ๊ฑฐ ๋ฏธ๊ฒ€์ถœ. Pass ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์Œ.",
2189
  }
2190
  else:
2191
  result = {
2192
- "๋Œ€ํ‘œ INCI": inci_name or "-",
2193
  "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
2194
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
2195
  "๋น„๊ณ ": "-",
@@ -2197,14 +2175,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
 
@@ -2714,7 +2685,7 @@ def process(
2714
  mfds_df, mfds_live_msg = mfds_live_lookup_terms(
2715
  terms=terms,
2716
  max_terms=live_max_terms,
2717
- headless=live_headless,
2718
  )
2719
  except Exception as e:
2720
  mfds_df = pd.DataFrame()
@@ -2725,6 +2696,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:
@@ -2849,6 +2844,7 @@ def process(
2849
  f"- In formula ํ•ฉ๊ณ„: {format_amount(formula_total)}%\n"
2850
  f"- ์žฌ๊ฒ€ํ†  ํ•„์š” ์„ฑ๋ถ„: {len(regulatory_df)}๊ฐœ\n"
2851
  f"- MFDS ์ƒํƒœ: {mfds_live_msg}\n"
 
2852
  "- ๊ฒฐ๊ณผ ํŒŒ์ผ ์‹œํŠธ:\n"
2853
  " 1) Formula Ingredients Statement\n"
2854
  " 2) Regulatory Screening Summary\n"
@@ -2862,18 +2858,83 @@ def process(
2862
  print(tb)
2863
  return None, None, f"โŒ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}\n\n{tb[-3000:]}"
2864
 
2865
- # ============================================================
2866
  # ============================================================
2867
  # 11-1. ๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰
2868
  # ============================================================
2869
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2870
  def process_single_ingredient(
2871
  countries,
2872
- single_korean_name,
2873
- single_inci_name,
2874
- single_cas_no,
2875
- single_function,
2876
  single_amount,
 
2877
  use_mfds_live_single=False,
2878
  live_max_terms_single=3,
2879
  ):
@@ -2884,43 +2945,21 @@ def process_single_ingredient(
2884
  if not countries:
2885
  return pd.DataFrame(), "โŒ ๊ฒ€์ƒ‰ํ•  ๊ตญ๊ฐ€๋ฅผ ์„ ํƒํ•ด์ฃผ์„ธ์š”."
2886
 
2887
- if not safe_str(single_korean_name) and not safe_str(single_inci_name) and not safe_str(single_cas_no):
2888
- return pd.DataFrame(), "โŒ ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…, INCI Name, CAS.No ์ค‘ ํ•˜๋‚˜๋Š” ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
2889
-
2890
- amount_float = to_number(single_amount)
2891
- amount_text = format_amount(amount_float) if amount_float is not None else ""
2892
-
2893
- component = {
2894
- "ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…": safe_str(single_korean_name),
2895
- "INCI Name": safe_str(single_inci_name),
2896
- "FUNCTION": safe_str(single_function),
2897
- "CAS.No": safe_str(single_cas_no),
2898
- "SOURCE": "Manual Search",
2899
- "In formula(w/w %)": amount_text,
2900
- "amount_float": amount_float,
2901
- }
2902
-
2903
- material = {
2904
- "NO": "1",
2905
- "Trade name(๊ตญ๋ฌธ)": safe_str(single_korean_name),
2906
- "Trade name(์˜๋ฌธ)": safe_str(single_inci_name),
2907
- "Components": [component],
2908
- }
2909
 
2910
- row_items = [{
2911
- "target_id": "single_ingredient",
2912
- "material": material,
2913
- "component": component,
2914
- "row_data": {},
2915
- "notes": [],
2916
- }]
2917
 
2918
  llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
2919
 
2920
  mfds_df = pd.DataFrame()
2921
  mfds_live_msg = "์‚ฌ์šฉ ์•ˆ ํ•จ"
2922
 
2923
- terms = extract_terms_for_live_lookup(row_items)
2924
 
2925
  if use_mfds_live_single:
2926
  try:
@@ -2937,6 +2976,7 @@ def process_single_ingredient(
2937
  ingredient_amount_parts = defaultdict(list)
2938
 
2939
  identity = get_identity_text(material, component)
 
2940
 
2941
  if amount_float is not None:
2942
  for canonical, rule in FRAGRANCE_ALLERGEN_RULES.items():
@@ -3002,7 +3042,7 @@ def process_single_ingredient(
3002
  display_text = normalize_formula_country_text(
3003
  final_result.get("๊ฒฐ๊ณผ", ""),
3004
  country_col=country_col,
3005
- inci_name=component.get("INCI Name", ""),
3006
  amount_text=amount_text,
3007
  )
3008
 
@@ -3011,6 +3051,7 @@ def process_single_ingredient(
3011
  "ํ‘œ์‹œ ๊ฒฐ๊ณผ": display_text,
3012
  "์ƒ์„ธ ํŒ์ •": final_result.get("๊ฒฐ๊ณผ", ""),
3013
  "ํŒ์ • ์ถœ์ฒ˜": source,
 
3014
  "ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…": component.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""),
3015
  "INCI Name": component.get("INCI Name", ""),
3016
  "CAS.No": component.get("CAS.No", ""),
@@ -3032,7 +3073,7 @@ def process_single_ingredient(
3032
 
3033
  msg = (
3034
  "โœ… ๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰ ์™„๋ฃŒ\n"
3035
- f"- ๊ฒ€์ƒ‰ ์„ฑ๋ถ„: {safe_str(single_inci_name) or safe_str(single_korean_name) or safe_str(single_cas_no)}\n"
3036
  f"- ์„ ํƒ ๊ตญ๊ฐ€ ์ˆ˜: {len(countries)}๊ฐœ\n"
3037
  f"- MFDS ์ƒํƒœ: {mfds_live_msg}\n"
3038
  f"- MFDS ์กฐํšŒ ๋Œ€์ƒ: {', '.join(terms[:10]) if terms else '์—†์Œ'}\n"
@@ -3044,8 +3085,8 @@ def process_single_ingredient(
3044
  tb = traceback.format_exc()
3045
  print(tb)
3046
  return pd.DataFrame(), f"โŒ ๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰ ์˜ค๋ฅ˜: {str(e)}\n\n{tb[-3000:]}"
3047
-
3048
- # ============================================================
3049
  # ============================================================
3050
  # 12. Gradio UI
3051
  # ============================================================
@@ -3150,7 +3191,7 @@ with gr.Blocks(css=custom_css) as demo:
3150
 
3151
  with gr.Tab("๐Ÿ”Ž ๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰"):
3152
  gr.Markdown("## ๐Ÿ”Ž ๋‹จ์ผ ์„ฑ๋ถ„ ๊ทœ์ œ ๊ฒ€์ƒ‰")
3153
- gr.Markdown("์—‘์…€ ์—…๋กœ๋“œ ์—†์ด ๊ตญ๊ฐ€๋ฅผ ์„ ํƒํ•˜๊ณ  ์„ฑ๋ถ„ ํ•˜๋‚˜๋งŒ ์ž…๋ ฅํ•ด์„œ ๋ฐ”๋กœ ์Šคํฌ๋ฆฌ๋‹ํ•ฉ๋‹ˆ๋‹ค.")
3154
 
3155
  single_country = gr.CheckboxGroup(
3156
  choices=get_country_folders(),
@@ -3161,33 +3202,22 @@ with gr.Blocks(css=custom_css) as demo:
3161
 
3162
  single_refresh = gr.Button("๐Ÿ”„ ๊ตญ๊ฐ€/๊ทœ์ œํŒŒ์ผ ์ƒˆ๋กœ๊ณ ์นจ")
3163
 
3164
- with gr.Row():
3165
- single_korean_name = gr.Textbox(
3166
- label="ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…",
3167
- placeholder="์˜ˆ: ํ˜ธ๋ชจ์‚ด๋ ˆ์ดํŠธ",
3168
- )
3169
-
3170
- single_inci_name = gr.Textbox(
3171
- label="INCI Name",
3172
- placeholder="์˜ˆ: Homosalate",
3173
- )
3174
 
3175
  with gr.Row():
3176
- single_cas_no = gr.Textbox(
3177
- label="CAS.No",
3178
- placeholder="์˜ˆ: 118-56-9",
3179
  )
3180
 
3181
  single_function = gr.Textbox(
3182
- label="FUNCTION",
3183
  placeholder="์˜ˆ: Sunscreen Agent",
3184
  )
3185
 
3186
- single_amount = gr.Textbox(
3187
- label="ํ•จ๋Ÿ‰ %(w/w)",
3188
- placeholder="์˜ˆ: 7.2",
3189
- )
3190
-
3191
  use_mfds_live_single = gr.Checkbox(
3192
  label="์‹์•ฝ์ฒ˜ ์‚ฌ์ดํŠธ ์‹ค์‹œ๊ฐ„ ์กฐํšŒ ์‚ฌ์šฉ",
3193
  value=False,
@@ -3223,11 +3253,9 @@ with gr.Blocks(css=custom_css) as demo:
3223
  fn=process_single_ingredient,
3224
  inputs=[
3225
  single_country,
3226
- single_korean_name,
3227
- single_inci_name,
3228
- single_cas_no,
3229
- single_function,
3230
  single_amount,
 
3231
  use_mfds_live_single,
3232
  live_max_terms_single,
3233
  ],
 
13
  # - Gradio ๋กœ๊ทธ์ธ ์ธ์ฆ / public share link ์ ์šฉ
14
  # - MergedCell column_letter ์˜ค๋ฅ˜ ์ˆ˜์ • ์™„๋ฃŒ
15
  # ============================================================
16
+
17
  # ============================================================
18
  # reBom Regulatory Screening AI
19
+ # - ์—‘์…€ ์ „์„ฑ๋ถ„ ์ „์ฒด ์Šคํฌ๋ฆฌ๋‹
20
+ # - ๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰ ํƒญ ์ถ”๊ฐ€
21
  # - ๊ตญ๊ฐ€๋ณ„ ๊ทœ์ œ ํด๋” ์•ˆ์—์„œ๋งŒ ๊ฒ€์ƒ‰
22
  # - FAISS ๋””์Šคํฌ ์บ์‹œ
23
  # - GPT๋Š” ๊ฒ€์ƒ‰๋œ ์›๋ฌธ ์•ˆ์—์„œ๋งŒ ํŒ์ •
24
  # - ์‹์•ฝ์ฒ˜ ์‚ฌ์ดํŠธ ์‹ค์‹œ๊ฐ„ ์กฐํšŒ ์˜ต์…˜
25
  # - COOS ์ œ๊ฑฐ
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_cas_like(text):
410
+ text = safe_str(text)
411
+ return bool(re.match(r"^\d{2,7}-\d{2}-\d$", text))
412
+
413
+
414
+ def is_plain_fragrance_component(material, component):
415
+ texts = [
416
+ component.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""),
417
+ component.get("INCI Name", ""),
418
+ component.get("FUNCTION", ""),
419
+ component.get("CAS.No", ""),
420
+ material.get("Trade name(๊ตญ๋ฌธ)", ""),
421
+ material.get("Trade name(์˜๋ฌธ)", ""),
422
+ ]
423
+
424
+ compact = normalize_compact(" ".join([safe_str(x) for x in texts if safe_str(x)]))
425
+
426
+ fragrance_words = [
427
+ "ํ–ฅ๋ฃŒ",
428
+ "fragrance",
429
+ "parfum",
430
+ "perfume",
431
+ "aroma",
432
+ ]
433
+
434
+ return any(normalize_compact(w) in compact for w in fragrance_words)
435
+
436
+
437
+ def evaluate_plain_fragrance_rule(country, material, component):
438
+ if not is_plain_fragrance_component(material, component):
439
+ return None
440
+
441
+ return {
442
+ "๋Œ€ํ‘œ INCI": safe_str(component.get("INCI Name", "")) or "Fragrance",
443
+ "๊ฒฐ๊ณผ": f"ํ–ฅ๋ฃŒ / {display_country(country)} ์•Œ๋ ˆ๋ฅด๊ฒ ํ‘œ์‹œ์„ฑ๋ถ„ ๋ฐ ์„ธ๋ถ€ ์กฐ์„ฑ ํ™•์ธ ํ•„์š”",
444
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
445
+ "๋น„๊ณ ": "ํ–ฅ๋ฃŒ๋Š” ์„ธ๋ถ€ ๊ตฌ์„ฑ์„ฑ๋ถ„ ๋ฐ ์•Œ๋ ˆ๋ฅด๊ฒ ํ‘œ์‹œ๋Œ€์ƒ ์—ฌ๋ถ€ ํ™•์ธ ํ•„์š”. ์ž๋™ Pass ์ฒ˜๋ฆฌ ๊ธˆ์ง€.",
446
+ }
447
+
448
+
449
  def get_restricted_candidate_reason(material, component):
450
+ if is_plain_fragrance_component(material, component):
451
+ return "ํ–ฅ๋ฃŒ"
452
+
453
  uv_key = match_rule_key(material, component, UV_FILTER_RULES)
454
  if uv_key:
455
  return "UV ํ•„ํ„ฐ"
 
526
  if NEED_CHECK_TEXT in text:
527
  return NEED_CHECK_TEXT
528
 
529
+ if "ํ–ฅ๋ฃŒ" in text or "fragrance" in lower or "parfum" in lower:
530
+ return NEED_CHECK_TEXT
531
+
532
  if "octocrylene" in inci_norm or "์˜ฅํ† ํฌ๋ฆด๋ Œ" in inci_norm:
533
  if country_col == "EU":
534
  return "๋ฐฐํ•ฉ ํ•œ๋„:\n์Šคํ”„๋ ˆ์ด: 9% /\n๊ธฐํƒ€์ œํ’ˆ: 10%"
 
1222
  terms = []
1223
 
1224
  for item in row_items:
1225
+ material = item["material"]
1226
  comp = item["component"]
1227
+
1228
+ if is_plain_fragrance_component(material, comp):
1229
+ continue
1230
+
1231
+ high_risk_reason = get_restricted_candidate_reason(material, comp)
1232
+
1233
+ if not high_risk_reason:
1234
+ continue
1235
+
1236
+ candidate_values = [
1237
+ comp.get("INCI Name", ""),
1238
+ comp.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""),
1239
+ comp.get("CAS.No", ""),
1240
+ ]
1241
+
1242
+ for value in candidate_values:
1243
  value = safe_str(value)
1244
+
1245
+ if not value or value == "-":
1246
+ continue
1247
+
1248
+ key = normalize_compact(value)
1249
+
1250
+ if len(key) < 3:
1251
+ continue
1252
+
1253
+ terms.append(value)
1254
 
1255
  seen = set()
1256
  unique = []
1257
 
1258
  for term in terms:
1259
  key = normalize_compact(term)
1260
+
1261
  if key and key not in seen:
1262
  seen.add(key)
1263
  unique.append(term)
 
1502
 
1503
  with sync_playwright() as p:
1504
  browser = p.chromium.launch(
1505
+ headless=True,
1506
+ args=[
1507
+ "--no-sandbox",
1508
+ "--disable-setuid-sandbox",
1509
+ "--disable-dev-shm-usage",
1510
+ "--disable-gpu",
1511
+ "--disable-software-rasterizer",
1512
+ "--disable-extensions",
1513
+ "--disable-background-networking",
1514
+ "--disable-default-apps",
1515
+ "--disable-sync",
1516
+ "--metrics-recording-only",
1517
+ "--mute-audio",
1518
+ ],
1519
+ )
1520
+
1521
  context = browser.new_context(
1522
+ viewport={"width": 1280, "height": 900},
1523
+ user_agent=(
1524
+ "Mozilla/5.0 (X11; Linux x86_64) "
1525
+ "AppleWebKit/537.36 (KHTML, like Gecko) "
1526
+ "Chrome/120.0.0.0 Safari/537.36"
1527
+ ),
1528
+ ignore_https_errors=True,
1529
  )
1530
+
1531
  page = context.new_page()
1532
 
1533
  for idx, term in enumerate(terms, start=1):
1534
  try:
1535
  print(f"MFDS ์‹ค์‹œ๊ฐ„ ์กฐํšŒ {idx}/{len(terms)}: {term}")
1536
 
1537
+ goto_success = False
1538
+ last_goto_error = ""
1539
+
1540
+ for attempt in range(3):
1541
+ try:
1542
+ page.goto(
1543
+ MFDS_LIVE_URL,
1544
+ wait_until="domcontentloaded",
1545
+ timeout=45000,
1546
+ )
1547
+ page.wait_for_timeout(3000)
1548
+ goto_success = True
1549
+ break
1550
+ except Exception as e:
1551
+ last_goto_error = str(e)
1552
+ page.wait_for_timeout(3000)
1553
+
1554
+ if not goto_success:
1555
+ local_errors.append(f"{term}: ์‹์•ฝ์ฒ˜ ์ ‘์† ์‹คํŒจ: {last_goto_error}")
1556
+ continue
1557
 
1558
  if not mfds_fill_search_input(page, term):
1559
  local_errors.append(f"{term}: ๊ฒ€์ƒ‰ ์ž…๋ ฅ์ฐฝ ์ฐพ๊ธฐ ์‹คํŒจ")
 
1758
  ckey = country_key(country)
1759
  amount = component.get("amount_float")
1760
 
1761
+ plain_fragrance = evaluate_plain_fragrance_rule(country, material, component)
1762
+ if plain_fragrance is not None:
1763
+ return plain_fragrance
1764
+
1765
  uv_result = evaluate_limit_rule(country, material, component, UV_FILTER_RULES, "UV ํ•„ํ„ฐ")
1766
  if uv_result is not None:
1767
  return uv_result
 
1796
  if not matched:
1797
  continue
1798
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1799
  return {
1800
  "๋Œ€ํ‘œ INCI": rule["label"],
1801
+ "๊ฒฐ๊ณผ": f"ํ–ฅ๋ฃŒ ์•Œ๋ ˆ๋ฅด๊ฒ / {rule['label']} / {display_country(country)} ํ‘œ์‹œ๊ธฐ์ค€ ํ™•์ธ ํ•„์š”",
1802
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
1803
+ "๋น„๊ณ ": "ํ–ฅ๋ฃŒ ์•Œ๋ ˆ๋ฅด๊ฒ ํ›„๋ณด. ์„ธ๋ถ€ ํ‘œ์‹œ๊ธฐ์ค€ ๋ฐ ์ œํ’ˆ ์œ ํ˜• ํ™•์ธ ํ•„์š”.",
1804
  }
1805
 
1806
  if amount is None:
 
1950
  amount_text = format_percent(amount) if amount is not None else "ํ•จ๋Ÿ‰ ํ™•์ธ ํ•„์š”"
1951
  high_risk_reason = get_restricted_candidate_reason(material, component)
1952
 
1953
+ if not inci_name and not korean_name and not cas_no:
1954
  return {"๋Œ€ํ‘œ INCI": "-", "๊ฒฐ๊ณผ": "", "ํ‘œ์‹œ๋ฌธ๊ตฌ": "", "๋น„๊ณ ": "-"}
1955
 
1956
  if not db:
1957
  if high_risk_reason:
1958
  result = {
1959
+ "๋Œ€ํ‘œ INCI": inci_name or korean_name or cas_no or "-",
1960
+ "๊ฒฐ๊ณผ": f"{high_risk_reason} / {inci_name or korean_name or cas_no} / {country_col} ์ œํ•œ ์—ฌ๋ถ€ ํ™•์ธ ํ•„์š”",
1961
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
1962
  "๋น„๊ณ ": "ํ•ด๋‹น ๊ตญ๊ฐ€/์ฑ„๋„ ๊ทœ์ œ DB ์—†์Œ. ๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด์ด๋ฏ€๋กœ Pass ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์Œ.",
1963
  }
1964
  else:
1965
  result = {
1966
+ "๋Œ€ํ‘œ INCI": inci_name or korean_name or cas_no or "-",
1967
  "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
1968
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
1969
  "๋น„๊ณ ": "-",
 
2001
  if not has_hit:
2002
  if high_risk_reason:
2003
  result = {
2004
+ "๋Œ€ํ‘œ INCI": inci_name or korean_name or cas_no or "-",
2005
+ "๊ฒฐ๊ณผ": f"{high_risk_reason} / {inci_name or korean_name or cas_no} / {country_col} ์ œํ•œ ์—ฌ๋ถ€ ํ™•์ธ ํ•„์š”",
2006
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
2007
  "๋น„๊ณ ": "๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด์ด๋‚˜ ๊ตญ๊ฐ€๋ณ„ ๊ทœ์ œํŒŒ์ผ์—์„œ ์ง์ ‘ ๊ทผ๊ฑฐ ๋ฏธ๊ฒ€์ถœ. Pass ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์Œ.",
2008
  }
2009
  else:
2010
  result = {
2011
+ "๋Œ€ํ‘œ INCI": inci_name or korean_name or cas_no or "-",
2012
  "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
2013
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
2014
  "๋น„๊ณ ": "-",
 
2049
  ๊ฒฐ๊ณผ:
2050
  ํ‘œ์‹œ๋ฌธ๊ตฌ:
2051
  ๋น„๊ณ :
 
 
 
 
 
 
 
2052
  """
2053
 
2054
  try:
 
2067
 
2068
  except Exception as e:
2069
  result = {
2070
+ "๋Œ€ํ‘œ INCI": inci_name or korean_name or cas_no or "-",
2071
  "๊ฒฐ๊ณผ": "ํ™•์ธ ํ•„์š”",
2072
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
2073
  "๋น„๊ณ ": str(e),
 
2091
  material = item["material"]
2092
  inci_name = safe_str(comp.get("INCI Name", ""))
2093
  korean_name = safe_str(comp.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""))
2094
+ cas_no = safe_str(comp.get("CAS.No", ""))
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 cas_no or "-",
2100
+ "๊ฒฐ๊ณผ": f"{high_risk_reason} / {inci_name or korean_name or cas_no} / {country_col} ์ œํ•œ ์—ฌ๋ถ€ ํ™•์ธ ํ•„์š”",
2101
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
2102
  "๋น„๊ณ ": "ํ•ด๋‹น ๊ตญ๊ฐ€/์ฑ„๋„ ๊ทœ์ œ DB ์—†์Œ. ๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด์ด๋ฏ€๋กœ Pass ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์Œ.",
2103
  }
2104
  else:
2105
  result = {
2106
+ "๋Œ€ํ‘œ INCI": inci_name or korean_name or cas_no or "-",
2107
  "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
2108
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
2109
  "๋น„๊ณ ": "-",
2110
  }
2111
 
2112
  results[item["target_id"]] = result
2113
+ log_search_context(item["target_id"], country, comp, result["๊ฒฐ๊ณผ"], "NO_DB", "ํ•ด๋‹น ๊ตญ๊ฐ€/์ฑ„๋„ ๊ทœ์ œ DB ์—†์Œ")
 
 
 
 
 
 
 
2114
 
2115
  return results
2116
 
 
2160
  else:
2161
  if high_risk_reason:
2162
  result = {
2163
+ "๋Œ€ํ‘œ INCI": inci_name or korean_name or cas_no or "-",
2164
+ "๊ฒฐ๊ณผ": f"{high_risk_reason} / {inci_name or korean_name or cas_no} / {country_col} ์ œํ•œ ์—ฌ๋ถ€ ํ™•์ธ ํ•„์š”",
2165
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
2166
  "๋น„๊ณ ": "๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด์ด๋‚˜ ๊ตญ๊ฐ€๋ณ„ ๊ทœ์ œํŒŒ์ผ์—์„œ ์ง์ ‘ ๊ทผ๊ฑฐ ๋ฏธ๊ฒ€์ถœ. Pass ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์Œ.",
2167
  }
2168
  else:
2169
  result = {
2170
+ "๋Œ€ํ‘œ INCI": inci_name or korean_name or cas_no or "-",
2171
  "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
2172
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
2173
  "๋น„๊ณ ": "-",
 
2175
 
2176
  results[item["target_id"]] = result
2177
  EVAL_CACHE[make_eval_cache_key(country, comp)] = result
2178
+ log_search_context(item["target_id"], country, comp, result["๊ฒฐ๊ณผ"], "NO_MEANINGFUL_HIT", context)
 
 
 
 
 
 
 
2179
 
2180
  uncached_targets = filtered_targets
2181
 
 
2685
  mfds_df, mfds_live_msg = mfds_live_lookup_terms(
2686
  terms=terms,
2687
  max_terms=live_max_terms,
2688
+ headless=True,
2689
  )
2690
  except Exception as e:
2691
  mfds_df = pd.DataFrame()
 
2696
  gpt_targets = []
2697
 
2698
  for item in row_items:
2699
+ fragrance_result = evaluate_plain_fragrance_rule(
2700
+ country=country,
2701
+ material=item["material"],
2702
+ component=item["component"],
2703
+ )
2704
+
2705
+ if fragrance_result is not None:
2706
+ item["row_data"][col_name] = fragrance_result.get("๊ฒฐ๊ณผ", "")
2707
+ item["row_data"][col_name + "_display"] = fragrance_result.get("ํ‘œ์‹œ๋ฌธ๊ตฌ", NEED_CHECK_TEXT)
2708
+
2709
+ note = safe_str(fragrance_result.get("๋น„๊ณ ", "-"))
2710
+ if note and note != "-":
2711
+ item["notes"].append(f"{col_name}: {note}")
2712
+
2713
+ log_search_context(
2714
+ item["target_id"],
2715
+ country,
2716
+ item["component"],
2717
+ fragrance_result.get("๊ฒฐ๊ณผ", ""),
2718
+ "FRAGRANCE_RULE",
2719
+ note,
2720
+ )
2721
+ continue
2722
+
2723
  mfds_result = None
2724
 
2725
  if use_mfds_live and mfds_df is not None and not mfds_df.empty:
 
2844
  f"- In formula ํ•ฉ๊ณ„: {format_amount(formula_total)}%\n"
2845
  f"- ์žฌ๊ฒ€ํ†  ํ•„์š” ์„ฑ๋ถ„: {len(regulatory_df)}๊ฐœ\n"
2846
  f"- MFDS ์ƒํƒœ: {mfds_live_msg}\n"
2847
+ f"- MFDS ์กฐํšŒ ๋Œ€์ƒ: {', '.join(terms[:10]) if terms else '์—†์Œ'}\n"
2848
  "- ๊ฒฐ๊ณผ ํŒŒ์ผ ์‹œํŠธ:\n"
2849
  " 1) Formula Ingredients Statement\n"
2850
  " 2) Regulatory Screening Summary\n"
 
2858
  print(tb)
2859
  return None, None, f"โŒ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}\n\n{tb[-3000:]}"
2860
 
2861
+
2862
  # ============================================================
2863
  # 11-1. ๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰
2864
  # ============================================================
2865
 
2866
+ def build_single_component_from_query(query, single_amount="", single_function=""):
2867
+ query = safe_str(query)
2868
+ amount_float = to_number(single_amount)
2869
+ amount_text = format_amount(amount_float) if amount_float is not None else ""
2870
+
2871
+ korean_name = ""
2872
+ inci_name = ""
2873
+ cas_no = ""
2874
+
2875
+ if is_cas_like(query):
2876
+ cas_no = query
2877
+ elif re.search(r"[๊ฐ€-ํžฃ]", query):
2878
+ korean_name = query
2879
+ inci_name = query
2880
+ else:
2881
+ inci_name = query
2882
+ korean_name = query
2883
+
2884
+ component = {
2885
+ "ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…": korean_name,
2886
+ "INCI Name": inci_name,
2887
+ "FUNCTION": safe_str(single_function),
2888
+ "CAS.No": cas_no,
2889
+ "SOURCE": "Manual Search",
2890
+ "In formula(w/w %)": amount_text,
2891
+ "amount_float": amount_float,
2892
+ }
2893
+
2894
+ material = {
2895
+ "NO": "1",
2896
+ "Trade name(๊ตญ๋ฌธ)": korean_name or query,
2897
+ "Trade name(์˜๋ฌธ)": inci_name or query,
2898
+ "Components": [component],
2899
+ }
2900
+
2901
+ return material, component, amount_text
2902
+
2903
+
2904
+ def extract_single_lookup_terms(query, material, component):
2905
+ query = safe_str(query)
2906
+
2907
+ terms = []
2908
+
2909
+ for value in [
2910
+ query,
2911
+ component.get("INCI Name", ""),
2912
+ component.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""),
2913
+ component.get("CAS.No", ""),
2914
+ ]:
2915
+ value = safe_str(value)
2916
+
2917
+ if value and value != "-":
2918
+ terms.append(value)
2919
+
2920
+ seen = set()
2921
+ unique = []
2922
+
2923
+ for term in terms:
2924
+ key = normalize_compact(term)
2925
+
2926
+ if key and key not in seen:
2927
+ seen.add(key)
2928
+ unique.append(term)
2929
+
2930
+ return unique
2931
+
2932
+
2933
  def process_single_ingredient(
2934
  countries,
2935
+ single_query,
 
 
 
2936
  single_amount,
2937
+ single_function,
2938
  use_mfds_live_single=False,
2939
  live_max_terms_single=3,
2940
  ):
 
2945
  if not countries:
2946
  return pd.DataFrame(), "โŒ ๊ฒ€์ƒ‰ํ•  ๊ตญ๊ฐ€๋ฅผ ์„ ํƒํ•ด์ฃผ์„ธ์š”."
2947
 
2948
+ if not safe_str(single_query):
2949
+ return pd.DataFrame(), "โŒ ๊ฒ€์ƒ‰ํ•  ์„ฑ๋ถ„๋ช…, INCI, CAS.No ์ค‘ ํ•˜๋‚˜๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2950
 
2951
+ material, component, amount_text = build_single_component_from_query(
2952
+ query=single_query,
2953
+ single_amount=single_amount,
2954
+ single_function=single_function,
2955
+ )
 
 
2956
 
2957
  llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
2958
 
2959
  mfds_df = pd.DataFrame()
2960
  mfds_live_msg = "์‚ฌ์šฉ ์•ˆ ํ•จ"
2961
 
2962
+ terms = extract_single_lookup_terms(single_query, material, component)
2963
 
2964
  if use_mfds_live_single:
2965
  try:
 
2976
  ingredient_amount_parts = defaultdict(list)
2977
 
2978
  identity = get_identity_text(material, component)
2979
+ amount_float = component.get("amount_float")
2980
 
2981
  if amount_float is not None:
2982
  for canonical, rule in FRAGRANCE_ALLERGEN_RULES.items():
 
3042
  display_text = normalize_formula_country_text(
3043
  final_result.get("๊ฒฐ๊ณผ", ""),
3044
  country_col=country_col,
3045
+ inci_name=component.get("INCI Name", "") or safe_str(single_query),
3046
  amount_text=amount_text,
3047
  )
3048
 
 
3051
  "ํ‘œ์‹œ ๊ฒฐ๊ณผ": display_text,
3052
  "์ƒ์„ธ ํŒ์ •": final_result.get("๊ฒฐ๊ณผ", ""),
3053
  "ํŒ์ • ์ถœ์ฒ˜": source,
3054
+ "๊ฒ€์ƒ‰์–ด": safe_str(single_query),
3055
  "ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…": component.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""),
3056
  "INCI Name": component.get("INCI Name", ""),
3057
  "CAS.No": component.get("CAS.No", ""),
 
3073
 
3074
  msg = (
3075
  "โœ… ๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰ ์™„๋ฃŒ\n"
3076
+ f"- ๊ฒ€์ƒ‰์–ด: {safe_str(single_query)}\n"
3077
  f"- ์„ ํƒ ๊ตญ๊ฐ€ ์ˆ˜: {len(countries)}๊ฐœ\n"
3078
  f"- MFDS ์ƒํƒœ: {mfds_live_msg}\n"
3079
  f"- MFDS ์กฐํšŒ ๋Œ€์ƒ: {', '.join(terms[:10]) if terms else '์—†์Œ'}\n"
 
3085
  tb = traceback.format_exc()
3086
  print(tb)
3087
  return pd.DataFrame(), f"โŒ ๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰ ์˜ค๋ฅ˜: {str(e)}\n\n{tb[-3000:]}"
3088
+
3089
+
3090
  # ============================================================
3091
  # 12. Gradio UI
3092
  # ============================================================
 
3191
 
3192
  with gr.Tab("๐Ÿ”Ž ๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰"):
3193
  gr.Markdown("## ๐Ÿ”Ž ๋‹จ์ผ ์„ฑ๋ถ„ ๊ทœ์ œ ๊ฒ€์ƒ‰")
3194
+ gr.Markdown("์—‘์…€ ์—…๋กœ๋“œ ์—†์ด ๊ตญ๊ฐ€๋ฅผ ์„ ํƒํ•˜๊ณ  ์„ฑ๋ถ„๋ช…, INCI, CAS.No ์ค‘ ์•„๋ฌด๊ฑฐ๋‚˜ ํ•˜๋‚˜๋งŒ ์ž…๋ ฅํ•ด์„œ ๋ฐ”๋กœ ์Šคํฌ๋ฆฌ๋‹ํ•ฉ๋‹ˆ๋‹ค.")
3195
 
3196
  single_country = gr.CheckboxGroup(
3197
  choices=get_country_folders(),
 
3202
 
3203
  single_refresh = gr.Button("๐Ÿ”„ ๊ตญ๊ฐ€/๊ทœ์ œํŒŒ์ผ ์ƒˆ๋กœ๊ณ ์นจ")
3204
 
3205
+ single_query = gr.Textbox(
3206
+ label="๊ฒ€์ƒ‰์–ด",
3207
+ placeholder="์˜ˆ: ํ˜ธ๋ชจ์‚ด๋ ˆ์ดํŠธ / Homosalate / 118-56-9 / Octocrylene / ํ–ฅ๋ฃŒ",
3208
+ )
 
 
 
 
 
 
3209
 
3210
  with gr.Row():
3211
+ single_amount = gr.Textbox(
3212
+ label="ํ•จ๋Ÿ‰ %(w/w) ์„ ํƒ ์ž…๋ ฅ",
3213
+ placeholder="์˜ˆ: 7.2",
3214
  )
3215
 
3216
  single_function = gr.Textbox(
3217
+ label="FUNCTION ์„ ํƒ ์ž…๋ ฅ",
3218
  placeholder="์˜ˆ: Sunscreen Agent",
3219
  )
3220
 
 
 
 
 
 
3221
  use_mfds_live_single = gr.Checkbox(
3222
  label="์‹์•ฝ์ฒ˜ ์‚ฌ์ดํŠธ ์‹ค์‹œ๊ฐ„ ์กฐํšŒ ์‚ฌ์šฉ",
3223
  value=False,
 
3253
  fn=process_single_ingredient,
3254
  inputs=[
3255
  single_country,
3256
+ single_query,
 
 
 
3257
  single_amount,
3258
+ single_function,
3259
  use_mfds_live_single,
3260
  live_max_terms_single,
3261
  ],