Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 171 |
-
|
| 172 |
-
|
| 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 |
-
|
| 199 |
-
|
| 200 |
-
|
| 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 |
-
|
| 228 |
-
|
| 229 |
-
|
| 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 |
-
|
| 252 |
-
|
| 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 |
-
|
| 274 |
-
|
| 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 |
-
"
|
| 370 |
-
"
|
| 371 |
-
"
|
| 372 |
-
"
|
| 373 |
-
"
|
| 374 |
-
"
|
| 375 |
-
"
|
| 376 |
-
"
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1273 |
value = safe_str(value)
|
| 1274 |
-
|
| 1275 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 1527 |
-
|
| 1528 |
-
|
| 1529 |
-
|
| 1530 |
-
|
| 1531 |
-
|
| 1532 |
-
|
| 1533 |
-
|
| 1534 |
-
|
| 1535 |
-
|
| 1536 |
-
|
| 1537 |
-
|
| 1538 |
-
|
| 1539 |
-
|
| 1540 |
-
)
|
|
|
|
| 1541 |
context = browser.new_context(
|
| 1542 |
-
viewport={"width":
|
| 1543 |
-
user_agent=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 1552 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
"๊ฒฐ๊ณผ":
|
| 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=
|
| 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 |
-
|
| 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(
|
| 2888 |
-
return pd.DataFrame(), "โ
|
| 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 |
-
|
| 2911 |
-
|
| 2912 |
-
|
| 2913 |
-
|
| 2914 |
-
|
| 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 =
|
| 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"- ๊ฒ์
|
| 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 |
-
|
| 3165 |
-
|
| 3166 |
-
|
| 3167 |
-
|
| 3168 |
-
)
|
| 3169 |
-
|
| 3170 |
-
single_inci_name = gr.Textbox(
|
| 3171 |
-
label="INCI Name",
|
| 3172 |
-
placeholder="์: Homosalate",
|
| 3173 |
-
)
|
| 3174 |
|
| 3175 |
with gr.Row():
|
| 3176 |
-
|
| 3177 |
-
label="
|
| 3178 |
-
placeholder="์:
|
| 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 |
-
|
| 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 |
],
|