Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,57 +1,35 @@
|
|
| 1 |
# APP_PATCH_NOTE_SPEED_MFDS_BATCH_OFF = "์ ์ฒด ์คํฌ๋ฆฌ๋ ์๋ ์๊ธํจ์น: MFDS ์ค์๊ฐ ์กฐํ ๋ฐฐ์น ๋นํ์ฑํ + ๋งค์นญ ์บ์"
|
| 2 |
# APP_PATCH_NOTE_LIMIT_POSITIVE_MFDS = "Positive List ํ๋ํ์ธ + MFDS ์ ํ ํ์ฑ ๋ณด๊ฐ ์ ์ฉ๋ณธ"
|
| 3 |
-
# APP_PATCH_NOTE_SOURCE_ONLY_STRICT_V3 = "์
๋ก๋ ๊ตญ๊ฐ๋ณ ํ์ผ ์ง์ ๊ทผ๊ฑฐ ์ ์ฉ ๋ชจ๋ + ํ๋์ฝ๋ฉ ํ๋/๊ธ์ง ์๋ํ์ ์ฐจ๋จ"
|
| 4 |
# ============================================================
|
| 5 |
-
# reBom Regulatory Screening AI -
|
| 6 |
-
# ============================================================
|
| 7 |
-
# ํต์ฌ ๋ชฉ์
|
| 8 |
-
# - ์ฌ์ฉ์๊ฐ ์
๋ก๋ํ ๊ตญ๊ฐ๋ณ ๊ท์ ํ์ผ์์ ์ง์ ํ์ธ๋ ๊ทผ๊ฑฐ๋ง ๊ธฐ์ค์ผ๋ก ์คํฌ๋ฆฌ๋
|
| 9 |
-
# - ์
๋ก๋ ํ์ผ์ ์๋ ๋ฐฐํฉํ๋/๊ธ์ง์ฌํญ ์๋ ์์ฑ ๋ฐฉ์ง
|
| 10 |
-
# - ๋ฌธ์ ์๋ ์ฑ๋ถ์ด ๊ธ์ง์ฑ๋ถ ๋๋ ํ๋์ฑ๋ถ์ผ๋ก ์คํ์ ๋๋ ๋ฌธ์ ๋ฐฉ์ง
|
| 11 |
-
# - Positive List๋ ๊ธฐ๋ณธ์ ์ผ๋ก ํ์ฉ๋ชฉ๋ก์ผ๋ก ์ฒ๋ฆฌ
|
| 12 |
-
# - Positive List์ ์ฑ๋ถ๋ช
์ด ์์ด๋ ๋ช
ํํ ํ๋ ์์น๊ฐ ์์ผ๋ฉด ๋ฌธ์ ์ฑ๋ถ์ผ๋ก ์ฒ๋ฆฌํ์ง ์์
|
| 13 |
-
# - ๊ธ์ง/์ ํ ๋ฌธ๊ตฌ๊ฐ ๋ช
ํํ์ง ์์ผ๋ฉด Pass ๋๋ ํด๋น ์๋ฃ ๋ด ์ ํ ๊ทผ๊ฑฐ ์์ ์ฒ๋ฆฌ
|
| 14 |
-
#
|
| 15 |
-
# ์ฃผ์ ๊ธฐ๋ฅ
|
| 16 |
# - ๊ตญ๊ฐ/์ฑ๋ ํด๋ ์๋ ์ธ์
|
| 17 |
# - ๊ท์ ํ์ผ ์๋ ๋ณ๊ฒฝ ๊ฐ์ง
|
| 18 |
-
# - ๊ตญ๊ฐ๋ณ
|
| 19 |
-
# - ๊ตญ๊ฐ๋ณ
|
|
|
|
|
|
|
|
|
|
| 20 |
# - Formula Ingredients Statement ์๋ณธ ์์ ์ถ๋ ฅ
|
| 21 |
# - ๋ฌธ์ ์ฑ๋ถ๋ง Regulatory Screening Summary ์ถ๋ ฅ
|
| 22 |
-
# - Raw Search Log
|
| 23 |
# - Gradio ๋ก๊ทธ์ธ ์ธ์ฆ / public share link ์ ์ฉ
|
| 24 |
# - MergedCell column_letter ์ค๋ฅ ์์ ์๋ฃ
|
| 25 |
# - ์์
์ ์ฑ๋ถ ์ ์ฒด ์คํฌ๋ฆฌ๋
|
| 26 |
# - ๋จ์ผ ์ฑ๋ถ ๊ฒ์
|
| 27 |
-
# -
|
| 28 |
-
# -
|
| 29 |
-
# -
|
| 30 |
-
#
|
| 31 |
-
#
|
| 32 |
-
# - ์
๋ก๋ ํ์ผ์์ ๊ธ์ง ๊ทผ๊ฑฐ ์ง์ ํ์ธ๋จ -> ๋ฐฐํฉ๊ธ์ง
|
| 33 |
-
# - ์
๋ก๋ ํ์ผ์์ ์ ํ/ํ๋ ๊ทผ๊ฑฐ ์ง์ ํ์ธ๋จ -> ๋ฐฐํฉํ๋ ๋๋ ํ์ธ ํ์
|
| 34 |
-
# - Positive List์ ์ฑ๋ถ๋ช
๋ง ์์ -> Pass
|
| 35 |
-
# - ํ์ผ์ ์ฑ๋ถ๋ช
๋ง ์๊ณ ๊ธ์ง/์ ํ ๊ทผ๊ฑฐ ์์ -> Pass
|
| 36 |
-
# - ์
๋ก๋ ํ์ผ์ ์ฑ๋ถ๋ช
์ง์ ๊ทผ๊ฑฐ ์์ -> ํด๋น ์๋ฃ ๋ด ์ ํ ๊ทผ๊ฑฐ ์์
|
| 37 |
-
#
|
| 38 |
-
# SOURCE_ONLY_MODE=True์์ ๋นํ์ฑํ๋๋ ๊ธฐ์กด ์๋ํ์
|
| 39 |
-
# - ๋ก์ปฌ ๊ท์น ์ฐ์ ํ์ ๋นํ์ฑํ
|
| 40 |
-
# - UV_FILTER_RULES ์๋ ํ๋ํ์ ๋นํ์ฑํ
|
| 41 |
-
# - PRESERVATIVE_RULES ์๋ ํ๋ํ์ ๋นํ์ฑํ
|
| 42 |
-
# - FUNCTIONAL_KOREA_RULES ์๋ ๊ธฐ๋ฅ์ฑ ํ์ธ ๋นํ์ฑํ
|
| 43 |
-
# - CRITICAL_COUNTRY_RULES ์๋ ๊ธ์ง/์ ํ ํ์ ๋นํ์ฑํ
|
| 44 |
-
# - Tranexamic Acid ์ผ๋ณธ ๋ฐฐํฉ๊ธ์ง ํ๋์ฝ๋ฉ ์ฐ์ ์ฒ๋ฆฌ ๋นํ์ฑํ
|
| 45 |
-
# - ํฅ๋ฃ ์๋ ํ์ธ ํ์ ์ฒ๋ฆฌ ๋นํ์ฑํ
|
| 46 |
-
# - ๊ณ ์ํ ์ฑ๋ถ ์๋ ํ์ธ ํ์ ์ฒ๋ฆฌ ๋นํ์ฑํ
|
| 47 |
-
#
|
| 48 |
-
# ์ ์ง๋๋ ๊ธฐ๋ณธ ์์ธ
|
| 49 |
# - ์ ์ ์ / Water / Aqua๋ ์ ๊ตญ๊ฐ ๊ธฐ๋ณธ Pass
|
| 50 |
-
#
|
| 51 |
-
#
|
| 52 |
-
# -
|
| 53 |
-
# -
|
| 54 |
-
# -
|
|
|
|
|
|
|
|
|
|
| 55 |
# ============================================================
|
| 56 |
|
| 57 |
# reBom Regulatory Screening AI - compact full app.py
|
|
@@ -97,30 +75,6 @@ REG_INDEX_CACHE_DIR = ".reg_index_cache"
|
|
| 97 |
NO_EVIDENCE_TEXT = "ํด๋น ์๋ฃ ๋ด ์ ํ ๊ทผ๊ฑฐ ์์"
|
| 98 |
NEED_CHECK_TEXT = "ํ์ธ ํ์"
|
| 99 |
LIMIT_CHECK_TEXT = "๋ฐฐํฉํ๋ ํ์ธ ํ์"
|
| 100 |
-
# ============================================================
|
| 101 |
-
# Source Only Strict Mode
|
| 102 |
-
# ============================================================
|
| 103 |
-
# True:
|
| 104 |
-
# - ์
๋ก๋ํ ๊ตญ๊ฐ๋ณ ๊ท์ ํ์ผ์์ ์ง์ ํ์ธ๋ ๊ทผ๊ฑฐ๋ง ์ฌ์ฉ
|
| 105 |
-
# - ํ๋์ฝ๋ฉ ํ๋/๊ธ์ง/๊ธฐ๋ฅ์ฑ/ํฅ๋ฃ ์๋ํ์ ์ฐจ๋จ
|
| 106 |
-
# - ์
๋ก๋ ํ์ผ์ ์๋ ๋ฐฐํฉํ๋/๊ธ์ง์ฌํญ ์์ฑ ๋ฐฉ์ง
|
| 107 |
-
SOURCE_ONLY_MODE = True
|
| 108 |
-
|
| 109 |
-
# Positive List๋ ๊ธฐ๋ณธ์ ์ผ๋ก ํ์ฉ๋ชฉ๋ก์ผ๋ก ๋ณธ๋ค.
|
| 110 |
-
# ๋ช
ํํ ํ๋ ์์น๊ฐ ์์ ๋๋ง ๋ฐฐํฉํ๋๋ก ํ์ํ๊ณ ,
|
| 111 |
-
# ์ฑ๋ถ๋ช
๋ง ๋ฑ์ฌ๋์ด ์์ผ๋ฉด Pass ์ฒ๋ฆฌํ๋ค.
|
| 112 |
-
TREAT_POSITIVE_LIST_AS_PASS = True
|
| 113 |
-
|
| 114 |
-
# ============================================================
|
| 115 |
-
# SOURCE_ONLY_MODE
|
| 116 |
-
# True:
|
| 117 |
-
# - ์
๋ก๋๋ ๊ตญ๊ฐ๋ณ ๊ท์ ํ์ผ์์ ์ง์ ์ฐพ์ ๊ทผ๊ฑฐ๋ง ํ์ ์ ์ฌ์ฉ
|
| 118 |
-
# - UV_FILTER_RULES / PRESERVATIVE_RULES / CRITICAL_COUNTRY_RULES ๊ฐ์ ํ๋์ฝ๋ฉ ํ๋ยท๊ธ์ง ์๋ํ์ ๋นํ์ฑํ
|
| 119 |
-
# - ํ์ผ์์ ์ฑ๋ถ๋ช
์ด ๋ฐ๊ฒฌ๋์ด๋ ๊ธ์ง/์ ํ/ํ๋ ํํ์ด ์์ผ๋ฉด ๋ฌธ์ ์ฑ๋ถ์ผ๋ก ํ์ํ์ง ์์
|
| 120 |
-
# False:
|
| 121 |
-
# - ๊ธฐ์กด์ฒ๋ผ ๋ก์ปฌ ํ๋์ฝ๋ฉ ๊ท์น๋ ํจ๊ป ์ฌ์ฉ
|
| 122 |
-
# ============================================================
|
| 123 |
-
SOURCE_ONLY_MODE = True
|
| 124 |
MFDS_LIVE_URL = "https://nedrug.mfds.go.kr/pbp/CCBDF01"
|
| 125 |
# ์๋ ์๊ธํจ์น
|
| 126 |
# - ์ ์ฒด ์ ์ฑ๋ถ ์คํฌ๋ฆฌ๋์์๋ MFDS ์ฌ์ดํธ ์ค์๊ฐ ์กฐํ๋ฅผ ๊ธฐ๋ณธ์ ์ผ๋ก ์ฌ์ฉํ์ง ์๋๋ค.
|
|
@@ -2249,15 +2203,14 @@ def process(countries,file,product_name="",use_mfds_live=False,live_max_terms=5,
|
|
| 2249 |
final_result = None
|
| 2250 |
source = ""
|
| 2251 |
|
| 2252 |
-
|
| 2253 |
-
|
| 2254 |
-
|
| 2255 |
-
|
| 2256 |
-
|
| 2257 |
-
)
|
| 2258 |
|
| 2259 |
-
|
| 2260 |
-
|
| 2261 |
|
| 2262 |
if final_result is None and is_always_pass_component(mat, comp):
|
| 2263 |
final_result = {
|
|
@@ -2268,7 +2221,7 @@ def process(countries,file,product_name="",use_mfds_live=False,live_max_terms=5,
|
|
| 2268 |
}
|
| 2269 |
source = "ALWAYS_PASS_RULE"
|
| 2270 |
|
| 2271 |
-
if final_result is None
|
| 2272 |
fragrance_result = evaluate_plain_fragrance_rule(
|
| 2273 |
country=country,
|
| 2274 |
material=mat,
|
|
@@ -2303,7 +2256,7 @@ def process(countries,file,product_name="",use_mfds_live=False,live_max_terms=5,
|
|
| 2303 |
final_result = file_result
|
| 2304 |
source = "COUNTRY_FILE_FAST"
|
| 2305 |
|
| 2306 |
-
if final_result is None
|
| 2307 |
local_result = evaluate_local_rules(
|
| 2308 |
country=country,
|
| 2309 |
material=mat,
|
|
@@ -2367,7 +2320,7 @@ def process(countries,file,product_name="",use_mfds_live=False,live_max_terms=5,
|
|
| 2367 |
f"- ์ ์ฑ๋ถ ํ ์: {len(formula_df)}๊ฐ\n"
|
| 2368 |
f"- In formula ํฉ๊ณ: {format_amount(sum_formula_percent(formula_df))}%\n"
|
| 2369 |
f"- ์ฌ๊ฒํ ํ์ ์ฑ๋ถ: {len(regulatory_df)}๊ฐ\n"
|
| 2370 |
-
"- MFDS ์ํ:
|
| 2371 |
"- ํ์ ๋ฐฉ์: GPT ํ์ ์์ / ์
๋ก๋๋ ๊ตญ๊ฐ๋ณ ํ์ผ rowยทline ์ง์ ๊ฒ์\n"
|
| 2372 |
f"- ๊ตญ๊ฐ๋ณ ์ธ๋ฑ์ค ์ํ: {' | '.join(index_messages)}\n"
|
| 2373 |
"- ์๋ ๊ฐ์ : ์ ์ฒด ์คํฌ๋ฆฌ๋์์ GPT/LLM ํธ์ถ ์ ๊ฑฐ\n"
|
|
@@ -2950,81 +2903,32 @@ def warmup_country_indexes(countries):
|
|
| 2950 |
|
| 2951 |
|
| 2952 |
def extract_limit_condition_from_context(context):
|
| 2953 |
-
"""
|
| 2954 |
-
ํ๋ ์ถ์ถ ๊ฐํ ๋ฒ์ .
|
| 2955 |
-
๊ธฐ์กด ๋ฌธ์ :
|
| 2956 |
-
- ๋ฌธ๋งฅ์ ์ซ์/%๊ฐ ์๊ธฐ๋ง ํด๋ ๋ฐฐํฉํ๋์ฒ๋ผ ์กํ ์ ์์.
|
| 2957 |
-
๊ฐ์ :
|
| 2958 |
-
- ์ฑ๋ถ ์ฃผ๋ณ ๋ฌธ๋งฅ์ '๋ฐฐํฉํ๋/maximum/limit/not exceed/์ดํ/์ต๋/์ ํ์ฌํญ' ๊ฐ์ ์ ํ ํค์๋๊ฐ ์์ด์ผ๋ง ํ๋ ์ถ์ถ.
|
| 2959 |
-
- ํ์/๋ผ๋ฒจ/์๋ ๋ฅด๊ฒ/๋ถ์๋ฌผ/์ํ๋ฒ/ppm ๊ด๋ฆฌ๊ฐ ๋ฑ์ ๋ฐฐํฉํ๋๋ก ๋ณด์ง ์์.
|
| 2960 |
-
"""
|
| 2961 |
text = safe_str(context)
|
| 2962 |
compact = re.sub(r"\s+", " ", text).strip()
|
| 2963 |
-
|
| 2964 |
if not compact:
|
| 2965 |
return "", ""
|
| 2966 |
|
| 2967 |
-
limit_keywords = [
|
| 2968 |
-
"๋ฐฐํฉํ๋", "๋ฐฐํฉ ํ๋", "์ฌ์ฉํ๋", "์ฌ์ฉ ํ๋", "์ ํ์ฌํญ", "์ฌ์ฉ์ ํ", "์ฌ์ฉ ์ ํ",
|
| 2969 |
-
"์ต๋", "์ดํ", "ํ๋", "maximum", "max.", "limit", "limits", "limited",
|
| 2970 |
-
"restriction", "restricted", "not exceed", "not exceeding", "no more than",
|
| 2971 |
-
]
|
| 2972 |
-
|
| 2973 |
-
false_limit_keywords = [
|
| 2974 |
-
"label", "labeling", "labelling", "๋ผ๋ฒจ", "ํ์", "์๋ ๋ฅด๊ฒ", "allergen",
|
| 2975 |
-
"warning", "๊ฒฝ๊ณ ", "๋ถ์๋ฌผ", "impurity", "์ํ", "์ํ๋ฒ", "test method",
|
| 2976 |
-
"analysis", "๊ฒ์ฌ", "๊ด๋ฆฌ๊ฐ", "๊ฒ์ถํ๊ณ", "detection limit",
|
| 2977 |
-
"peroxide value", "์ฐ๊ฐ", "์๋", "purity",
|
| 2978 |
-
]
|
| 2979 |
-
|
| 2980 |
-
candidate_lines = []
|
| 2981 |
-
lines = [safe_str(x) for x in text.splitlines() if safe_str(x)]
|
| 2982 |
-
|
| 2983 |
-
for line in lines:
|
| 2984 |
-
low = line.lower()
|
| 2985 |
-
if any(k.lower() in low for k in false_limit_keywords):
|
| 2986 |
-
continue
|
| 2987 |
-
if any(k.lower() in low for k in limit_keywords):
|
| 2988 |
-
candidate_lines.append(line)
|
| 2989 |
-
|
| 2990 |
-
search_text = "\n".join(candidate_lines)
|
| 2991 |
-
if not search_text and any(k.lower() in compact.lower() for k in limit_keywords):
|
| 2992 |
-
if not any(k.lower() in compact.lower() for k in false_limit_keywords):
|
| 2993 |
-
search_text = compact
|
| 2994 |
-
|
| 2995 |
-
if not search_text:
|
| 2996 |
-
return "", ""
|
| 2997 |
-
|
| 2998 |
patterns = [
|
| 2999 |
r"([0-9]+(?:\.[0-9]+)?\s*%)",
|
|
|
|
| 3000 |
r"([0-9]+(?:\.[0-9]+)?\s*g\s*/\s*100\s*g)",
|
| 3001 |
r"([0-9]+(?:\.[0-9]+)?\s*g\s+per\s+100\s*g)",
|
|
|
|
| 3002 |
]
|
| 3003 |
-
|
| 3004 |
limits = []
|
| 3005 |
for pat in patterns:
|
| 3006 |
-
for m in re.finditer(pat,
|
| 3007 |
v = m.group(1).replace(" ", "")
|
| 3008 |
if v not in limits:
|
| 3009 |
limits.append(v)
|
| 3010 |
|
| 3011 |
-
# ppm์ ๋ถ์๋ฌผ ๊ด๋ฆฌ๊ฐ์ธ ๊ฒฝ์ฐ๊ฐ ๋ง์ผ๋ฏ๋ก 'maximum concentration/๋ฐฐํฉํ๋'๊ฐ ๊ฐ์ ๋ฌธ์ฅ์ ์์ ๋๋ง ํ์ฉ
|
| 3012 |
-
for line in candidate_lines:
|
| 3013 |
-
low = line.lower()
|
| 3014 |
-
if ("ppm" in low) and any(k in low for k in ["maximum concentration", "max concentration", "๋ฐฐํฉํ๋", "์ฌ์ฉํ๋"]):
|
| 3015 |
-
for m in re.finditer(r"([0-9]+(?:\.[0-9]+)?\s*ppm)", line, flags=re.IGNORECASE):
|
| 3016 |
-
v = m.group(1).replace(" ", "")
|
| 3017 |
-
if v not in limits:
|
| 3018 |
-
limits.append(v)
|
| 3019 |
-
|
| 3020 |
condition_keywords = [
|
| 3021 |
"leave-on", "rinse-off", "oral", "mucosa", "washed away",
|
| 3022 |
"๋ณด์กด์ ", "๋ฐฉ๋ถ์ ", "์์ธ์ ", "์์", "์ ๋ง", "๊ตฌ๊ฐ",
|
| 3023 |
-
"์ ํ์ฌํญ", "
|
| 3024 |
]
|
| 3025 |
-
|
| 3026 |
condition_lines = []
|
| 3027 |
-
for line in
|
| 3028 |
l = line.lower()
|
| 3029 |
if any(k.lower() in l for k in condition_keywords):
|
| 3030 |
cleaned = re.sub(r"\s+", " ", line).strip()
|
|
@@ -3045,8 +2949,8 @@ def make_restricted_or_positive_result(country, component, match, reg_type):
|
|
| 3045 |
display = f"๋ฐฐํฉํ๋: {limit_text}"
|
| 3046 |
result = f"{display_country(country)} {label}์์ ์ฑ๋ถ ํ์ธ / ํ๋ {limit_text}"
|
| 3047 |
elif kind.startswith("positive_"):
|
| 3048 |
-
display = "
|
| 3049 |
-
result =
|
| 3050 |
else:
|
| 3051 |
display = "๋ฐฐํฉํ๋/์ ํ ํ์ธ"
|
| 3052 |
result = f"{display_country(country)} {label}์์ ์ฑ๋ถ ํ์ธ / ํ๋ยท์กฐ๊ฑด ํ์ธ ํ์"
|
|
@@ -3323,37 +3227,24 @@ def evaluate_component_from_uploaded_source_records(country, material, component
|
|
| 3323 |
|
| 3324 |
if reg_kind.startswith("positive_"):
|
| 3325 |
limit_text, condition_text = extract_limit_condition_from_context(context)
|
| 3326 |
-
|
| 3327 |
-
|
| 3328 |
-
|
| 3329 |
-
|
| 3330 |
-
|
| 3331 |
-
|
| 3332 |
-
"๋ํ INCI": representative,
|
| 3333 |
-
"๊ฒฐ๊ณผ": f"{country_col} {reg_label}์์ ์ฑ๋ถ ์ง์ ํ์ธ / ํ๋ {limit_text}" + (f" / ์กฐ๊ฑด: {condition_text}" if condition_text else ""),
|
| 3334 |
-
"ํ์๋ฌธ๊ตฌ": f"๋ฐฐํฉํ๋: {limit_text}",
|
| 3335 |
-
"๋น๊ณ ": f"[์ถ์ฒํ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
|
| 3336 |
-
}
|
| 3337 |
-
else:
|
| 3338 |
-
result = {
|
| 3339 |
-
"๋ํ INCI": representative,
|
| 3340 |
-
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 3341 |
-
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 3342 |
-
"๋น๊ณ ": f"ํ์ฉ๋ชฉ๋ก์์ ์ฑ๋ถ๋ช
์ ํ์ธ๋์์ผ๋ ๋ฐฐํฉํ๋ ์์น ๊ทผ๊ฑฐ ์์ / [์ถ์ฒํ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
|
| 3343 |
-
}
|
| 3344 |
-
|
| 3345 |
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "UPLOADED_SOURCE_RECORD_POSITIVE", result["๋น๊ณ "])
|
| 3346 |
return result
|
| 3347 |
|
| 3348 |
# ํ์ผ์์๋ ์ฑ๋ถ์ ์ฐพ์์ง๋ง ํ์ผ ์ ํ์ด ๋ถ๋ช
ํํ ๊ฒฝ์ฐ:
|
| 3349 |
-
#
|
| 3350 |
result = {
|
| 3351 |
"๋ํ INCI": representative,
|
| 3352 |
-
"๊ฒฐ๊ณผ":
|
| 3353 |
-
"ํ์๋ฌธ๊ตฌ":
|
| 3354 |
-
"๋น๊ณ ": f"
|
| 3355 |
}
|
| 3356 |
-
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "
|
| 3357 |
return result
|
| 3358 |
|
| 3359 |
|
|
@@ -3375,24 +3266,22 @@ def evaluate_component_from_country_files_only(country, material, component, tar
|
|
| 3375 |
cas_no = safe_str(component.get("CAS.No", ""))
|
| 3376 |
representative = inci_name or korean_name or cas_no or "-"
|
| 3377 |
|
| 3378 |
-
critical_result =
|
| 3379 |
-
|
| 3380 |
-
|
| 3381 |
-
|
| 3382 |
-
|
| 3383 |
-
component=component,
|
| 3384 |
-
)
|
| 3385 |
|
| 3386 |
-
|
| 3387 |
-
|
| 3388 |
-
|
| 3389 |
-
|
| 3390 |
-
|
| 3391 |
-
|
| 3392 |
-
|
| 3393 |
-
|
| 3394 |
-
|
| 3395 |
-
|
| 3396 |
|
| 3397 |
if is_always_pass_component(material, component):
|
| 3398 |
result = {
|
|
@@ -3559,34 +3448,32 @@ def process_single_ingredient(
|
|
| 3559 |
final_result = None
|
| 3560 |
source = ""
|
| 3561 |
|
| 3562 |
-
critical_result =
|
| 3563 |
-
|
| 3564 |
-
|
| 3565 |
-
|
| 3566 |
-
|
| 3567 |
-
component=component,
|
| 3568 |
-
)
|
| 3569 |
|
| 3570 |
-
|
| 3571 |
-
|
| 3572 |
-
|
| 3573 |
-
|
| 3574 |
-
|
| 3575 |
-
|
| 3576 |
-
|
| 3577 |
-
|
| 3578 |
-
|
| 3579 |
|
| 3580 |
-
|
| 3581 |
-
|
| 3582 |
-
|
| 3583 |
-
|
| 3584 |
-
|
| 3585 |
-
|
| 3586 |
-
|
| 3587 |
-
|
| 3588 |
|
| 3589 |
-
|
| 3590 |
|
| 3591 |
if is_always_pass_component(material, component):
|
| 3592 |
result_rows.append({
|
|
@@ -3609,17 +3496,15 @@ def process_single_ingredient(
|
|
| 3609 |
|
| 3610 |
continue
|
| 3611 |
|
| 3612 |
-
fragrance_result =
|
| 3613 |
-
|
| 3614 |
-
|
| 3615 |
-
|
| 3616 |
-
|
| 3617 |
-
component=component,
|
| 3618 |
-
)
|
| 3619 |
|
| 3620 |
-
|
| 3621 |
-
|
| 3622 |
-
|
| 3623 |
|
| 3624 |
if final_result is None and mfds_df is not None and not mfds_df.empty:
|
| 3625 |
mfds_result = evaluate_live_detail_rule(
|
|
@@ -3645,7 +3530,7 @@ def process_single_ingredient(
|
|
| 3645 |
final_result = file_result
|
| 3646 |
source = "COUNTRY_FILE_FAST"
|
| 3647 |
|
| 3648 |
-
if final_result is None
|
| 3649 |
local_result = evaluate_local_rules(
|
| 3650 |
country=country,
|
| 3651 |
material=material,
|
|
@@ -3706,8 +3591,12 @@ def process_single_ingredient(
|
|
| 3706 |
"โ
๋จ์ผ ์ฑ๋ถ ๊ฒ์ ์๋ฃ\n"
|
| 3707 |
f"- ๊ฒ์์ด: {safe_str(single_query)}\n"
|
| 3708 |
f"- ์ ํ ๊ตญ๊ฐ ์: {len(countries)}๊ฐ\n"
|
| 3709 |
-
"- MFDS ์ํ:
|
| 3710 |
-
"-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3711 |
)
|
| 3712 |
return result_df, msg
|
| 3713 |
|
|
@@ -3732,17 +3621,25 @@ DEFAULT_ADMIN_EMAIL = os.getenv("ADMIN_EMAIL", "jin2li@rebom.kr").strip().lower(
|
|
| 3732 |
DEFAULT_ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD", "qwer0515!")
|
| 3733 |
|
| 3734 |
|
| 3735 |
-
def process_with_auth(user, countries, file, product_name=""):
|
| 3736 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3737 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3738 |
|
| 3739 |
-
def process_single_ingredient_with_auth(user, countries, single_query, single_amount, single_function):
|
| 3740 |
return process_single_ingredient(
|
| 3741 |
countries,
|
| 3742 |
single_query,
|
| 3743 |
single_amount,
|
| 3744 |
single_function,
|
| 3745 |
-
|
| 3746 |
)
|
| 3747 |
|
| 3748 |
|
|
@@ -3758,17 +3655,17 @@ def auth_fn(username, password):
|
|
| 3758 |
# Gradio ๊ธฐ๋ณธ auth ์ฌ์ฉ ์ ๋ด๋ถ ๋ก๊ทธ์ธ ์ฒดํฌ ์ฐํ
|
| 3759 |
# ============================================================
|
| 3760 |
|
| 3761 |
-
def process_with_auth(user, countries, file, product_name=""):
|
| 3762 |
-
return process(countries, file, product_name,
|
| 3763 |
|
| 3764 |
|
| 3765 |
-
def process_single_ingredient_with_auth(user, countries, single_query, single_amount, single_function):
|
| 3766 |
return process_single_ingredient(
|
| 3767 |
countries,
|
| 3768 |
single_query,
|
| 3769 |
single_amount,
|
| 3770 |
single_function,
|
| 3771 |
-
|
| 3772 |
)
|
| 3773 |
|
| 3774 |
|
|
@@ -3794,17 +3691,17 @@ def auth_fn(username, password):
|
|
| 3794 |
return USER_DB.get(username) == password
|
| 3795 |
|
| 3796 |
|
| 3797 |
-
def process_with_auth(user, countries, file, product_name=""):
|
| 3798 |
-
return process(countries, file, product_name,
|
| 3799 |
|
| 3800 |
|
| 3801 |
-
def process_single_ingredient_with_auth(user, countries, single_query, single_amount, single_function):
|
| 3802 |
return process_single_ingredient(
|
| 3803 |
countries,
|
| 3804 |
single_query,
|
| 3805 |
single_amount,
|
| 3806 |
single_function,
|
| 3807 |
-
|
| 3808 |
)
|
| 3809 |
|
| 3810 |
|
|
@@ -3835,17 +3732,17 @@ def auth_fn(username, password):
|
|
| 3835 |
|
| 3836 |
|
| 3837 |
# Gradio ๊ธฐ๋ณธ auth๋ฅผ ํต๊ณผํ ์ฌ์ฉ์๋ ์ด๋ฏธ ์ธ์ฆ๋ ์ํ์ด๋ฏ๋ก ๋ด๋ถ ๋ก๊ทธ์ธ ์ฒดํฌ๋ฅผ ํ์ง ์๋๋ค.
|
| 3838 |
-
def process_with_auth(user, countries, file, product_name=""):
|
| 3839 |
-
return process(countries, file, product_name,
|
| 3840 |
|
| 3841 |
|
| 3842 |
-
def process_single_ingredient_with_auth(user, countries, single_query, single_amount, single_function):
|
| 3843 |
return process_single_ingredient(
|
| 3844 |
countries,
|
| 3845 |
single_query,
|
| 3846 |
single_amount,
|
| 3847 |
single_function,
|
| 3848 |
-
|
| 3849 |
)
|
| 3850 |
|
| 3851 |
|
|
@@ -3871,17 +3768,17 @@ def auth_fn(username, password):
|
|
| 3871 |
return USER_DB.get(username) == password
|
| 3872 |
|
| 3873 |
|
| 3874 |
-
def process_with_auth(user, countries, file, product_name=""):
|
| 3875 |
-
return process(countries, file, product_name,
|
| 3876 |
|
| 3877 |
|
| 3878 |
-
def process_single_ingredient_with_auth(user, countries, single_query, single_amount, single_function):
|
| 3879 |
return process_single_ingredient(
|
| 3880 |
countries,
|
| 3881 |
single_query,
|
| 3882 |
single_amount,
|
| 3883 |
single_function,
|
| 3884 |
-
|
| 3885 |
)
|
| 3886 |
|
| 3887 |
|
|
@@ -3907,17 +3804,17 @@ def auth_fn(username, password):
|
|
| 3907 |
return USER_DB.get(username) == password
|
| 3908 |
|
| 3909 |
|
| 3910 |
-
def process_with_auth(user, countries, file, product_name=""):
|
| 3911 |
-
return process(countries, file, product_name,
|
| 3912 |
|
| 3913 |
|
| 3914 |
-
def process_single_ingredient_with_auth(user, countries, single_query, single_amount, single_function):
|
| 3915 |
return process_single_ingredient(
|
| 3916 |
countries,
|
| 3917 |
single_query,
|
| 3918 |
single_amount,
|
| 3919 |
single_function,
|
| 3920 |
-
|
| 3921 |
)
|
| 3922 |
|
| 3923 |
|
|
@@ -3955,83 +3852,175 @@ def auth_fn(username, password):
|
|
| 3955 |
return USER_DB.get(username) == password
|
| 3956 |
|
| 3957 |
|
| 3958 |
-
def process_with_auth(user, countries, file, product_name=""):
|
| 3959 |
-
return process(countries, file, product_name,
|
| 3960 |
|
| 3961 |
|
| 3962 |
-
def process_single_ingredient_with_auth(user, countries, single_query, single_amount, single_function):
|
| 3963 |
return process_single_ingredient(
|
| 3964 |
countries,
|
| 3965 |
single_query,
|
| 3966 |
single_amount,
|
| 3967 |
single_function,
|
| 3968 |
-
|
| 3969 |
)
|
| 3970 |
|
| 3971 |
-
|
| 3972 |
-
|
| 3973 |
# ============================================================
|
| 3974 |
-
#
|
| 3975 |
-
#
|
| 3976 |
-
# - ์
๋ก๋ํ ๊ตญ๊ฐ๋ณ ํ์ผ์์ ์ง์ ํ์ธ๋ ๊ทผ๊ฑฐ๋ง ์ฌ์ฉ
|
| 3977 |
-
# - ํ๋์ฝ๋ฉ UV/๋ณด์กด์ /๊ธฐ๋ฅ์ฑ/ํฅ๋ฃ/critical ๊ท์น ์๋ํ์ ์ฐจ๋จ
|
| 3978 |
-
# - ๋ง์ง๋ง ํ ์์ฑ ๋จ๊ณ์์ ์ฑ๋ถ๋ช
๋ง ๋ณด๊ณ ํ๋ ์ฌ์์ฑ๋๋ ๋ฌธ์ ์ฐจ๋จ
|
| 3979 |
-
# - Positive List๋ ํ๋ ์์น๊ฐ ๋ช
ํํ ๋๋ง ํ๋ ํ์, ์๋๋ฉด Pass
|
| 3980 |
-
# - ๊ธ์ง/์ ํ ๋ฌธ๊ตฌ๊ฐ ๋ช
ํํ์ง ์์ผ๋ฉด ๋ฌธ์ ์ฑ๋ถ์ผ๋ก ๋ง๋ค์ง ์์
|
| 3981 |
# ============================================================
|
| 3982 |
|
| 3983 |
SOURCE_ONLY_MODE = True
|
| 3984 |
TREAT_POSITIVE_LIST_AS_PASS = True
|
| 3985 |
|
| 3986 |
-
|
| 3987 |
"๋ฐฐํฉ๊ธ์ง", "์ฌ์ฉ๊ธ์ง", "์ฌ์ฉ ๊ธ์ง", "๊ธ์ง์๋ฃ", "๊ธ์ง ์๋ฃ", "๊ธ์ง์ฑ๋ถ", "๊ธ์ง ์ฑ๋ถ",
|
| 3988 |
"prohibited", "banned", "not allowed", "shall not be used", "must not be used",
|
| 3989 |
"shall not contain", "must not contain", "forbidden",
|
| 3990 |
]
|
| 3991 |
|
| 3992 |
-
|
| 3993 |
"๋ฐฐํฉํ๋", "๋ฐฐํฉ ํ๋", "์ฌ์ฉํ๋", "์ฌ์ฉ ํ๋", "์ฌ์ฉ์ ํ", "์ฌ์ฉ ์ ํ",
|
| 3994 |
"์ ํ์ฌํญ", "์ ํ ์ฌํญ", "์ ํ์ฑ๋ถ", "์ ํ ์ฑ๋ถ",
|
| 3995 |
"restricted", "restriction", "maximum concentration", "maximum amount",
|
| 3996 |
-
"max concentration", "not exceeding", "not exceed", "limit",
|
| 3997 |
]
|
| 3998 |
|
| 3999 |
-
|
| 4000 |
-
"positive list", "ํ์ฉ๋ชฉ๋ก", "ํ์ฉ ๋ชฉ๋ก", "annex iv", "annex v", "annex vi",
|
| 4001 |
-
"coloring agents", "colouring agents", "colorants", "preservatives",
|
| 4002 |
-
"uv filters", "sunscreen agents", "์์", "๋ณด์กด์ ", "๋ฐฉ๋ถ์ ", "์์ธ์ ", "์์ธ์ ์ฐจ๋จ",
|
| 4003 |
-
]
|
| 4004 |
-
|
| 4005 |
-
FALSE_LIMIT_CONTEXT_TERMS = [
|
| 4006 |
"label", "labelling", "labeling", "๋ผ๋ฒจ", "ํ์", "warning", "๊ฒฝ๊ณ ",
|
| 4007 |
-
"allergen", "์๋ ๋ฅด๊ฒ", "impurity", "impurities", "๋ถ์๋ฌผ",
|
| 4008 |
"test method", "์ํ๋ฒ", "์ํ", "analysis", "๋ถ์", "purity", "์๋",
|
| 4009 |
-
"๊ฒ์ถํ๊ณ", "๊ด๋ฆฌ๊ฐ", "๊ด๋ฆฌ์น", "peroxide value",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4010 |
]
|
| 4011 |
|
| 4012 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4013 |
text = safe_str(text)
|
| 4014 |
low = text.lower()
|
| 4015 |
compact = normalize_compact(text)
|
| 4016 |
for term in terms:
|
| 4017 |
-
|
| 4018 |
-
if not
|
| 4019 |
continue
|
| 4020 |
-
if
|
| 4021 |
return True
|
| 4022 |
-
if normalize_compact(
|
| 4023 |
return True
|
| 4024 |
return False
|
| 4025 |
|
| 4026 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4027 |
record_text = safe_str(record_text)
|
| 4028 |
if not record_text:
|
| 4029 |
return False
|
| 4030 |
for term in terms:
|
| 4031 |
term = safe_str(term)
|
| 4032 |
-
if not term:
|
| 4033 |
-
continue
|
| 4034 |
-
if len(normalize_compact(term)) < 3:
|
| 4035 |
continue
|
| 4036 |
if is_broad_lookup_term(term):
|
| 4037 |
continue
|
|
@@ -4044,123 +4033,171 @@ def _strict_component_match_in_record(record_text, terms):
|
|
| 4044 |
return True
|
| 4045 |
return False
|
| 4046 |
|
| 4047 |
-
def _strict_get_record_type(country, record):
|
| 4048 |
-
source_file = safe_str(record.get("source_file", ""))
|
| 4049 |
-
sheet = safe_str(record.get("sheet", ""))
|
| 4050 |
-
text = safe_str(record.get("text", ""))
|
| 4051 |
-
meta = f"{source_file}\n{sheet}"
|
| 4052 |
-
meta_low = meta.lower()
|
| 4053 |
-
|
| 4054 |
-
if (
|
| 4055 |
-
"annex ii" in meta_low or "annex_ii" in meta_low or "annex-ii" in meta_low
|
| 4056 |
-
or "negative list" in meta_low or "prohibited" in meta_low or "๊ธ์ง" in meta
|
| 4057 |
-
):
|
| 4058 |
-
return "prohibited"
|
| 4059 |
-
|
| 4060 |
-
if (
|
| 4061 |
-
"annex iii" in meta_low or "annex_iii" in meta_low or "annex-iii" in meta_low
|
| 4062 |
-
or "restricted" in meta_low or "restriction" in meta_low
|
| 4063 |
-
or "์ ํ" in meta or "๋ฐฐํฉํ๋" in meta
|
| 4064 |
-
):
|
| 4065 |
-
return "restricted"
|
| 4066 |
-
|
| 4067 |
-
if (
|
| 4068 |
-
"annex iv" in meta_low or "annex v" in meta_low or "annex vi" in meta_low
|
| 4069 |
-
or "positive" in meta_low or "colorant" in meta_low or "coloring" in meta_low
|
| 4070 |
-
or "colouring" in meta_low or "preservative" in meta_low
|
| 4071 |
-
or "uv filter" in meta_low or "sunscreen" in meta_low
|
| 4072 |
-
or "์์" in meta or "๋ณด์กด์ " in meta or "๋ฐฉ๋ถ์ " in meta or "์์ธ์ " in meta
|
| 4073 |
-
):
|
| 4074 |
-
return "positive"
|
| 4075 |
-
|
| 4076 |
-
if _strict_contains_any(text, STRICT_PROHIBITED_TERMS):
|
| 4077 |
-
return "prohibited"
|
| 4078 |
-
if _strict_contains_any(text, STRICT_RESTRICTED_TERMS):
|
| 4079 |
-
return "restricted"
|
| 4080 |
-
if _strict_contains_any(text, POSITIVE_LIST_TERMS):
|
| 4081 |
-
return "positive"
|
| 4082 |
-
return "unknown"
|
| 4083 |
|
| 4084 |
def extract_limit_condition_from_context(context):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4085 |
text = safe_str(context)
|
| 4086 |
compact = re.sub(r"\s+", " ", text).strip()
|
| 4087 |
if not compact:
|
| 4088 |
return "", ""
|
| 4089 |
-
|
|
|
|
|
|
|
|
|
|
| 4090 |
return "", ""
|
| 4091 |
-
|
|
|
|
| 4092 |
return "", ""
|
| 4093 |
|
| 4094 |
-
|
|
|
|
| 4095 |
r"([0-9]+(?:\.[0-9]+)?\s*%)",
|
| 4096 |
r"([0-9]+(?:\.[0-9]+)?\s*g\s*/\s*100\s*g)",
|
| 4097 |
r"([0-9]+(?:\.[0-9]+)?\s*g\s+per\s+100\s*g)",
|
| 4098 |
-
]
|
| 4099 |
-
limits = []
|
| 4100 |
-
for pat in patterns:
|
| 4101 |
for m in re.finditer(pat, compact, flags=re.IGNORECASE):
|
| 4102 |
v = m.group(1).replace(" ", "")
|
| 4103 |
if v not in limits:
|
| 4104 |
limits.append(v)
|
| 4105 |
|
|
|
|
| 4106 |
condition_keywords = [
|
| 4107 |
-
"leave-on", "rinse-off", "
|
| 4108 |
-
"๋ณด์กด์ ", "๋ฐฉ๋ถ์ ", "์์ธ์ ", "์์", "์ ๋ง", "๊ตฌ๊ฐ",
|
| 4109 |
-
"์
|
| 4110 |
]
|
| 4111 |
-
condition_lines = []
|
| 4112 |
for line in [safe_str(x) for x in text.splitlines() if safe_str(x)]:
|
| 4113 |
line_low = line.lower()
|
| 4114 |
if any(k.lower() in line_low for k in condition_keywords):
|
| 4115 |
cleaned = re.sub(r"\s+", " ", line).strip()
|
| 4116 |
if cleaned not in condition_lines:
|
| 4117 |
condition_lines.append(cleaned)
|
|
|
|
| 4118 |
return ", ".join(limits[:5]), " / ".join(condition_lines[:5])[:700]
|
| 4119 |
|
|
|
|
| 4120 |
def normalize_formula_country_text(text, country_col="", inci_name="", amount_text=""):
|
| 4121 |
text = safe_str(text)
|
| 4122 |
-
if not text:
|
| 4123 |
-
return "Pass"
|
| 4124 |
-
if text in ["-", NO_EVIDENCE_TEXT, "Pass", "PASS", "pass"]:
|
| 4125 |
return "Pass"
|
| 4126 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4127 |
return "๋ฐฐํฉ๊ธ์ง"
|
| 4128 |
limit_text, condition_text = extract_limit_condition_from_context(text)
|
| 4129 |
if limit_text:
|
| 4130 |
return f"๋ฐฐํฉํ๋: {limit_text}"
|
| 4131 |
-
if
|
| 4132 |
return NEED_CHECK_TEXT
|
| 4133 |
-
if _strict_contains_any(text, POSITIVE_LIST_TERMS):
|
| 4134 |
-
return "Pass"
|
| 4135 |
-
if NEED_CHECK_TEXT in text or LIMIT_CHECK_TEXT in text:
|
| 4136 |
-
return NEED_CHECK_TEXT
|
| 4137 |
-
if "ํจ๋ ํ์ธ" in text:
|
| 4138 |
-
return "ํจ๋ ํ์ธ"
|
| 4139 |
return "Pass"
|
| 4140 |
|
|
|
|
| 4141 |
def evaluate_critical_country_rule(country, material, component):
|
| 4142 |
if SOURCE_ONLY_MODE:
|
| 4143 |
return None
|
| 4144 |
return None
|
| 4145 |
|
|
|
|
| 4146 |
def evaluate_plain_fragrance_rule(country, material, component):
|
| 4147 |
if SOURCE_ONLY_MODE:
|
| 4148 |
return None
|
| 4149 |
return None
|
| 4150 |
|
|
|
|
| 4151 |
def evaluate_local_rules(country, material, component, ingredient_totals, ingredient_amount_parts):
|
| 4152 |
if SOURCE_ONLY_MODE:
|
| 4153 |
return None
|
| 4154 |
return None
|
| 4155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4156 |
def evaluate_component_from_uploaded_source_records(country, material, component, target_id=""):
|
| 4157 |
terms = source_match_terms_for_component(material, component)
|
| 4158 |
-
representative = (
|
| 4159 |
-
safe_str(component.get("INCI Name", ""))
|
| 4160 |
-
or safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", ""))
|
| 4161 |
-
or safe_str(component.get("CAS.No", ""))
|
| 4162 |
-
or "-"
|
| 4163 |
-
)
|
| 4164 |
if not terms:
|
| 4165 |
return None
|
| 4166 |
|
|
@@ -4168,102 +4205,87 @@ def evaluate_component_from_uploaded_source_records(country, material, component
|
|
| 4168 |
hits = []
|
| 4169 |
for rec in records:
|
| 4170 |
rec_text = safe_str(rec.get("text", ""))
|
| 4171 |
-
if
|
| 4172 |
hits.append(rec)
|
| 4173 |
|
| 4174 |
if not hits:
|
| 4175 |
return None
|
| 4176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4177 |
country_col = display_country(country)
|
| 4178 |
-
prohibited_hits = []
|
| 4179 |
-
restricted_hits = []
|
| 4180 |
-
positive_hits = []
|
| 4181 |
-
unknown_hits = []
|
| 4182 |
-
|
| 4183 |
-
for rec in hits:
|
| 4184 |
-
rec_type = _strict_get_record_type(country, rec)
|
| 4185 |
-
if rec_type == "prohibited":
|
| 4186 |
-
prohibited_hits.append(rec)
|
| 4187 |
-
elif rec_type == "restricted":
|
| 4188 |
-
restricted_hits.append(rec)
|
| 4189 |
-
elif rec_type == "positive":
|
| 4190 |
-
positive_hits.append(rec)
|
| 4191 |
-
else:
|
| 4192 |
-
unknown_hits.append(rec)
|
| 4193 |
|
| 4194 |
-
if
|
| 4195 |
-
best = prohibited_hits[0]
|
| 4196 |
-
context = safe_str(best.get("text", ""))
|
| 4197 |
result = {
|
| 4198 |
"๋ํ INCI": representative,
|
| 4199 |
-
"๊ฒฐ๊ณผ": f"{country_col} ์
๋ก๋ ํ์ผ์์
|
| 4200 |
"ํ์๋ฌธ๊ตฌ": "๋ฐฐํฉ๊ธ์ง",
|
| 4201 |
-
"๋น๊ณ ":
|
| 4202 |
}
|
| 4203 |
-
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "
|
| 4204 |
return result
|
| 4205 |
|
| 4206 |
-
if
|
| 4207 |
-
best = restricted_hits[0]
|
| 4208 |
-
context = safe_str(best.get("text", ""))
|
| 4209 |
limit_text, condition_text = extract_limit_condition_from_context(context)
|
| 4210 |
-
|
| 4211 |
-
|
| 4212 |
-
|
| 4213 |
-
|
| 4214 |
-
|
| 4215 |
-
|
| 4216 |
-
|
| 4217 |
-
else:
|
| 4218 |
-
result = {
|
| 4219 |
-
"๋ํ INCI": representative,
|
| 4220 |
-
"๊ฒฐ๊ณผ": f"{country_col} ์
๋ก๋ ํ์ผ์์ ์ ํ ๊ทผ๊ฑฐ ์ง์ ํ์ธ / ํ๋ ์์น ํ์ธ ํ์",
|
| 4221 |
-
"ํ์๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
|
| 4222 |
-
"๋น๊ณ ": f"[์ถ์ฒํ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
|
| 4223 |
-
}
|
| 4224 |
-
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "STRICT_SOURCE_RESTRICTED", result["๋น๊ณ "])
|
| 4225 |
return result
|
| 4226 |
|
| 4227 |
-
if
|
| 4228 |
-
best = positive_hits[0]
|
| 4229 |
-
context = safe_str(best.get("text", ""))
|
| 4230 |
limit_text, condition_text = extract_limit_condition_from_context(context)
|
| 4231 |
if limit_text:
|
| 4232 |
result = {
|
| 4233 |
"๋ํ INCI": representative,
|
| 4234 |
-
"๊ฒฐ๊ณผ": f"{country_col} ํ์ฉ๋ชฉ๋ก์์ ์ฑ๋ถ ์ง์ ํ์ธ / ํ๋ {limit_text}" + (f" / ์กฐ๊ฑด: {condition_text}" if condition_text else ""),
|
| 4235 |
"ํ์๋ฌธ๊ตฌ": f"๋ฐฐํฉํ๋: {limit_text}",
|
| 4236 |
-
"๋น๊ณ ":
|
| 4237 |
}
|
| 4238 |
-
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "
|
| 4239 |
return result
|
| 4240 |
-
|
| 4241 |
result = {
|
| 4242 |
"๋ํ INCI": representative,
|
| 4243 |
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 4244 |
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 4245 |
-
"๋น๊ณ ":
|
| 4246 |
}
|
| 4247 |
-
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "
|
| 4248 |
return result
|
| 4249 |
|
| 4250 |
-
|
| 4251 |
-
|
|
|
|
| 4252 |
result = {
|
| 4253 |
"๋ํ INCI": representative,
|
| 4254 |
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 4255 |
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 4256 |
-
"๋น๊ณ ":
|
| 4257 |
}
|
| 4258 |
-
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "
|
| 4259 |
return result
|
| 4260 |
|
|
|
|
| 4261 |
def evaluate_component_from_country_files_only(country, material, component, target_id=""):
|
| 4262 |
-
|
| 4263 |
-
inci_name = safe_str(component.get("INCI Name", ""))
|
| 4264 |
-
korean_name = safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", ""))
|
| 4265 |
-
cas_no = safe_str(component.get("CAS.No", ""))
|
| 4266 |
-
representative = inci_name or korean_name or cas_no or "-"
|
| 4267 |
|
| 4268 |
if is_always_pass_component(material, component):
|
| 4269 |
result = {
|
|
@@ -4275,12 +4297,7 @@ def evaluate_component_from_country_files_only(country, material, component, tar
|
|
| 4275 |
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "ALWAYS_PASS_RULE", result["๋น๊ณ "])
|
| 4276 |
return result
|
| 4277 |
|
| 4278 |
-
source_result = evaluate_component_from_uploaded_source_records(
|
| 4279 |
-
country=country,
|
| 4280 |
-
material=material,
|
| 4281 |
-
component=component,
|
| 4282 |
-
target_id=target_id,
|
| 4283 |
-
)
|
| 4284 |
if source_result is not None:
|
| 4285 |
return source_result
|
| 4286 |
|
|
@@ -4290,33 +4307,24 @@ def evaluate_component_from_country_files_only(country, material, component, tar
|
|
| 4290 |
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 4291 |
"๋น๊ณ ": "์
๋ก๋๋ ๊ตญ๊ฐ๋ณ ํ์ผ ๋ด ํ์ฌ ์ฑ๋ถ ์ง์ ๊ทผ๊ฑฐ ์์",
|
| 4292 |
}
|
| 4293 |
-
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "
|
| 4294 |
return result
|
| 4295 |
|
|
|
|
| 4296 |
def is_country_result_issue(text):
|
| 4297 |
text = safe_str(text)
|
| 4298 |
-
if not text:
|
| 4299 |
return False
|
| 4300 |
-
if
|
| 4301 |
return False
|
| 4302 |
-
|
| 4303 |
-
|
| 4304 |
-
|
| 4305 |
-
|
| 4306 |
-
|
| 4307 |
-
return True
|
| 4308 |
-
if LIMIT_CHECK_TEXT in text:
|
| 4309 |
-
return True
|
| 4310 |
-
if "ํ๋ ์ด๊ณผ" in text:
|
| 4311 |
-
return True
|
| 4312 |
-
if "๋ถ์ ํฉ" in text or "์ฌ๊ฒํ " in text or "์ฌ์ฉ ๋ถ๊ฐ" in text or "์ฌ์ฉ๋ถ๊ฐ" in text:
|
| 4313 |
-
return True
|
| 4314 |
-
if _strict_contains_any(text, STRICT_RESTRICTED_TERMS):
|
| 4315 |
-
return True
|
| 4316 |
-
return False
|
| 4317 |
|
| 4318 |
# ============================================================
|
| 4319 |
-
# END
|
| 4320 |
# ============================================================
|
| 4321 |
|
| 4322 |
|
|
@@ -4418,6 +4426,9 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 4418 |
refresh=gr.Button("๐ ํด๋/๊ท์ ํ์ผ ์๋ก๊ณ ์นจ")
|
| 4419 |
product_name=gr.Textbox(label="์ ํ๋ช
/ PRODUCT NAME",placeholder="์: ๋ง๋ฐ์นดํฌ๋ฆผ")
|
| 4420 |
file=gr.File(label="์ ์ฑ๋ถ ํ์ผ ์
๋ก๋",file_types=[".xlsx",".xls",".pdf",".png",".jpg",".jpeg",".webp"])
|
|
|
|
|
|
|
|
|
|
| 4421 |
btn=gr.Button("๐ ๋ถ์ ์์",variant="primary")
|
| 4422 |
df_out=gr.Dataframe(label="๋ฏธ๋ฆฌ๋ณด๊ธฐ - Formula Ingredients Statement",wrap=True,interactive=False)
|
| 4423 |
file_out=gr.File(label="๊ฒฐ๊ณผ ๋ค์ด๋ก๋")
|
|
@@ -4428,7 +4439,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 4428 |
|
| 4429 |
btn.click(
|
| 4430 |
process_with_auth,
|
| 4431 |
-
inputs=[current_user,country,file,product_name],
|
| 4432 |
outputs=[df_out,file_out,msg_out],
|
| 4433 |
)
|
| 4434 |
|
|
@@ -4441,6 +4452,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 4441 |
with gr.Row():
|
| 4442 |
single_amount=gr.Textbox(label="ํจ๋ %(w/w) ์ ํ ์
๋ ฅ",placeholder="์: 7.2")
|
| 4443 |
single_function=gr.Textbox(label="FUNCTION ์ ํ ์
๋ ฅ",placeholder="์: Sunscreen Agent")
|
|
|
|
| 4444 |
single_btn=gr.Button("๐ ๋จ์ผ ์ฑ๋ถ ๊ฒ์ ์์",variant="primary")
|
| 4445 |
single_df_out=gr.Dataframe(label="๋จ์ผ ์ฑ๋ถ ๊ฒ์ ๊ฒฐ๊ณผ",wrap=True,interactive=False)
|
| 4446 |
single_msg_out=gr.Textbox(label="๊ฒ์ ์ํ / ๋ฉ์์ง",interactive=False,lines=8)
|
|
@@ -4449,7 +4461,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 4449 |
|
| 4450 |
single_btn.click(
|
| 4451 |
process_single_ingredient_with_auth,
|
| 4452 |
-
inputs=[current_user,single_country,single_query,single_amount,single_function],
|
| 4453 |
outputs=[single_df_out,single_msg_out],
|
| 4454 |
)
|
| 4455 |
try:
|
|
|
|
| 1 |
# APP_PATCH_NOTE_SPEED_MFDS_BATCH_OFF = "์ ์ฒด ์คํฌ๋ฆฌ๋ ์๋ ์๊ธํจ์น: MFDS ์ค์๊ฐ ์กฐํ ๋ฐฐ์น ๋นํ์ฑํ + ๋งค์นญ ์บ์"
|
| 2 |
# APP_PATCH_NOTE_LIMIT_POSITIVE_MFDS = "Positive List ํ๋ํ์ธ + MFDS ์ ํ ํ์ฑ ๋ณด๊ฐ ์ ์ฉ๋ณธ"
|
|
|
|
| 3 |
# ============================================================
|
| 4 |
+
# reBom Regulatory Screening AI - Fast Grounded Fixed Version
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
# - ๊ตญ๊ฐ/์ฑ๋ ํด๋ ์๋ ์ธ์
|
| 6 |
# - ๊ท์ ํ์ผ ์๋ ๋ณ๊ฒฝ ๊ฐ์ง
|
| 7 |
+
# - ๊ตญ๊ฐ๋ณ FAISS ๋ฒกํฐ DB ๋์คํฌ ์บ์
|
| 8 |
+
# - ๊ตญ๊ฐ๋ณ ๋ฌธ์ ๊ฒฉ๋ฆฌ ๊ฒ์์ผ๋ก ํ๊ตญ ๊ท์ ํ์ฐ ๋ฐฉ์ง
|
| 9 |
+
# - ๋ก์ปฌ ๊ท์น ์ฐ์ ํ์
|
| 10 |
+
# - MFDS ์์ฝํ์์ ๋๋ผ ์์ธ DB ์์
์ฐ๋
|
| 11 |
+
# - GPT ํธ์ถ ์ ์๋ฏธ ์๋ ๊ฒ์๊ฒฐ๊ณผ ํํฐ๋ง
|
| 12 |
# - Formula Ingredients Statement ์๋ณธ ์์ ์ถ๋ ฅ
|
| 13 |
# - ๋ฌธ์ ์ฑ๋ถ๋ง Regulatory Screening Summary ์ถ๋ ฅ
|
| 14 |
+
# - Raw Search Log ๋ณ๋ ์ ์ฅ
|
| 15 |
# - Gradio ๋ก๊ทธ์ธ ์ธ์ฆ / public share link ์ ์ฉ
|
| 16 |
# - MergedCell column_letter ์ค๋ฅ ์์ ์๋ฃ
|
| 17 |
# - ์์
์ ์ฑ๋ถ ์ ์ฒด ์คํฌ๋ฆฌ๋
|
| 18 |
# - ๋จ์ผ ์ฑ๋ถ ๊ฒ์
|
| 19 |
+
# - ์ ์ฒด ์คํฌ๋ฆฌ๋: MFDS ๊ฒ์์ด 0๊ฐ ๋ฐฉ์ง
|
| 20 |
+
# - ๋จ์ผ ์ฑ๋ถ ๊ฒ์์ ์์ฝ์ฒ ์ค์๊ฐ ์กฐํ ์ฌ์ฉ
|
| 21 |
+
# - ๊ตญ๊ฐ๋ณ ๊ท์ ํด๋ ๊ฒ์
|
| 22 |
+
# - FAISS ๋์คํฌ ์บ์
|
| 23 |
+
# - ํฅ๋ฃ๋ ์ ๊ตญ๊ฐ ํ์ธ ํ์
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
# - ์ ์ ์ / Water / Aqua๋ ์ ๊ตญ๊ฐ ๊ธฐ๋ณธ Pass
|
| 25 |
+
# - ๊ตญ๊ฐ๋ณ ํต์ฌ ๊ธ์ง/์ ํ ์ฑ๋ถ์ GPT/RAG๋ณด๋ค ์ฐ์ ํ์
|
| 26 |
+
# - Tranexamic Acid๋ ์ผ๋ณธ ๋ฐฐํฉ๊ธ์ง ์ฐ์ ์ฒ๋ฆฌ
|
| 27 |
+
# - ๊ณ ์ํ ์ฑ๋ถ Pass ์๋ ๋ฐฉ์ง
|
| 28 |
+
# - Formular Ingredients Statement ์์ ์ถ๋ ฅ
|
| 29 |
+
# - ์๋ณธ TOTAL ํ ์ ๊ฑฐ ํ ์ TOTAL ํ 1๊ฐ๋ง ์์ฑ
|
| 30 |
+
# - ์ซ์ ์๋ '๋ฐฐํฉํ๋'๋ '๋ฐฐํฉํ๋ ํ์ธ ํ์'๋ก ํ์
|
| 31 |
+
# - Salicylic Acid ์์ฒด๋ง ์ ํ ํ๋ณด ์ฒ๋ฆฌ
|
| 32 |
+
# - Niacinamide/Adenosine์ ํ๊ตญ์์๋ง ๊ธฐ๋ฅ์ฑ ํ์ธ ์ฒ๋ฆฌ
|
| 33 |
# ============================================================
|
| 34 |
|
| 35 |
# reBom Regulatory Screening AI - compact full app.py
|
|
|
|
| 75 |
NO_EVIDENCE_TEXT = "ํด๋น ์๋ฃ ๋ด ์ ํ ๊ทผ๊ฑฐ ์์"
|
| 76 |
NEED_CHECK_TEXT = "ํ์ธ ํ์"
|
| 77 |
LIMIT_CHECK_TEXT = "๋ฐฐํฉํ๋ ํ์ธ ํ์"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
MFDS_LIVE_URL = "https://nedrug.mfds.go.kr/pbp/CCBDF01"
|
| 79 |
# ์๋ ์๊ธํจ์น
|
| 80 |
# - ์ ์ฒด ์ ์ฑ๋ถ ์คํฌ๋ฆฌ๋์์๋ MFDS ์ฌ์ดํธ ์ค์๊ฐ ์กฐํ๋ฅผ ๊ธฐ๋ณธ์ ์ผ๋ก ์ฌ์ฉํ์ง ์๋๋ค.
|
|
|
|
| 2203 |
final_result = None
|
| 2204 |
source = ""
|
| 2205 |
|
| 2206 |
+
final_result = evaluate_critical_country_rule(
|
| 2207 |
+
country=country,
|
| 2208 |
+
material=mat,
|
| 2209 |
+
component=comp,
|
| 2210 |
+
)
|
|
|
|
| 2211 |
|
| 2212 |
+
if final_result is not None:
|
| 2213 |
+
source = "CRITICAL_COUNTRY_RULE"
|
| 2214 |
|
| 2215 |
if final_result is None and is_always_pass_component(mat, comp):
|
| 2216 |
final_result = {
|
|
|
|
| 2221 |
}
|
| 2222 |
source = "ALWAYS_PASS_RULE"
|
| 2223 |
|
| 2224 |
+
if final_result is None:
|
| 2225 |
fragrance_result = evaluate_plain_fragrance_rule(
|
| 2226 |
country=country,
|
| 2227 |
material=mat,
|
|
|
|
| 2256 |
final_result = file_result
|
| 2257 |
source = "COUNTRY_FILE_FAST"
|
| 2258 |
|
| 2259 |
+
if final_result is None:
|
| 2260 |
local_result = evaluate_local_rules(
|
| 2261 |
country=country,
|
| 2262 |
material=mat,
|
|
|
|
| 2320 |
f"- ์ ์ฑ๋ถ ํ ์: {len(formula_df)}๊ฐ\n"
|
| 2321 |
f"- In formula ํฉ๊ณ: {format_amount(sum_formula_percent(formula_df))}%\n"
|
| 2322 |
f"- ์ฌ๊ฒํ ํ์ ์ฑ๋ถ: {len(regulatory_df)}๊ฐ\n"
|
| 2323 |
+
f"- MFDS ์ํ: {mfds_msg}\n"
|
| 2324 |
"- ํ์ ๋ฐฉ์: GPT ํ์ ์์ / ์
๋ก๋๋ ๊ตญ๊ฐ๋ณ ํ์ผ rowยทline ์ง์ ๊ฒ์\n"
|
| 2325 |
f"- ๊ตญ๊ฐ๋ณ ์ธ๋ฑ์ค ์ํ: {' | '.join(index_messages)}\n"
|
| 2326 |
"- ์๋ ๊ฐ์ : ์ ์ฒด ์คํฌ๋ฆฌ๋์์ GPT/LLM ํธ์ถ ์ ๊ฑฐ\n"
|
|
|
|
| 2903 |
|
| 2904 |
|
| 2905 |
def extract_limit_condition_from_context(context):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2906 |
text = safe_str(context)
|
| 2907 |
compact = re.sub(r"\s+", " ", text).strip()
|
|
|
|
| 2908 |
if not compact:
|
| 2909 |
return "", ""
|
| 2910 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2911 |
patterns = [
|
| 2912 |
r"([0-9]+(?:\.[0-9]+)?\s*%)",
|
| 2913 |
+
r"([0-9]+(?:\.[0-9]+)?\s*ppm)",
|
| 2914 |
r"([0-9]+(?:\.[0-9]+)?\s*g\s*/\s*100\s*g)",
|
| 2915 |
r"([0-9]+(?:\.[0-9]+)?\s*g\s+per\s+100\s*g)",
|
| 2916 |
+
r"([0-9]+(?:\.[0-9]+)?\s*mg\s*/\s*kg)",
|
| 2917 |
]
|
|
|
|
| 2918 |
limits = []
|
| 2919 |
for pat in patterns:
|
| 2920 |
+
for m in re.finditer(pat, compact, flags=re.IGNORECASE):
|
| 2921 |
v = m.group(1).replace(" ", "")
|
| 2922 |
if v not in limits:
|
| 2923 |
limits.append(v)
|
| 2924 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2925 |
condition_keywords = [
|
| 2926 |
"leave-on", "rinse-off", "oral", "mucosa", "washed away",
|
| 2927 |
"๋ณด์กด์ ", "๋ฐฉ๋ถ์ ", "์์ธ์ ", "์์", "์ ๋ง", "๊ตฌ๊ฐ",
|
| 2928 |
+
"์ ํ์ฌํญ", "๊ฒฝ๊ณ ", "warning", "condition", "ํ๋", "์ ํ",
|
| 2929 |
]
|
|
|
|
| 2930 |
condition_lines = []
|
| 2931 |
+
for line in [safe_str(x) for x in text.splitlines() if safe_str(x)]:
|
| 2932 |
l = line.lower()
|
| 2933 |
if any(k.lower() in l for k in condition_keywords):
|
| 2934 |
cleaned = re.sub(r"\s+", " ", line).strip()
|
|
|
|
| 2949 |
display = f"๋ฐฐํฉํ๋: {limit_text}"
|
| 2950 |
result = f"{display_country(country)} {label}์์ ์ฑ๋ถ ํ์ธ / ํ๋ {limit_text}"
|
| 2951 |
elif kind.startswith("positive_"):
|
| 2952 |
+
display = "ํ์ฉ๋ชฉ๋ก ๋ฑ์ฌ / ํ๋ ํ์ธ ํ์"
|
| 2953 |
+
result = f"{display_country(country)} {label}์์ ์ฑ๋ถ ํ์ธ / ๋ชฉ์ ๋ณ ํ์ฉ๋ชฉ๋ก ๋ฑ์ฌ, ํ๋ยท์กฐ๊ฑด ํ์ธ ํ์"
|
| 2954 |
else:
|
| 2955 |
display = "๋ฐฐํฉํ๋/์ ํ ํ์ธ"
|
| 2956 |
result = f"{display_country(country)} {label}์์ ์ฑ๋ถ ํ์ธ / ํ๋ยท์กฐ๊ฑด ํ์ธ ํ์"
|
|
|
|
| 3227 |
|
| 3228 |
if reg_kind.startswith("positive_"):
|
| 3229 |
limit_text, condition_text = extract_limit_condition_from_context(context)
|
| 3230 |
+
result = {
|
| 3231 |
+
"๋ํ INCI": representative,
|
| 3232 |
+
"๊ฒฐ๊ณผ": f"{country_col} {reg_label}์์ ์ฑ๋ถ ์ง์ ํ์ธ" + (f" / ์กฐ๊ฑด: {condition_text}" if condition_text else ""),
|
| 3233 |
+
"ํ์๋ฌธ๊ตฌ": f"๋ฐฐํฉํ๋: {limit_text}" if limit_text else "ํ์ฉ๋ชฉ๋ก ๋ฑ์ฌ / ํ๋ ํ์ธ ํ์",
|
| 3234 |
+
"๋น๊ณ ": f"[์ถ์ฒํ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
|
| 3235 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3236 |
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "UPLOADED_SOURCE_RECORD_POSITIVE", result["๋น๊ณ "])
|
| 3237 |
return result
|
| 3238 |
|
| 3239 |
# ํ์ผ์์๋ ์ฑ๋ถ์ ์ฐพ์์ง๋ง ํ์ผ ์ ํ์ด ๋ถ๋ช
ํํ ๊ฒฝ์ฐ:
|
| 3240 |
+
# PASS๋ก ๋จ์ ํ์ง ์๊ณ ํ์ธ ํ์๋ก ํ์. ๋จ, ์ด ๊ฒฝ์ฐ๋ "ํ์ผ ์ง์ ํ์ธ"์ ๋จ๊ธด๋ค.
|
| 3241 |
result = {
|
| 3242 |
"๋ํ INCI": representative,
|
| 3243 |
+
"๊ฒฐ๊ณผ": f"{country_col} ๊ตญ๊ฐ๋ณ ํ์ผ์์ ์ฑ๋ถ ์ง์ ํ์ธ / ํ์ผ ์ ํ ๋ฏธ๋ถ๋ฅ",
|
| 3244 |
+
"ํ์๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
|
| 3245 |
+
"๋น๊ณ ": f"[์ถ์ฒํ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
|
| 3246 |
}
|
| 3247 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "UPLOADED_SOURCE_RECORD_UNKNOWN", result["๋น๊ณ "])
|
| 3248 |
return result
|
| 3249 |
|
| 3250 |
|
|
|
|
| 3266 |
cas_no = safe_str(component.get("CAS.No", ""))
|
| 3267 |
representative = inci_name or korean_name or cas_no or "-"
|
| 3268 |
|
| 3269 |
+
critical_result = evaluate_critical_country_rule(
|
| 3270 |
+
country=country,
|
| 3271 |
+
material=material,
|
| 3272 |
+
component=component,
|
| 3273 |
+
)
|
|
|
|
|
|
|
| 3274 |
|
| 3275 |
+
if critical_result is not None:
|
| 3276 |
+
log_search_context(
|
| 3277 |
+
target_id,
|
| 3278 |
+
country,
|
| 3279 |
+
component,
|
| 3280 |
+
critical_result.get("๊ฒฐ๊ณผ", ""),
|
| 3281 |
+
"CRITICAL_COUNTRY_RULE",
|
| 3282 |
+
critical_result.get("๋น๊ณ ", "-"),
|
| 3283 |
+
)
|
| 3284 |
+
return critical_result
|
| 3285 |
|
| 3286 |
if is_always_pass_component(material, component):
|
| 3287 |
result = {
|
|
|
|
| 3448 |
final_result = None
|
| 3449 |
source = ""
|
| 3450 |
|
| 3451 |
+
critical_result = evaluate_critical_country_rule(
|
| 3452 |
+
country=country,
|
| 3453 |
+
material=material,
|
| 3454 |
+
component=component,
|
| 3455 |
+
)
|
|
|
|
|
|
|
| 3456 |
|
| 3457 |
+
if critical_result is not None:
|
| 3458 |
+
result_rows.append({
|
| 3459 |
+
"๊ตญ๊ฐ": country_col,
|
| 3460 |
+
"๊ฒ์์ด": shorten_for_table(single_query, 80),
|
| 3461 |
+
"๋ฐฐํฉํ๋/๊ธ์ง": critical_result.get("ํ์๋ฌธ๊ตฌ", "๋ฐฐํฉ๊ธ์ง"),
|
| 3462 |
+
"์์ธ ํ์ ": critical_result.get("๊ฒฐ๊ณผ", ""),
|
| 3463 |
+
"ํ์ ์ถ์ฒ": "CRITICAL_COUNTRY_RULE",
|
| 3464 |
+
"๋น๊ณ ": simplify_single_note(critical_result.get("๋น๊ณ ", "-")),
|
| 3465 |
+
})
|
| 3466 |
|
| 3467 |
+
log_search_context(
|
| 3468 |
+
"single_ingredient",
|
| 3469 |
+
country,
|
| 3470 |
+
component,
|
| 3471 |
+
critical_result.get("๊ฒฐ๊ณผ", ""),
|
| 3472 |
+
"CRITICAL_COUNTRY_RULE",
|
| 3473 |
+
critical_result.get("๋น๊ณ ", "-"),
|
| 3474 |
+
)
|
| 3475 |
|
| 3476 |
+
continue
|
| 3477 |
|
| 3478 |
if is_always_pass_component(material, component):
|
| 3479 |
result_rows.append({
|
|
|
|
| 3496 |
|
| 3497 |
continue
|
| 3498 |
|
| 3499 |
+
fragrance_result = evaluate_plain_fragrance_rule(
|
| 3500 |
+
country=country,
|
| 3501 |
+
material=material,
|
| 3502 |
+
component=component,
|
| 3503 |
+
)
|
|
|
|
|
|
|
| 3504 |
|
| 3505 |
+
if fragrance_result is not None:
|
| 3506 |
+
final_result = fragrance_result
|
| 3507 |
+
source = "FRAGRANCE_RULE"
|
| 3508 |
|
| 3509 |
if final_result is None and mfds_df is not None and not mfds_df.empty:
|
| 3510 |
mfds_result = evaluate_live_detail_rule(
|
|
|
|
| 3530 |
final_result = file_result
|
| 3531 |
source = "COUNTRY_FILE_FAST"
|
| 3532 |
|
| 3533 |
+
if final_result is None:
|
| 3534 |
local_result = evaluate_local_rules(
|
| 3535 |
country=country,
|
| 3536 |
material=material,
|
|
|
|
| 3591 |
"โ
๋จ์ผ ์ฑ๋ถ ๊ฒ์ ์๋ฃ\n"
|
| 3592 |
f"- ๊ฒ์์ด: {safe_str(single_query)}\n"
|
| 3593 |
f"- ์ ํ ๊ตญ๊ฐ ์: {len(countries)}๊ฐ\n"
|
| 3594 |
+
f"- MFDS ์ํ: {mfds_live_msg}\n"
|
| 3595 |
+
f"- MFDS ์กฐํ ๋์: {', '.join(terms) if terms else '์์'}\n"
|
| 3596 |
+
"- ํ์ ๋ฐฉ์: GPT ํ์ ์์, ์
๋ก๋๋ ๊ตญ๊ฐ๋ณ ํ์ผ row/line ์ง์ ๊ฒ์ + ์์ฝ์ฒ ์ฒดํฌ ON ์ ์ค์๊ฐ ๊ฒฐ๊ณผ ์ฌ์ฉ\n"
|
| 3597 |
+
"- ๊ธ์ง ์ฑ๋ถ: ํจ๋ ์ ๋ฌด์ ๋ฌด๊ดํ๊ฒ ๋ฐฐํฉ๊ธ์ง ์ฐ์ ํ์\n"
|
| 3598 |
+
"- ์์ฝ์ฒ ๋ธ๋ผ์ฐ์ ์คํจ ์์๋ ๊ตญ๊ฐ๋ณ ํ์ผ ๊ฒ์ ๊ฒฐ๊ณผ๋ ๊ณ์ ํ์๋จ\n"
|
| 3599 |
+
"- MFDS ๊ท์ ๋งค์นญ 0ํ์ ์์ฝ์ฒ์์ ๊ธ์ง/์ ํ ์์ธ๊ฐ ํ์ธ๋์ง ์์๋ค๋ ์๋ฏธ\n"
|
| 3600 |
)
|
| 3601 |
return result_df, msg
|
| 3602 |
|
|
|
|
| 3621 |
DEFAULT_ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD", "qwer0515!")
|
| 3622 |
|
| 3623 |
|
| 3624 |
+
def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=5, live_headless=True):
|
| 3625 |
+
if not is_approved_user(user):
|
| 3626 |
+
return None, None, require_login_message()
|
| 3627 |
+
|
| 3628 |
+
return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
|
| 3629 |
+
|
| 3630 |
|
| 3631 |
+
def process_single_ingredient_with_auth(user, countries, single_query, single_amount, single_function, single_use_mfds_live=False):
|
| 3632 |
+
output_columns = ["๊ตญ๊ฐ", "๊ฒ์์ด", "๋ฐฐํฉํ๋/๊ธ์ง", "์์ธ ํ์ ", "ํ์ ์ถ์ฒ", "๋น๊ณ "]
|
| 3633 |
+
|
| 3634 |
+
if not is_approved_user(user):
|
| 3635 |
+
return pd.DataFrame(columns=output_columns), require_login_message()
|
| 3636 |
|
|
|
|
| 3637 |
return process_single_ingredient(
|
| 3638 |
countries,
|
| 3639 |
single_query,
|
| 3640 |
single_amount,
|
| 3641 |
single_function,
|
| 3642 |
+
single_use_mfds_live,
|
| 3643 |
)
|
| 3644 |
|
| 3645 |
|
|
|
|
| 3655 |
# Gradio ๊ธฐ๋ณธ auth ์ฌ์ฉ ์ ๋ด๋ถ ๋ก๊ทธ์ธ ์ฒดํฌ ์ฐํ
|
| 3656 |
# ============================================================
|
| 3657 |
|
| 3658 |
+
def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=5, live_headless=True):
|
| 3659 |
+
return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
|
| 3660 |
|
| 3661 |
|
| 3662 |
+
def process_single_ingredient_with_auth(user, countries, single_query, single_amount, single_function, single_use_mfds_live=False):
|
| 3663 |
return process_single_ingredient(
|
| 3664 |
countries,
|
| 3665 |
single_query,
|
| 3666 |
single_amount,
|
| 3667 |
single_function,
|
| 3668 |
+
single_use_mfds_live,
|
| 3669 |
)
|
| 3670 |
|
| 3671 |
|
|
|
|
| 3691 |
return USER_DB.get(username) == password
|
| 3692 |
|
| 3693 |
|
| 3694 |
+
def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=5, live_headless=True):
|
| 3695 |
+
return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
|
| 3696 |
|
| 3697 |
|
| 3698 |
+
def process_single_ingredient_with_auth(user, countries, single_query, single_amount, single_function, single_use_mfds_live=False):
|
| 3699 |
return process_single_ingredient(
|
| 3700 |
countries,
|
| 3701 |
single_query,
|
| 3702 |
single_amount,
|
| 3703 |
single_function,
|
| 3704 |
+
single_use_mfds_live,
|
| 3705 |
)
|
| 3706 |
|
| 3707 |
|
|
|
|
| 3732 |
|
| 3733 |
|
| 3734 |
# Gradio ๊ธฐ๋ณธ auth๋ฅผ ํต๊ณผํ ์ฌ์ฉ์๋ ์ด๋ฏธ ์ธ์ฆ๋ ์ํ์ด๋ฏ๋ก ๋ด๋ถ ๋ก๊ทธ์ธ ์ฒดํฌ๋ฅผ ํ์ง ์๋๋ค.
|
| 3735 |
+
def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=5, live_headless=True):
|
| 3736 |
+
return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
|
| 3737 |
|
| 3738 |
|
| 3739 |
+
def process_single_ingredient_with_auth(user, countries, single_query, single_amount, single_function, single_use_mfds_live=False):
|
| 3740 |
return process_single_ingredient(
|
| 3741 |
countries,
|
| 3742 |
single_query,
|
| 3743 |
single_amount,
|
| 3744 |
single_function,
|
| 3745 |
+
single_use_mfds_live,
|
| 3746 |
)
|
| 3747 |
|
| 3748 |
|
|
|
|
| 3768 |
return USER_DB.get(username) == password
|
| 3769 |
|
| 3770 |
|
| 3771 |
+
def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=5, live_headless=True):
|
| 3772 |
+
return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
|
| 3773 |
|
| 3774 |
|
| 3775 |
+
def process_single_ingredient_with_auth(user, countries, single_query, single_amount, single_function, single_use_mfds_live=False):
|
| 3776 |
return process_single_ingredient(
|
| 3777 |
countries,
|
| 3778 |
single_query,
|
| 3779 |
single_amount,
|
| 3780 |
single_function,
|
| 3781 |
+
single_use_mfds_live,
|
| 3782 |
)
|
| 3783 |
|
| 3784 |
|
|
|
|
| 3804 |
return USER_DB.get(username) == password
|
| 3805 |
|
| 3806 |
|
| 3807 |
+
def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=5, live_headless=True):
|
| 3808 |
+
return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
|
| 3809 |
|
| 3810 |
|
| 3811 |
+
def process_single_ingredient_with_auth(user, countries, single_query, single_amount, single_function, single_use_mfds_live=False):
|
| 3812 |
return process_single_ingredient(
|
| 3813 |
countries,
|
| 3814 |
single_query,
|
| 3815 |
single_amount,
|
| 3816 |
single_function,
|
| 3817 |
+
single_use_mfds_live,
|
| 3818 |
)
|
| 3819 |
|
| 3820 |
|
|
|
|
| 3852 |
return USER_DB.get(username) == password
|
| 3853 |
|
| 3854 |
|
| 3855 |
+
def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=5, live_headless=True):
|
| 3856 |
+
return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
|
| 3857 |
|
| 3858 |
|
| 3859 |
+
def process_single_ingredient_with_auth(user, countries, single_query, single_amount, single_function, single_use_mfds_live=False):
|
| 3860 |
return process_single_ingredient(
|
| 3861 |
countries,
|
| 3862 |
single_query,
|
| 3863 |
single_amount,
|
| 3864 |
single_function,
|
| 3865 |
+
single_use_mfds_live,
|
| 3866 |
)
|
| 3867 |
|
|
|
|
|
|
|
| 3868 |
# ============================================================
|
| 3869 |
+
# STRUCTURED FOLDER SCREENING PATCH V5.1
|
| 3870 |
+
# ๊ธฐ์กด UI/๋ก๊ทธ์ธ/์์
์ถ๋ ฅ ํํ๋ ์ ์งํ๊ณ , ํ์ ์์ง๋ง ํด๋ ๊ตฌ์กฐ ๊ธฐ์ค์ผ๋ก ์ฌ์ ์
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3871 |
# ============================================================
|
| 3872 |
|
| 3873 |
SOURCE_ONLY_MODE = True
|
| 3874 |
TREAT_POSITIVE_LIST_AS_PASS = True
|
| 3875 |
|
| 3876 |
+
V51_PROHIBITED_TERMS = [
|
| 3877 |
"๋ฐฐํฉ๊ธ์ง", "์ฌ์ฉ๊ธ์ง", "์ฌ์ฉ ๊ธ์ง", "๊ธ์ง์๋ฃ", "๊ธ์ง ์๋ฃ", "๊ธ์ง์ฑ๋ถ", "๊ธ์ง ์ฑ๋ถ",
|
| 3878 |
"prohibited", "banned", "not allowed", "shall not be used", "must not be used",
|
| 3879 |
"shall not contain", "must not contain", "forbidden",
|
| 3880 |
]
|
| 3881 |
|
| 3882 |
+
V51_RESTRICTED_TERMS = [
|
| 3883 |
"๋ฐฐํฉํ๋", "๋ฐฐํฉ ํ๋", "์ฌ์ฉํ๋", "์ฌ์ฉ ํ๋", "์ฌ์ฉ์ ํ", "์ฌ์ฉ ์ ํ",
|
| 3884 |
"์ ํ์ฌํญ", "์ ํ ์ฌํญ", "์ ํ์ฑ๋ถ", "์ ํ ์ฑ๋ถ",
|
| 3885 |
"restricted", "restriction", "maximum concentration", "maximum amount",
|
| 3886 |
+
"max concentration", "not exceeding", "not exceed", "limit", "limits",
|
| 3887 |
]
|
| 3888 |
|
| 3889 |
+
V51_FALSE_LIMIT_CONTEXT_TERMS = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3890 |
"label", "labelling", "labeling", "๋ผ๋ฒจ", "ํ์", "warning", "๊ฒฝ๊ณ ",
|
| 3891 |
+
"allergen", "์๋ ๋ฅด๊ฒ", "impurity", "impurities", "๋ถ์๋ฌผ", "contaminant", "contaminants", "์ค์ผ๋ฌผ์ง",
|
| 3892 |
"test method", "์ํ๋ฒ", "์ํ", "analysis", "๋ถ์", "purity", "์๋",
|
| 3893 |
+
"๊ฒ์ถํ๊ณ", "๊ด๋ฆฌ๊ฐ", "๊ด๋ฆฌ์น", "peroxide value", "safe harbor", "๋
ธ์ถ๋",
|
| 3894 |
+
]
|
| 3895 |
+
|
| 3896 |
+
V51_REFERENCE_FOLDER_TERMS = [
|
| 3897 |
+
"reference", "archive", "test_method", "test-method", "์ํ๋ฐฉ๋ฒ", "functional_cosmetics_reference",
|
| 3898 |
+
"safety_assessment", "historical_use", "used_ingredient_inventory", "regulatory_framework",
|
| 3899 |
+
"ingredient_review_procedure", "labeling_advertising_reference", "microbiological_quality",
|
| 3900 |
]
|
| 3901 |
|
| 3902 |
+
V51_IMPURITY_FOLDER_TERMS = [
|
| 3903 |
+
"impurity", "impurities", "contaminant", "contaminants", "contaminant_impurity_limits",
|
| 3904 |
+
"colorants_impurity_reference", "์ํ๋ฌผ์ง", "๋ถ์๋ฌผ", "์ค์ผ๋ฌผ์ง",
|
| 3905 |
+
]
|
| 3906 |
+
|
| 3907 |
+
V51_RETAILER_TERMS = ["retailer", "sephora", "target", "ulta", "clean_standard", "clean_formula_restriction"]
|
| 3908 |
+
V51_PROP65_TERMS = ["prop65", "proposition_65", "california_prop65", "california_prop65_warning"]
|
| 3909 |
+
V51_VOLUNTARY_TERMS = ["voluntary", "jcia", "์์จ", "์์", "์์ ", "voluntary_restriction", "voluntary_silicone_restriction"]
|
| 3910 |
+
V51_LABELING_TERMS = ["fragrance_allergen_labelling", "fragrance_allergen_labeling", "labeling", "labelling", "ํ์"]
|
| 3911 |
+
|
| 3912 |
+
|
| 3913 |
+
def _v51_text_has_any(text, terms):
|
| 3914 |
text = safe_str(text)
|
| 3915 |
low = text.lower()
|
| 3916 |
compact = normalize_compact(text)
|
| 3917 |
for term in terms:
|
| 3918 |
+
term = safe_str(term)
|
| 3919 |
+
if not term:
|
| 3920 |
continue
|
| 3921 |
+
if term.lower() in low:
|
| 3922 |
return True
|
| 3923 |
+
if normalize_compact(term) and normalize_compact(term) in compact:
|
| 3924 |
return True
|
| 3925 |
return False
|
| 3926 |
|
| 3927 |
+
|
| 3928 |
+
def _v51_path_text(record):
|
| 3929 |
+
source_file = safe_str(record.get("source_file", ""))
|
| 3930 |
+
sheet = safe_str(record.get("sheet", ""))
|
| 3931 |
+
return f"{source_file}\n{sheet}".replace("\\", "/")
|
| 3932 |
+
|
| 3933 |
+
|
| 3934 |
+
def _v51_folder_category(country, record):
|
| 3935 |
+
"""
|
| 3936 |
+
ํด๋๋ช
/ํ์ผ๋ช
๊ธฐ์ค์ 1์ฐจ ๋ถ๋ฅ.
|
| 3937 |
+
ํต์ฌ: reference/impurity/retailer/Prop65/voluntary๋ ๋ฒ์ ๋ฐฐํฉ๊ธ์งยทํ๋์ ๋ถ๋ฆฌํ๋ค.
|
| 3938 |
+
"""
|
| 3939 |
+
path_text = _v51_path_text(record)
|
| 3940 |
+
low = path_text.lower()
|
| 3941 |
+
compact = normalize_compact(path_text)
|
| 3942 |
+
|
| 3943 |
+
if _v51_text_has_any(path_text, V51_PROP65_TERMS):
|
| 3944 |
+
return "nonlegal_prop65"
|
| 3945 |
+
if _v51_text_has_any(path_text, V51_RETAILER_TERMS):
|
| 3946 |
+
return "nonlegal_retailer"
|
| 3947 |
+
if _v51_text_has_any(path_text, V51_IMPURITY_FOLDER_TERMS):
|
| 3948 |
+
return "nonlegal_impurity"
|
| 3949 |
+
if _v51_text_has_any(path_text, V51_VOLUNTARY_TERMS):
|
| 3950 |
+
return "nonlegal_voluntary"
|
| 3951 |
+
if _v51_text_has_any(path_text, V51_LABELING_TERMS):
|
| 3952 |
+
return "nonlegal_labeling"
|
| 3953 |
+
if _v51_text_has_any(path_text, V51_REFERENCE_FOLDER_TERMS):
|
| 3954 |
+
return "reference"
|
| 3955 |
+
|
| 3956 |
+
# ๋ฒ์ ๊ธ์ง/์ ํ ํด๋
|
| 3957 |
+
if "/prohibited/" in low or low.startswith("prohibited/") or "annex_ii" in low or "annex-ii" in low or "annex ii" in low:
|
| 3958 |
+
return "legal_prohibited"
|
| 3959 |
+
if "/restricted/" in low or low.startswith("restricted/") or "annex_iii" in low or "annex-iii" in low or "annex iii" in low:
|
| 3960 |
+
return "legal_restricted"
|
| 3961 |
+
|
| 3962 |
+
# ํ๊ตญ ๋ณํ ํ์ผ๋ช
๋ณด์
|
| 3963 |
+
if "annex_1_prohibited" in low or "๋ณํ1" in compact or "๋ณํ 1" in path_text:
|
| 3964 |
+
return "legal_prohibited"
|
| 3965 |
+
if "annex_2_restricted" in low or "restricted_ingredients" in low or "๋ณํ2" in compact or "๋ณํ 2" in path_text:
|
| 3966 |
+
return "legal_restricted"
|
| 3967 |
+
|
| 3968 |
+
# Positive list ๊ณ์ด
|
| 3969 |
+
positive_markers = [
|
| 3970 |
+
"positive_colorants", "positive_colorant", "positive_preservatives", "positive_preservative",
|
| 3971 |
+
"positive_uv_filters", "positive_uv", "colorants_permitted", "permitted_colorants",
|
| 3972 |
+
"annex_iv", "annex-v", "annex_v", "annex_vi", "annex-vi", "annex iv", "annex v", "annex vi",
|
| 3973 |
+
"colorant", "colorants", "preservative", "preservatives", "uv_filter", "uv_filters", "uv filters",
|
| 3974 |
+
"ํ์ฉ์์", "ํ์ฉ ์์", "tar_colorants_permitted",
|
| 3975 |
+
]
|
| 3976 |
+
if _v51_text_has_any(path_text, positive_markers):
|
| 3977 |
+
return "positive_list"
|
| 3978 |
+
|
| 3979 |
+
# ASEAN annexes_main_screening, Japan cosmetic_standards_main ๊ฐ์ด ํ ํ์ผ์ ์ฌ๋ฌ ๋ถ์์๊ฐ ๋ค์ด๊ฐ ๊ฒฝ์ฐ
|
| 3980 |
+
if "annexes_main_screening" in low or "cosmetic_standards_main" in low or "standards_for_cosmetics" in low:
|
| 3981 |
+
return "legal_mixed"
|
| 3982 |
+
|
| 3983 |
+
return "unknown"
|
| 3984 |
+
|
| 3985 |
+
|
| 3986 |
+
def _v51_record_type(country, record):
|
| 3987 |
+
category = _v51_folder_category(country, record)
|
| 3988 |
+
text = safe_str(record.get("text", ""))
|
| 3989 |
+
path_text = _v51_path_text(record)
|
| 3990 |
+
combined = path_text + "\n" + text[:1500]
|
| 3991 |
+
|
| 3992 |
+
if category in ["nonlegal_prop65", "nonlegal_retailer", "nonlegal_impurity", "nonlegal_voluntary", "nonlegal_labeling", "reference"]:
|
| 3993 |
+
return category
|
| 3994 |
+
if category in ["legal_prohibited", "legal_restricted", "positive_list"]:
|
| 3995 |
+
return category
|
| 3996 |
+
|
| 3997 |
+
# mixed legal file ๋ด๋ถ ๋ฌธ๋งฅ ๋ณด์
|
| 3998 |
+
if category == "legal_mixed":
|
| 3999 |
+
if _v51_text_has_any(combined, ["appendix 1", "annex ii", "prohibited", "๊ธ์ง", "์ฌ์ฉํ ์ ์๋ ์๋ฃ"]):
|
| 4000 |
+
return "legal_prohibited"
|
| 4001 |
+
if _v51_text_has_any(combined, ["appendix 2", "annex iii", "restricted", "์ ํ", "๋ฐฐํฉํ๋", "maximum amount"]):
|
| 4002 |
+
return "legal_restricted"
|
| 4003 |
+
if _v51_text_has_any(combined, ["appendix 3", "appendix 4", "annex iv", "annex v", "annex vi", "preservative", "uv absorber", "uv filter", "tar colors", "์์", "๋ณด์กด์ ", "์์ธ์ "]):
|
| 4004 |
+
return "positive_list"
|
| 4005 |
+
return "reference"
|
| 4006 |
+
|
| 4007 |
+
# ํด๋๋ช
์ด ๋ถ๋ช
ํํ ๊ฒฝ์ฐ ๋ฌธ๋งฅ๋ง์ผ๋ก ๋งค์ฐ ๋ณด์์ ์ผ๋ก ํ๋จ
|
| 4008 |
+
if _v51_text_has_any(combined, V51_PROHIBITED_TERMS):
|
| 4009 |
+
return "legal_prohibited"
|
| 4010 |
+
if _v51_text_has_any(combined, V51_RESTRICTED_TERMS):
|
| 4011 |
+
return "legal_restricted"
|
| 4012 |
+
if _v51_text_has_any(combined, ["positive list", "permitted", "ํ์ฉ๋ชฉ๋ก", "ํ์ฉ ๋ชฉ๋ก", "coloring agents", "preservatives", "uv filters"]):
|
| 4013 |
+
return "positive_list"
|
| 4014 |
+
return "unknown"
|
| 4015 |
+
|
| 4016 |
+
|
| 4017 |
+
def _v51_component_match_in_record(record_text, terms):
|
| 4018 |
record_text = safe_str(record_text)
|
| 4019 |
if not record_text:
|
| 4020 |
return False
|
| 4021 |
for term in terms:
|
| 4022 |
term = safe_str(term)
|
| 4023 |
+
if not term or len(normalize_compact(term)) < 3:
|
|
|
|
|
|
|
| 4024 |
continue
|
| 4025 |
if is_broad_lookup_term(term):
|
| 4026 |
continue
|
|
|
|
| 4033 |
return True
|
| 4034 |
return False
|
| 4035 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4036 |
|
| 4037 |
def extract_limit_condition_from_context(context):
|
| 4038 |
+
"""
|
| 4039 |
+
V5.1: ์ค์ ๋ฐฐํฉํ๋/์ฌ์ฉ์กฐ๊ฑด๋ง ์ถ์ถ.
|
| 4040 |
+
ํ์๊ธฐ์ค, ํฅ๋ฃ ์๋ ๋ฅด๊ฒ ํ์ threshold, ๋ถ์๋ฌผ ppm, Prop65 ๋
ธ์ถ/๊ฒฝ๊ณ ๊ธฐ์ค์ ๋ฐฐํฉํ๋์์ ์ ์ธ.
|
| 4041 |
+
"""
|
| 4042 |
text = safe_str(context)
|
| 4043 |
compact = re.sub(r"\s+", " ", text).strip()
|
| 4044 |
if not compact:
|
| 4045 |
return "", ""
|
| 4046 |
+
|
| 4047 |
+
if _v51_text_has_any(compact, V51_FALSE_LIMIT_CONTEXT_TERMS):
|
| 4048 |
+
# ๋จ, restricted ํด๋์์ %๊ฐ ๋ช
ํํ ์๊ณ label/impurity๊ฐ ์๋ ๊ฒฝ์ฐ๋ง ์๋์์ ์ด๋ฆด ์ฌ์ง๊ฐ ์์ผ๋
|
| 4049 |
+
# ์ฌ๊ธฐ์๋ ์คํ ๋ฐฉ์ง๋ฅผ ์ฐ์ ํ๋ค.
|
| 4050 |
return "", ""
|
| 4051 |
+
|
| 4052 |
+
if not _v51_text_has_any(compact, V51_RESTRICTED_TERMS):
|
| 4053 |
return "", ""
|
| 4054 |
|
| 4055 |
+
limits = []
|
| 4056 |
+
for pat in [
|
| 4057 |
r"([0-9]+(?:\.[0-9]+)?\s*%)",
|
| 4058 |
r"([0-9]+(?:\.[0-9]+)?\s*g\s*/\s*100\s*g)",
|
| 4059 |
r"([0-9]+(?:\.[0-9]+)?\s*g\s+per\s+100\s*g)",
|
| 4060 |
+
]:
|
|
|
|
|
|
|
| 4061 |
for m in re.finditer(pat, compact, flags=re.IGNORECASE):
|
| 4062 |
v = m.group(1).replace(" ", "")
|
| 4063 |
if v not in limits:
|
| 4064 |
limits.append(v)
|
| 4065 |
|
| 4066 |
+
condition_lines = []
|
| 4067 |
condition_keywords = [
|
| 4068 |
+
"leave-on", "rinse-off", "washed away", "not used for mucosa", "mucosa", "oral",
|
| 4069 |
+
"๋ณด์กด์ ", "๋ฐฉ๋ถ์ ", "์์ธ์ ", "์์", "์ ๋ง", "๊ตฌ๊ฐ", "์ฌ์ฉ์กฐ๊ฑด", "์ฌ์ฉ ์กฐ๊ฑด", "condition",
|
| 4070 |
+
"์ ํ", "type", "parts", "warning", "์ฃผ์",
|
| 4071 |
]
|
|
|
|
| 4072 |
for line in [safe_str(x) for x in text.splitlines() if safe_str(x)]:
|
| 4073 |
line_low = line.lower()
|
| 4074 |
if any(k.lower() in line_low for k in condition_keywords):
|
| 4075 |
cleaned = re.sub(r"\s+", " ", line).strip()
|
| 4076 |
if cleaned not in condition_lines:
|
| 4077 |
condition_lines.append(cleaned)
|
| 4078 |
+
|
| 4079 |
return ", ".join(limits[:5]), " / ".join(condition_lines[:5])[:700]
|
| 4080 |
|
| 4081 |
+
|
| 4082 |
def normalize_formula_country_text(text, country_col="", inci_name="", amount_text=""):
|
| 4083 |
text = safe_str(text)
|
| 4084 |
+
if not text or text in ["-", NO_EVIDENCE_TEXT, "Pass", "PASS", "pass"]:
|
|
|
|
|
|
|
| 4085 |
return "Pass"
|
| 4086 |
+
if "Prop 65" in text or "๊ฒฝ๊ณ ํ์" in text:
|
| 4087 |
+
return "๊ฒฝ๊ณ ํ์ ๊ฒํ "
|
| 4088 |
+
if "Clean" in text or "๋ฆฌํ
์ผ๋ฌ" in text or "SEPHORA" in text or "TARGET" in text or "ULTA" in text:
|
| 4089 |
+
return NEED_CHECK_TEXT
|
| 4090 |
+
if "๋ถ์๋ฌผ" in text or "์ค์ผ๋ฌผ์ง" in text or "impurity" in text.lower() or "contaminant" in text.lower():
|
| 4091 |
+
return "๋ถ์๋ฌผ/์ค์ผ๋ฌผ์ง ํ์ธ"
|
| 4092 |
+
if "์์จ๊ธฐ์ค" in text or "์์ " in text or "์์" in text or "voluntary" in text.lower():
|
| 4093 |
+
return "์์จ๊ธฐ์ค ํ์ธ"
|
| 4094 |
+
if "ํ์" in text or "label" in text.lower() or "allergen" in text.lower():
|
| 4095 |
+
return "ํ์๊ธฐ์ค ํ์ธ"
|
| 4096 |
+
if _v51_text_has_any(text, V51_PROHIBITED_TERMS):
|
| 4097 |
return "๋ฐฐํฉ๊ธ์ง"
|
| 4098 |
limit_text, condition_text = extract_limit_condition_from_context(text)
|
| 4099 |
if limit_text:
|
| 4100 |
return f"๋ฐฐํฉํ๋: {limit_text}"
|
| 4101 |
+
if _v51_text_has_any(text, V51_RESTRICTED_TERMS):
|
| 4102 |
return NEED_CHECK_TEXT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4103 |
return "Pass"
|
| 4104 |
|
| 4105 |
+
|
| 4106 |
def evaluate_critical_country_rule(country, material, component):
|
| 4107 |
if SOURCE_ONLY_MODE:
|
| 4108 |
return None
|
| 4109 |
return None
|
| 4110 |
|
| 4111 |
+
|
| 4112 |
def evaluate_plain_fragrance_rule(country, material, component):
|
| 4113 |
if SOURCE_ONLY_MODE:
|
| 4114 |
return None
|
| 4115 |
return None
|
| 4116 |
|
| 4117 |
+
|
| 4118 |
def evaluate_local_rules(country, material, component, ingredient_totals, ingredient_amount_parts):
|
| 4119 |
if SOURCE_ONLY_MODE:
|
| 4120 |
return None
|
| 4121 |
return None
|
| 4122 |
|
| 4123 |
+
|
| 4124 |
+
def _v51_nonlegal_result(kind, country, component, best, target_id=""):
|
| 4125 |
+
country_col = display_country(country)
|
| 4126 |
+
representative = safe_str(component.get("INCI Name", "")) or safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", "")) or safe_str(component.get("CAS.No", "")) or "-"
|
| 4127 |
+
context = safe_str(best.get("text", ""))
|
| 4128 |
+
src = f"[์ถ์ฒํ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}"
|
| 4129 |
+
|
| 4130 |
+
if kind == "nonlegal_prop65":
|
| 4131 |
+
result = {
|
| 4132 |
+
"๋ํ INCI": representative,
|
| 4133 |
+
"๊ฒฐ๊ณผ": f"{country_col}(CA Prop 65): ๊ฒฝ๊ณ ํ์ ๊ฒํ ํ์",
|
| 4134 |
+
"ํ์๋ฌธ๊ตฌ": "๊ฒฝ๊ณ ํ์ ๊ฒํ ",
|
| 4135 |
+
"๋น๊ณ ": "Proposition 65 ๋ฑ์ฌ/๊ด๋ จ ๋ฌผ์ง. ์บ๋ฆฌํฌ๋์ ํ๋งค ์ ๋
ธ์ถ๋ยท์ธ์ดํํ๋ฒยท๊ฒฝ๊ณ ํ์ ํ์ ์ฌ๋ถ ๊ฒํ . " + src,
|
| 4136 |
+
}
|
| 4137 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "V51_NONLEGAL_PROP65_WARNING", result["๋น๊ณ "])
|
| 4138 |
+
return result
|
| 4139 |
+
|
| 4140 |
+
if kind == "nonlegal_retailer":
|
| 4141 |
+
retailer = "๋ฆฌํ
์ผ๋ฌ"
|
| 4142 |
+
path = _v51_path_text(best).lower()
|
| 4143 |
+
if "sephora" in path:
|
| 4144 |
+
retailer = "SEPHORA"
|
| 4145 |
+
elif "target" in path:
|
| 4146 |
+
retailer = "TARGET"
|
| 4147 |
+
elif "ulta" in path:
|
| 4148 |
+
retailer = "ULTA"
|
| 4149 |
+
result = {
|
| 4150 |
+
"๋ํ INCI": representative,
|
| 4151 |
+
"๊ฒฐ๊ณผ": f"{retailer}: Clean ๊ธฐ์ค ํ์ธ ํ์",
|
| 4152 |
+
"ํ์๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
|
| 4153 |
+
"๋น๊ณ ": "๊ตญ๊ฐ ๋ฒ์ ๋ฐฐํฉ๊ธ์ง/ํ๋๊ฐ ์๋๋ผ ๋ฆฌํ
์ผ๋ฌ ํด๋ฆฐ ๊ธฐ์ค. " + src,
|
| 4154 |
+
}
|
| 4155 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "V51_NONLEGAL_RETAILER_CLEAN", result["๋น๊ณ "])
|
| 4156 |
+
return result
|
| 4157 |
+
|
| 4158 |
+
if kind == "nonlegal_impurity":
|
| 4159 |
+
result = {
|
| 4160 |
+
"๋ํ INCI": representative,
|
| 4161 |
+
"๊ฒฐ๊ณผ": f"{country_col}: ๋ถ์๋ฌผ/์ค์ผ๋ฌผ์ง ๊ธฐ์ค ํ์ธ ํ์",
|
| 4162 |
+
"ํ์๋ฌธ๊ตฌ": "๋ถ์๋ฌผ/์ค์ผ๋ฌผ์ง ํ์ธ",
|
| 4163 |
+
"๋น๊ณ ": "์๋ฃ/์์ ํ์ ๋ถ์๋ฌผยท์ค์ผ๋ฌผ์ง ๊ธฐ์ค์ด๋ฉฐ ๋ฐฐํฉํ๋ ์๋. " + src,
|
| 4164 |
+
}
|
| 4165 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "V51_NONLEGAL_IMPURITY_REFERENCE", result["๋น๊ณ "])
|
| 4166 |
+
return result
|
| 4167 |
+
|
| 4168 |
+
if kind == "nonlegal_voluntary":
|
| 4169 |
+
result = {
|
| 4170 |
+
"๋ํ INCI": representative,
|
| 4171 |
+
"๊ฒฐ๊ณผ": f"{country_col}: ์์จ๊ธฐ์ค ํ์ธ ํ์",
|
| 4172 |
+
"ํ์๋ฌธ๊ตฌ": "์์จ๊ธฐ์ค ํ์ธ",
|
| 4173 |
+
"๋น๊ณ ": "๋ฒ์ ๋ฐฐํฉ๊ธ์ง๊ฐ ์๋๋ผ ์
๊ณ ์์จ๊ธฐ์ค/์ฌ์ฉ ์์ ยท์์ ๊ธฐ์ค. " + src,
|
| 4174 |
+
}
|
| 4175 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "V51_NONLEGAL_VOLUNTARY", result["๋น๊ณ "])
|
| 4176 |
+
return result
|
| 4177 |
+
|
| 4178 |
+
if kind == "nonlegal_labeling":
|
| 4179 |
+
result = {
|
| 4180 |
+
"๋ํ INCI": representative,
|
| 4181 |
+
"๊ฒฐ๊ณผ": f"{country_col}: ํ์๊ธฐ์ค ํ์ธ ํ์",
|
| 4182 |
+
"ํ์๋ฌธ๊ตฌ": "ํ์๊ธฐ์ค ํ์ธ",
|
| 4183 |
+
"๋น๊ณ ": "ํ์/๋ผ๋ฒจ๋ง ๊ธฐ์ค์ด๋ฉฐ ๋ฐฐํฉํ๋ ์๋. " + src,
|
| 4184 |
+
}
|
| 4185 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "V51_NONLEGAL_LABELING", result["๋น๊ณ "])
|
| 4186 |
+
return result
|
| 4187 |
+
|
| 4188 |
+
result = {
|
| 4189 |
+
"๋ํ INCI": representative,
|
| 4190 |
+
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 4191 |
+
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 4192 |
+
"๋น๊ณ ": "์ฐธ๊ณ ์๋ฃ์์ ์ฑ๋ถ๋ช
์ ํ์ธ๋์์ผ๋ ๊ธ์ง/์ ํ ํ์ ์๋ฃ ์๋. " + src,
|
| 4193 |
+
}
|
| 4194 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "V51_REFERENCE_NAME_ONLY_PASS", result["๋น๊ณ "])
|
| 4195 |
+
return result
|
| 4196 |
+
|
| 4197 |
+
|
| 4198 |
def evaluate_component_from_uploaded_source_records(country, material, component, target_id=""):
|
| 4199 |
terms = source_match_terms_for_component(material, component)
|
| 4200 |
+
representative = safe_str(component.get("INCI Name", "")) or safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", "")) or safe_str(component.get("CAS.No", "")) or "-"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4201 |
if not terms:
|
| 4202 |
return None
|
| 4203 |
|
|
|
|
| 4205 |
hits = []
|
| 4206 |
for rec in records:
|
| 4207 |
rec_text = safe_str(rec.get("text", ""))
|
| 4208 |
+
if _v51_component_match_in_record(rec_text, terms):
|
| 4209 |
hits.append(rec)
|
| 4210 |
|
| 4211 |
if not hits:
|
| 4212 |
return None
|
| 4213 |
|
| 4214 |
+
priority = {
|
| 4215 |
+
"legal_prohibited": 100,
|
| 4216 |
+
"legal_restricted": 90,
|
| 4217 |
+
"positive_list": 70,
|
| 4218 |
+
"nonlegal_retailer": 60,
|
| 4219 |
+
"nonlegal_prop65": 58,
|
| 4220 |
+
"nonlegal_voluntary": 56,
|
| 4221 |
+
"nonlegal_impurity": 54,
|
| 4222 |
+
"nonlegal_labeling": 52,
|
| 4223 |
+
"reference": 20,
|
| 4224 |
+
"unknown": 10,
|
| 4225 |
+
}
|
| 4226 |
+
typed_hits = [(rec, _v51_record_type(country, rec)) for rec in hits]
|
| 4227 |
+
typed_hits.sort(key=lambda x: priority.get(x[1], 0), reverse=True)
|
| 4228 |
+
best, kind = typed_hits[0]
|
| 4229 |
+
context = safe_str(best.get("text", ""))
|
| 4230 |
+
src_note = f"[์ถ์ฒํ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}"
|
| 4231 |
country_col = display_country(country)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4232 |
|
| 4233 |
+
if kind == "legal_prohibited":
|
|
|
|
|
|
|
| 4234 |
result = {
|
| 4235 |
"๋ํ INCI": representative,
|
| 4236 |
+
"๊ฒฐ๊ณผ": f"{country_col}: ์
๋ก๋ ๋ฒ์ ๊ธ์ง ํด๋/ํ์ผ์์ ์ฑ๋ถ ์ง์ ํ์ธ",
|
| 4237 |
"ํ์๋ฌธ๊ตฌ": "๋ฐฐํฉ๊ธ์ง",
|
| 4238 |
+
"๋น๊ณ ": src_note,
|
| 4239 |
}
|
| 4240 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "V51_LEGAL_PROHIBITED", result["๋น๊ณ "])
|
| 4241 |
return result
|
| 4242 |
|
| 4243 |
+
if kind == "legal_restricted":
|
|
|
|
|
|
|
| 4244 |
limit_text, condition_text = extract_limit_condition_from_context(context)
|
| 4245 |
+
result = {
|
| 4246 |
+
"๋ํ INCI": representative,
|
| 4247 |
+
"๊ฒฐ๊ณผ": f"{country_col}: ์
๋ก๋ ๋ฒ์ ์ ํ ํด๋/ํ์ผ์์ ์ฑ๋ถ ์ง์ ํ์ธ" + (f" / ํ๋ {limit_text}" if limit_text else " / ํ๋ยท์กฐ๊ฑด ํ์ธ ํ์") + (f" / ์กฐ๊ฑด: {condition_text}" if condition_text else ""),
|
| 4248 |
+
"ํ์๋ฌธ๊ตฌ": f"๋ฐฐํฉํ๋: {limit_text}" if limit_text else NEED_CHECK_TEXT,
|
| 4249 |
+
"๋น๊ณ ": src_note,
|
| 4250 |
+
}
|
| 4251 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "V51_LEGAL_RESTRICTED", result["๋น๊ณ "])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4252 |
return result
|
| 4253 |
|
| 4254 |
+
if kind == "positive_list":
|
|
|
|
|
|
|
| 4255 |
limit_text, condition_text = extract_limit_condition_from_context(context)
|
| 4256 |
if limit_text:
|
| 4257 |
result = {
|
| 4258 |
"๋ํ INCI": representative,
|
| 4259 |
+
"๊ฒฐ๊ณผ": f"{country_col}: ํ์ฉ๋ชฉ๋ก์์ ์ฑ๋ถ ์ง์ ํ์ธ / ํ๋ {limit_text}" + (f" / ์กฐ๊ฑด: {condition_text}" if condition_text else ""),
|
| 4260 |
"ํ์๋ฌธ๊ตฌ": f"๋ฐฐํฉํ๋: {limit_text}",
|
| 4261 |
+
"๋น๊ณ ": src_note,
|
| 4262 |
}
|
| 4263 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "V51_POSITIVE_LIST_LIMIT", result["๋น๊ณ "])
|
| 4264 |
return result
|
|
|
|
| 4265 |
result = {
|
| 4266 |
"๋ํ INCI": representative,
|
| 4267 |
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 4268 |
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 4269 |
+
"๋น๊ณ ": "ํ์ฉ๋ชฉ๋ก์์ ์ฑ๋ถ๋ช
ํ์ธ. ๋ช
ํํ ๋ฐฐํฉํ๋ ์์น ๊ทผ๊ฑฐ ์์. " + src_note,
|
| 4270 |
}
|
| 4271 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "V51_POSITIVE_LIST_PASS", result["๋น๊ณ "])
|
| 4272 |
return result
|
| 4273 |
|
| 4274 |
+
if kind.startswith("nonlegal_") or kind == "reference":
|
| 4275 |
+
return _v51_nonlegal_result(kind, country, component, best, target_id)
|
| 4276 |
+
|
| 4277 |
result = {
|
| 4278 |
"๋ํ INCI": representative,
|
| 4279 |
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 4280 |
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 4281 |
+
"๋น๊ณ ": "์ฑ๋ถ๋ช
์ ์
๋ก๋ ํ์ผ์์ ๋ฐ๊ฒฌ๋์์ผ๋ ๊ธ์ง/์ ํ/ํ๋ ๊ทผ๊ฑฐ ์์. " + src_note,
|
| 4282 |
}
|
| 4283 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "V51_SOURCE_NAME_ONLY_PASS", result["๋น๊ณ "])
|
| 4284 |
return result
|
| 4285 |
|
| 4286 |
+
|
| 4287 |
def evaluate_component_from_country_files_only(country, material, component, target_id=""):
|
| 4288 |
+
representative = safe_str(component.get("INCI Name", "")) or safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", "")) or safe_str(component.get("CAS.No", "")) or "-"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4289 |
|
| 4290 |
if is_always_pass_component(material, component):
|
| 4291 |
result = {
|
|
|
|
| 4297 |
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "ALWAYS_PASS_RULE", result["๋น๊ณ "])
|
| 4298 |
return result
|
| 4299 |
|
| 4300 |
+
source_result = evaluate_component_from_uploaded_source_records(country, material, component, target_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4301 |
if source_result is not None:
|
| 4302 |
return source_result
|
| 4303 |
|
|
|
|
| 4307 |
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 4308 |
"๋น๊ณ ": "์
๋ก๋๋ ๊ตญ๊ฐ๋ณ ํ์ผ ๋ด ํ์ฌ ์ฑ๋ถ ์ง์ ๊ทผ๊ฑฐ ์์",
|
| 4309 |
}
|
| 4310 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "V51_SOURCE_NO_HIT_PASS", result["๋น๊ณ "])
|
| 4311 |
return result
|
| 4312 |
|
| 4313 |
+
|
| 4314 |
def is_country_result_issue(text):
|
| 4315 |
text = safe_str(text)
|
| 4316 |
+
if not text or text in ["-", NO_EVIDENCE_TEXT, "Pass", "PASS", "pass"]:
|
| 4317 |
return False
|
| 4318 |
+
if "ํ์ฉ๋ชฉ๋ก" in text and not _v51_text_has_any(text, V51_RESTRICTED_TERMS + V51_PROHIBITED_TERMS):
|
| 4319 |
return False
|
| 4320 |
+
issue_markers = [
|
| 4321 |
+
"๋ฐฐํฉ๊ธ์ง", "๊ธ์ง", "๋ฐฐํฉํ๋", "ํ๋", "ํ์ธ ํ์", "๊ฒฝ๊ณ ํ์", "Clean ๊ธฐ์ค",
|
| 4322 |
+
"๋ถ์๋ฌผ", "์ค์ผ๋ฌผ์ง", "์์จ๊ธฐ์ค", "ํ์๊ธฐ์ค", "๋ถ์ ํฉ", "์ฌ๊ฒํ ", "์ฌ์ฉ ๋ถ๊ฐ", "์ฌ์ฉ๋ถ๊ฐ",
|
| 4323 |
+
]
|
| 4324 |
+
return _v51_text_has_any(text, issue_markers + V51_PROHIBITED_TERMS + V51_RESTRICTED_TERMS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4325 |
|
| 4326 |
# ============================================================
|
| 4327 |
+
# END STRUCTURED FOLDER SCREENING PATCH V5.1
|
| 4328 |
# ============================================================
|
| 4329 |
|
| 4330 |
|
|
|
|
| 4426 |
refresh=gr.Button("๐ ํด๋/๊ท์ ํ์ผ ์๋ก๊ณ ์นจ")
|
| 4427 |
product_name=gr.Textbox(label="์ ํ๋ช
/ PRODUCT NAME",placeholder="์: ๋ง๋ฐ์นดํฌ๋ฆผ")
|
| 4428 |
file=gr.File(label="์ ์ฑ๋ถ ํ์ผ ์
๋ก๋",file_types=[".xlsx",".xls",".pdf",".png",".jpg",".jpeg",".webp"])
|
| 4429 |
+
use_mfds_live=gr.Checkbox(label="์์ฝ์ฒ ์ฌ์ดํธ ์ค์๊ฐ ์กฐํ ์ฌ์ฉ(์ ์ฒด ์คํฌ๋ฆฌ๋์์๋ ์๋ ๋นํ์ฑํ)",value=False)
|
| 4430 |
+
live_max_terms=gr.Number(label="์์ฝ์ฒ ์ค์๊ฐ ์กฐํ ์ต๋ ๊ฒ์์ด ์(์ต๋ 5)",value=5,precision=0)
|
| 4431 |
+
live_headless=gr.Checkbox(label="์์ฝ์ฒ ์กฐํ ๋ธ๋ผ์ฐ์ ์จ๊น ๋ชจ๋",value=True)
|
| 4432 |
btn=gr.Button("๐ ๋ถ์ ์์",variant="primary")
|
| 4433 |
df_out=gr.Dataframe(label="๋ฏธ๋ฆฌ๋ณด๊ธฐ - Formula Ingredients Statement",wrap=True,interactive=False)
|
| 4434 |
file_out=gr.File(label="๊ฒฐ๊ณผ ๋ค์ด๋ก๋")
|
|
|
|
| 4439 |
|
| 4440 |
btn.click(
|
| 4441 |
process_with_auth,
|
| 4442 |
+
inputs=[current_user,country,file,product_name,use_mfds_live,live_max_terms,live_headless],
|
| 4443 |
outputs=[df_out,file_out,msg_out],
|
| 4444 |
)
|
| 4445 |
|
|
|
|
| 4452 |
with gr.Row():
|
| 4453 |
single_amount=gr.Textbox(label="ํจ๋ %(w/w) ์ ํ ์
๋ ฅ",placeholder="์: 7.2")
|
| 4454 |
single_function=gr.Textbox(label="FUNCTION ์ ํ ์
๋ ฅ",placeholder="์: Sunscreen Agent")
|
| 4455 |
+
single_use_mfds_live=gr.Checkbox(label="์์ฝ์ฒ ์ฌ์ดํธ ์ค์๊ฐ ์กฐํ ์ฌ์ฉ(์ ์ฒด ์คํฌ๋ฆฌ๋์์๋ ์๋ ๋นํ์ฑํ)",value=False)
|
| 4456 |
single_btn=gr.Button("๐ ๋จ์ผ ์ฑ๋ถ ๊ฒ์ ์์",variant="primary")
|
| 4457 |
single_df_out=gr.Dataframe(label="๋จ์ผ ์ฑ๋ถ ๊ฒ์ ๊ฒฐ๊ณผ",wrap=True,interactive=False)
|
| 4458 |
single_msg_out=gr.Textbox(label="๊ฒ์ ์ํ / ๋ฉ์์ง",interactive=False,lines=8)
|
|
|
|
| 4461 |
|
| 4462 |
single_btn.click(
|
| 4463 |
process_single_ingredient_with_auth,
|
| 4464 |
+
inputs=[current_user,single_country,single_query,single_amount,single_function,single_use_mfds_live],
|
| 4465 |
outputs=[single_df_out,single_msg_out],
|
| 4466 |
)
|
| 4467 |
try:
|