Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,11 +35,7 @@
|
|
| 35 |
# reBom Regulatory Screening AI - compact full app.py
|
| 36 |
# Excel/PDF/Image input + country folder RAG + local rules + single ingredient search
|
| 37 |
|
| 38 |
-
import os, re, json, base64, hashlib, traceback, sqlite3, secrets, datetime, time, sys, subprocess,
|
| 39 |
-
# Hugging Face Spaces + Gradio 6 SSR can hang on "Building". Force client-side rendering before importing gradio.
|
| 40 |
-
os.environ.setdefault("GRADIO_SSR_MODE", "False")
|
| 41 |
-
os.environ.setdefault("GRADIO_SERVER_NAME", "0.0.0.0")
|
| 42 |
-
os.environ.setdefault("GRADIO_SERVER_PORT", "7860")
|
| 43 |
from pathlib import Path
|
| 44 |
from collections import defaultdict
|
| 45 |
from functools import lru_cache
|
|
@@ -97,10 +93,10 @@ RAW_SEARCH_LOGS = []
|
|
| 97 |
REG_TEXT_CACHE = {}
|
| 98 |
REG_SECTION_INDEX_CACHE = {}
|
| 99 |
|
| 100 |
-
COUNTRY_ORDER = ["ASEAN",
|
| 101 |
COUNTRY_DISPLAY = {"EU":"EU","์ ๋ฝ":"EU","FDA":"US","๋ฏธ๊ตญ":"US","USA":"US","US":"US","KOREA":"Korea","ํ๊ตญ":"Korea","KR":"Korea","JAPAN":"์ผ๋ณธ","์ผ๋ณธ":"์ผ๋ณธ","JP":"์ผ๋ณธ","CHINA":"์ค๊ตญ","์ค๊ตญ":"์ค๊ตญ","CN":"์ค๊ตญ","ASEAN":"ASEAN","์์ธ์":"ASEAN","UK":"UK","์๊ตญ":"UK","EU (FUTURE)":"EU (FUTURE)","EU_FUTURE":"EU (FUTURE)","CALIFORNIA":"CALIFORNIA","MEXICO":"MEXICO","SEPHORA":"SEPHORA","TARGET":"TARGET","ULTA":"ULTA"}
|
| 102 |
COUNTRY_FOLDER_ALIASES = {"EU":"EU","์ ๋ฝ":"EU","FDA":"US","๋ฏธ๊ตญ":"US","USA":"US","US":"US","us":"us","KOREA":"KOREA","ํ๊ตญ":"KOREA","KR":"KOREA","JAPAN":"JAPAN","์ผ๋ณธ":"JAPAN","JP":"JAPAN","CHINA":"CHINA","์ค๊ตญ":"CHINA","CN":"CHINA","ASEAN":"ASEAN","์์ธ์":"ASEAN","UK":"UK","์๊ตญ":"UK","EU (FUTURE)":"EU (FUTURE)","EU_FUTURE":"EU (FUTURE)","EU FUTURE":"EU (FUTURE)","CALIFORNIA":"CALIFORNIA","MEXICO":"MEXICO","SEPHORA":"SEPHORA","TARGET":"TARGET","ULTA":"ULTA"}
|
| 103 |
-
BLOCKED_PATHS = [str(BASE_DIR / c) for c in COUNTRY_ORDER] + [str(BASE_DIR/FAISS_CACHE_DIR), str(BASE_DIR
|
| 104 |
ALLOWED_PATHS = [str(OUTPUT_DIR), str(BASE_DIR)]
|
| 105 |
SUPPORTED_INPUT_EXTENSIONS = {".xlsx",".xls",".pdf",".png",".jpg",".jpeg",".webp"}
|
| 106 |
SUPPORTED_REG_FILE_EXTENSIONS = {".pdf",".txt",".csv",".xlsx",".xls"}
|
|
@@ -168,7 +164,12 @@ def safe_filename(text): return re.sub(r"[^a-zA-Z0-9๊ฐ-ํฃ._() -]","_",safe_str
|
|
| 168 |
def chunk_list(items,size):
|
| 169 |
for i in range(0,len(items),size): yield items[i:i+size]
|
| 170 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
|
|
|
| 172 |
def get_embeddings():
|
| 173 |
global EMBEDDINGS_CACHE
|
| 174 |
if EMBEDDINGS_CACHE is None: EMBEDDINGS_CACHE=OpenAIEmbeddings(model="text-embedding-3-small")
|
|
@@ -256,6 +257,9 @@ def is_plain_fragrance_component(material,component):
|
|
| 256 |
identity=normalize_compact(" ".join([component.get("ํ๊ธ ์ฑ๋ถ๋ช
",""),component.get("INCI Name",""),component.get("FUNCTION",""),component.get("CAS.No",""),material.get("Trade name(๊ตญ๋ฌธ)",""),material.get("Trade name(์๋ฌธ)","")]))
|
| 257 |
return any(normalize_compact(w) in identity for w in ["ํฅ๋ฃ","fragrance","parfum","perfume","aroma"])
|
| 258 |
|
|
|
|
|
|
|
|
|
|
| 259 |
|
| 260 |
def get_restricted_candidate_reason(material,component):
|
| 261 |
if is_always_pass_component(material,component): return ""
|
|
@@ -272,6 +276,10 @@ def get_restricted_candidate_reason(material,component):
|
|
| 272 |
if normalize_compact(component.get("ํ๊ธ ์ฑ๋ถ๋ช
",""))==normalize_compact("์ด๋ฆฌ์ค๋ฆญ์ ์จ๋"): return "์ ํ ๊ฐ๋ฅ์ฑ ์ฑ๋ถ"
|
| 273 |
return ""
|
| 274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
|
| 276 |
def log_search_context(target_id,country,component,result_text,source,context):
|
| 277 |
RAW_SEARCH_LOGS.append({"target_id":target_id,"๊ตญ๊ฐ/์ฑ๋":display_country(country),"์ฑ๋ถ๋ช
":safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
","")),"INCI Name":safe_str(component.get("INCI Name","")),"ํ์ ":safe_str(result_text),"์ถ์ฒ":safe_str(source),"๊ฒ์ ์๋ฌธ":safe_str(context)[:3000]})
|
|
@@ -310,6 +318,32 @@ def validate_limit_result_against_evidence(result_obj,evidence_text,component):
|
|
| 310 |
result_obj["๋น๊ณ "]=(note+" / "+ev) if note and note!="-" else ev
|
| 311 |
return result_obj
|
| 312 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
|
| 314 |
|
| 315 |
def standardize_formula_dataframe(df):
|
|
@@ -560,6 +594,8 @@ def is_broad_lookup_term(term):
|
|
| 560 |
return False
|
| 561 |
|
| 562 |
|
|
|
|
|
|
|
| 563 |
# ============================================================
|
| 564 |
# ๊ท์ ๋์์ด / CAS / ์ด์ฑ์ง์ฒด ๋ ์ง์คํธ๋ฆฌ
|
| 565 |
# - ๊ตญ๊ฐ๋ณ ํ์ผ ํ๊ธฐ๊ฐ INCI์ ๋ค๋ฅผ ๋ PASS ์คํ์ ๋ง๊ธฐ ์ํ ๋ณด์ ์ธต
|
|
@@ -1148,6 +1184,8 @@ def validate_country_file_match_context(context, component, lookup_terms):
|
|
| 1148 |
return False
|
| 1149 |
|
| 1150 |
|
|
|
|
|
|
|
| 1151 |
# country db
|
| 1152 |
|
| 1153 |
def resolve_country_folder(country):
|
|
@@ -1157,16 +1195,18 @@ def resolve_country_folder(country):
|
|
| 1157 |
fmap={f.lower():f for f in os.listdir(".") if os.path.isdir(f)}
|
| 1158 |
return fmap.get(alias.lower(),alias)
|
| 1159 |
|
| 1160 |
-
def
|
| 1161 |
exclude={".git",".cache","__pycache__",".ipynb_checkpoints",".venv","venv","node_modules",FAISS_CACHE_DIR,"outputs"}
|
| 1162 |
folders=[f for f in os.listdir(".") if os.path.isdir(f) and f not in exclude]
|
| 1163 |
existing=set(folders); ordered=[c for c in COUNTRY_ORDER if c in existing]; extras=sorted([f for f in folders if f not in COUNTRY_ORDER])
|
| 1164 |
return ordered+extras if ordered or extras else COUNTRY_ORDER.copy()
|
| 1165 |
|
| 1166 |
-
def
|
| 1167 |
choices=get_country_folders(); kept=[v for v in (current_values or []) if v in choices]
|
| 1168 |
return gr.update(choices=choices,value=kept)
|
| 1169 |
|
|
|
|
|
|
|
| 1170 |
|
| 1171 |
def get_regulatory_file_list(folder):
|
| 1172 |
files=[]
|
|
@@ -1465,6 +1505,8 @@ def mfds_click_probable_result(page, term):
|
|
| 1465 |
return False
|
| 1466 |
|
| 1467 |
|
|
|
|
|
|
|
| 1468 |
def mfds_click_first_detail_result(page):
|
| 1469 |
"""
|
| 1470 |
์์ฝ์ฒ ๊ฒ์ ๊ฒฐ๊ณผ์์ ๊ฒ์์ด์ ๊ฒฐ๊ณผ๋ช
์นญ์ด ๋ค๋ฅผ ์ ์๋ค.
|
|
@@ -1753,6 +1795,8 @@ def mfds_lookup_one_term_with_retry(page, term):
|
|
| 1753 |
return [], last_error[:300]
|
| 1754 |
|
| 1755 |
|
|
|
|
|
|
|
| 1756 |
def mfds_launch_chromium(playwright_obj):
|
| 1757 |
"""
|
| 1758 |
Playwright Chromium ๋ธ๋ผ์ฐ์ ์คํ ํจ์.
|
|
@@ -1947,6 +1991,15 @@ def evaluate_live_detail_rule(country, material, component, live_df):
|
|
| 1947 |
}
|
| 1948 |
|
| 1949 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1950 |
|
| 1951 |
def evaluate_limit_rule(country,material,component,group,name):
|
| 1952 |
key=match_rule_key(material,component,group)
|
|
@@ -1960,6 +2013,24 @@ def evaluate_limit_rule(country,material,component,group,name):
|
|
| 1960 |
return {"๋ํ INCI":label,"๊ฒฐ๊ณผ":f"{name} / {label} ํ์ฌ ํจ๋ {at}%, ํ๋ {format_percent(lim)}% ์ด๋ด","ํ์๋ฌธ๊ตฌ":cr.get("formula_text") or f"๋ฐฐํฉํ๋: {format_percent(lim)}%","๋น๊ณ ":"-"}
|
| 1961 |
return {"๋ํ INCI":label,"๊ฒฐ๊ณผ":f"{name} / {label} / ํ๋๊ฐ ํ์ธ ํ์","ํ์๋ฌธ๊ตฌ":LIMIT_CHECK_TEXT,"๋น๊ณ ":"๋ก์ปฌ ๊ท์น์ ์ฑ๋ถ์ ์์ผ๋ ํ๋๊ฐ์ด ๋น์ด ์์."}
|
| 1962 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1963 |
|
| 1964 |
def parse_country_response(text):
|
| 1965 |
res={"๋ํ INCI":"-","๊ฒฐ๊ณผ":NO_EVIDENCE_TEXT,"ํ์๋ฌธ๊ตฌ":"Pass","๋น๊ณ ":"-"}
|
|
@@ -2018,6 +2089,16 @@ def make_formula_statement_rows(row_items,country_cols):
|
|
| 2018 |
for cc in country_cols: total_row[cc]=""
|
| 2019 |
rows.append(total_row); return pd.DataFrame(rows)
|
| 2020 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2021 |
|
| 2022 |
def sum_formula_percent(df): return sum(to_number(r.get("%(w/w)","")) or 0 for _,r in df.iterrows() if not is_total_like_text(r.get("INGREDIENT NAME (INCI)","")))
|
| 2023 |
|
|
@@ -2040,6 +2121,9 @@ def style_output_workbook(path,product_name=""):
|
|
| 2040 |
for col in range(1,sheet.max_column+1): sheet.column_dimensions[get_column_letter(col)].width=18
|
| 2041 |
wb.save(path)
|
| 2042 |
|
|
|
|
|
|
|
|
|
|
| 2043 |
|
| 2044 |
def process(countries,file,product_name="",use_mfds_live=False,live_max_terms=5,live_headless=True):
|
| 2045 |
"""
|
|
@@ -2315,6 +2399,9 @@ def build_single_component_from_query(query, amount="", function="", single_amou
|
|
| 2315 |
return mat, comp, at
|
| 2316 |
|
| 2317 |
|
|
|
|
|
|
|
|
|
|
| 2318 |
def get_country_regulatory_text_cached(country):
|
| 2319 |
"""
|
| 2320 |
๊ตญ๊ฐ๋ณ ๊ท์ ํ์ผ ์๋ฌธ์ ์ง์ ์ฝ์ด์ ์บ์ํ๋ค.
|
|
@@ -2548,7 +2635,7 @@ def split_regulatory_text_into_sections(raw_text):
|
|
| 2548 |
return sections
|
| 2549 |
|
| 2550 |
|
| 2551 |
-
def
|
| 2552 |
"""
|
| 2553 |
๋จ์ผ ์ฑ๋ถ ๊ฒ์ ๊ณ ์ํ์ฉ ์น์
์ธ๋ฑ์ค.
|
| 2554 |
๊ตญ๊ฐ๋ณ ํ์ผ์ ๋งค๋ฒ PDF/Excel ์ ์ฒด ์ฝ๊ธฐํ์ง ์๊ณ ,
|
|
@@ -2813,6 +2900,44 @@ def warmup_country_indexes(countries):
|
|
| 2813 |
return "\n".join(messages) if messages else "์ ํ๋ ๊ตญ๊ฐ ์์"
|
| 2814 |
|
| 2815 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2816 |
def make_restricted_or_positive_result(country, component, match, reg_type):
|
| 2817 |
context = safe_str(match.get("context", "")) if isinstance(match, dict) else safe_str(match)
|
| 2818 |
label = safe_str(reg_type.get("label", "๊ท์ ๋ชฉ๋ก"))
|
|
@@ -3025,6 +3150,177 @@ def build_country_source_record_index(country):
|
|
| 3025 |
return records, "BUILT_SOURCE_RECORD_INDEX"
|
| 3026 |
|
| 3027 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3028 |
def shorten_for_table(value, max_len=80):
|
| 3029 |
value = safe_str(value)
|
| 3030 |
|
|
@@ -3325,10 +3621,54 @@ DEFAULT_ADMIN_EMAIL = os.getenv("ADMIN_EMAIL", "jin2li@rebom.kr").strip().lower(
|
|
| 3325 |
DEFAULT_ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD", "qwer0515!")
|
| 3326 |
|
| 3327 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3328 |
# ============================================================
|
| 3329 |
# Gradio ๊ธฐ๋ณธ auth ์ฌ์ฉ ์ ๋ด๋ถ ๋ก๊ทธ์ธ ์ฒดํฌ ์ฐํ
|
| 3330 |
# ============================================================
|
| 3331 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3332 |
|
| 3333 |
# ============================================================
|
| 3334 |
# ๋ก๊ทธ์ธ ์ธ์ฆ
|
|
@@ -3336,6 +3676,35 @@ DEFAULT_ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD", "qwer0515!")
|
|
| 3336 |
# - USER_DB์ ์ฌ๋ฌ ์์ด๋/๋น๋ฐ๋ฒํธ๋ฅผ ์ง์ ๋ฑ๋ก
|
| 3337 |
# ============================================================
|
| 3338 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3339 |
|
| 3340 |
# ============================================================
|
| 3341 |
# ๋ก๊ทธ์ธ ์ธ์ฆ
|
|
@@ -3347,28 +3716,34 @@ DEFAULT_ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD", "qwer0515!")
|
|
| 3347 |
# "๋ฉ์ผ์ฃผ์": "๋น๋ฐ๋ฒํธ",
|
| 3348 |
# ============================================================
|
| 3349 |
|
|
|
|
|
|
|
| 3350 |
|
| 3351 |
-
#
|
|
|
|
|
|
|
|
|
|
| 3352 |
|
| 3353 |
|
| 3354 |
-
|
| 3355 |
-
|
| 3356 |
-
|
| 3357 |
-
|
| 3358 |
-
# ============================================================
|
| 3359 |
|
| 3360 |
|
| 3361 |
-
#
|
| 3362 |
-
|
| 3363 |
-
|
| 3364 |
-
# - ์๋ USER_DB์ ๋ฉ์ผ/๋น๋ฐ๋ฒํธ๋ฅผ ์ง์ ๋ฑ๋ก
|
| 3365 |
-
# ============================================================
|
| 3366 |
|
| 3367 |
|
| 3368 |
-
|
| 3369 |
-
|
| 3370 |
-
|
| 3371 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3372 |
|
| 3373 |
|
| 3374 |
|
|
@@ -3377,18 +3752,13 @@ DEFAULT_ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD", "qwer0515!")
|
|
| 3377 |
# - Gradio ๊ธฐ๋ณธ ๋ก๊ทธ์ธ์ฐฝ ์ฌ์ฉ
|
| 3378 |
# - ์๋ USER_DB์ ๋ฉ์ผ/๋น๋ฐ๋ฒํธ๋ฅผ ์ง์ ๋ฑ๋ก
|
| 3379 |
# ============================================================
|
| 3380 |
-
# ์ฌ์ฉ์ ์ถ๊ฐ ๋ฐฉ๋ฒ:
|
| 3381 |
-
# USER_DB ์์ "์์ด๋": "๋น๋ฐ๋ฒํธ", ํ์์ผ๋ก ํ ์ค์ฉ ์ถ๊ฐํ์ธ์.
|
| 3382 |
-
# ๊ฐ ์ค ๋์๋ ์ฝค๋ง(,)๋ฅผ ๋ถ์ด๋ ๊ฒ์ ๊ถ์ฅํฉ๋๋ค.
|
| 3383 |
-
# ============================================================
|
| 3384 |
|
| 3385 |
USER_DB = {
|
| 3386 |
"jin2li@rebom.kr": "qwer0515!",
|
| 3387 |
-
"jkh@rebom.kr": "rebom123!",
|
| 3388 |
-
"admin": "rebom123!",
|
| 3389 |
|
| 3390 |
# ์ฌ์ฉ์ ๋ฑ๋ก ์์:
|
| 3391 |
# "yubin.p@rebom.kr": "123456!",
|
|
|
|
| 3392 |
}
|
| 3393 |
|
| 3394 |
|
|
@@ -3411,13 +3781,97 @@ def process_single_ingredient_with_auth(user, countries, single_query, single_am
|
|
| 3411 |
single_use_mfds_live,
|
| 3412 |
)
|
| 3413 |
|
| 3414 |
-
# ============================================================
|
| 3415 |
-
# STRUCTURED FOLDER SCREENING PATCH V5.1
|
| 3416 |
-
# ๊ธฐ์กด UI/๋ก๊ทธ์ธ/์์
์ถ๋ ฅ ํํ๋ ์ ์งํ๊ณ , ํ์ ์์ง๋ง ํด๋ ๊ตฌ์กฐ ๊ธฐ์ค์ผ๋ก ์ฌ์ ์
|
| 3417 |
-
# ============================================================
|
| 3418 |
|
| 3419 |
-
|
| 3420 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3421 |
|
| 3422 |
V51_PROHIBITED_TERMS = [
|
| 3423 |
"๋ฐฐํฉ๊ธ์ง", "์ฌ์ฉ๊ธ์ง", "์ฌ์ฉ ๊ธ์ง", "๊ธ์ง์๋ฃ", "๊ธ์ง ์๋ฃ", "๊ธ์ง์ฑ๋ถ", "๊ธ์ง ์ฑ๋ถ",
|
|
@@ -3567,6 +4021,38 @@ def _v51_is_glycerin_deg_impurity_record(country, record, component):
|
|
| 3567 |
|
| 3568 |
return has_glycerin and has_deg and has_impurity_limit
|
| 3569 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3570 |
|
| 3571 |
|
| 3572 |
def _v51_component_match_in_record(record_text, terms):
|
|
@@ -3658,6 +4144,24 @@ def normalize_formula_country_text(text, country_col="", inci_name="", amount_te
|
|
| 3658 |
return "Pass"
|
| 3659 |
|
| 3660 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3661 |
def _v51_nonlegal_result(kind, country, component, best, target_id=""):
|
| 3662 |
country_col = display_country(country)
|
| 3663 |
representative = safe_str(component.get("INCI Name", "")) or safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", "")) or safe_str(component.get("CAS.No", "")) or "-"
|
|
@@ -3732,11 +4236,141 @@ def _v51_nonlegal_result(kind, country, component, best, target_id=""):
|
|
| 3732 |
return result
|
| 3733 |
|
| 3734 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3735 |
# ============================================================
|
| 3736 |
# END STRUCTURED FOLDER SCREENING PATCH V5.1
|
| 3737 |
# ============================================================
|
| 3738 |
|
| 3739 |
|
|
|
|
|
|
|
| 3740 |
# ============================================================
|
| 3741 |
# STRUCTURED FOLDER SCREENING PATCH V5.2
|
| 3742 |
# 2026-06: US ํด๋๋ช
๋ฐ์ + ์ฃผ์ ์คํ์ ์ฐจ๋จ
|
|
@@ -3746,8 +4380,35 @@ def _v51_nonlegal_result(kind, country, component, best, target_id=""):
|
|
| 3746 |
# - Phenoxyethanol: EU/ASEAN/KOREA/JAPAN ๋ณด์กด์ ์ต๋ 1.0% ํ๋๋ก ๊ณ ์ ๋ณด์
|
| 3747 |
# ============================================================
|
| 3748 |
|
|
|
|
| 3749 |
COUNTRY_DISPLAY.update({"FDA": "US", "๋ฏธ๊ตญ": "US", "USA": "US", "US": "US", "us": "US"})
|
| 3750 |
COUNTRY_FOLDER_ALIASES.update({"FDA": "US", "๋ฏธ๊ตญ": "US", "USA": "US", "US": "US", "us": "us"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3751 |
|
| 3752 |
|
| 3753 |
def _v52_component_blob(material, component):
|
|
@@ -3877,6 +4538,35 @@ def _v51_record_type(country, record, component=None):
|
|
| 3877 |
return "unknown"
|
| 3878 |
|
| 3879 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3880 |
|
| 3881 |
# ============================================================
|
| 3882 |
# END STRUCTURED FOLDER SCREENING PATCH V5.2
|
|
@@ -3893,8 +4583,12 @@ def _v51_record_type(country, record, component=None):
|
|
| 3893 |
# - ํ์ผ๋ช
/๋ฌธ์ ์ ์ฒด์ prohibited/limit ํค์๋๋ง์ผ๋ก ์ฑ๋ถ ํ์ ๊ธ์ง
|
| 3894 |
# ============================================================
|
| 3895 |
|
|
|
|
|
|
|
|
|
|
| 3896 |
COUNTRY_DISPLAY.update({"FDA": "US", "๋ฏธ๊ตญ": "US", "USA": "US", "US": "US", "us": "US"})
|
| 3897 |
COUNTRY_FOLDER_ALIASES.update({"FDA": "US", "๋ฏธ๊ตญ": "US", "USA": "US", "US": "US", "us": "us", "Us": "US"})
|
|
|
|
| 3898 |
|
| 3899 |
|
| 3900 |
def country_key(country):
|
|
@@ -3915,6 +4609,19 @@ def country_key(country):
|
|
| 3915 |
return m.get(t, t)
|
| 3916 |
|
| 3917 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3918 |
def _v6_path_text(record):
|
| 3919 |
return f"{safe_str(record.get('source_file',''))}\n{safe_str(record.get('sheet',''))}".replace('\\', '/')
|
| 3920 |
|
|
@@ -4161,6 +4868,125 @@ def _v6_nonlegal_result(country, material, component, record, rtype, target_id="
|
|
| 4161 |
return _v6_result(representative, NO_EVIDENCE_TEXT, "Pass", src, target_id, country, component, "V6_REFERENCE_ONLY_NO_LEGAL_CLASSIFICATION")
|
| 4162 |
|
| 4163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4164 |
def evaluate_critical_country_rule(country, material, component):
|
| 4165 |
if SOURCE_ONLY_MODE:
|
| 4166 |
return None
|
|
@@ -4179,6 +5005,16 @@ def evaluate_local_rules(country, material, component, ingredient_totals, ingred
|
|
| 4179 |
return None
|
| 4180 |
|
| 4181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4182 |
|
| 4183 |
# ============================================================
|
| 4184 |
# END SOURCE TABLE ROW ENGINE PATCH V6
|
|
@@ -4597,6 +5433,8 @@ def is_country_result_issue(text):
|
|
| 4597 |
# ============================================================
|
| 4598 |
|
| 4599 |
|
|
|
|
|
|
|
| 4600 |
# ============================================================
|
| 4601 |
# USER PATCH 2026-06-15
|
| 4602 |
# 1) Output country/channel display names forced to English
|
|
@@ -4657,7 +5495,7 @@ def display_country(country):
|
|
| 4657 |
return COUNTRY_DISPLAY.get(str(country).upper(), COUNTRY_DISPLAY.get(str(country), c))
|
| 4658 |
|
| 4659 |
|
| 4660 |
-
_ORIGINAL_get_country_folders =
|
| 4661 |
|
| 4662 |
|
| 4663 |
def get_country_folders():
|
|
@@ -4665,7 +5503,7 @@ def get_country_folders():
|
|
| 4665 |
return [c for c in _ORIGINAL_get_country_folders() if not _is_hidden_always_folder(c)]
|
| 4666 |
|
| 4667 |
|
| 4668 |
-
_ORIGINAL_refresh_country_choices_keep_selection =
|
| 4669 |
|
| 4670 |
|
| 4671 |
def refresh_country_choices_keep_selection(current_values=None):
|
|
@@ -4682,7 +5520,7 @@ def refresh_country_choices_and_clear_cache(current_values=None):
|
|
| 4682 |
return refresh_country_choices_keep_selection(current_values)
|
| 4683 |
|
| 4684 |
|
| 4685 |
-
_ORIGINAL_get_country_section_index_cached =
|
| 4686 |
|
| 4687 |
|
| 4688 |
def get_country_section_index_cached(country):
|
|
@@ -4718,7 +5556,7 @@ def get_country_section_index_cached(country):
|
|
| 4718 |
return list(sections or []) + extra_sections, status
|
| 4719 |
|
| 4720 |
|
| 4721 |
-
with gr.Blocks() as demo:
|
| 4722 |
current_user = gr.State({})
|
| 4723 |
gr.Markdown("# ๐ reBom")
|
| 4724 |
gr.HTML("""
|
|
@@ -4797,6 +5635,8 @@ with gr.Blocks() as demo:
|
|
| 4797 |
</script>
|
| 4798 |
|
| 4799 |
|
|
|
|
|
|
|
| 4800 |
""")
|
| 4801 |
gr.Markdown("### Screening")
|
| 4802 |
|
|
@@ -4848,39 +5688,11 @@ with gr.Blocks() as demo:
|
|
| 4848 |
inputs=[current_user,single_country,single_query,single_amount,single_function],
|
| 4849 |
outputs=[single_df_out,single_msg_out],
|
| 4850 |
)
|
| 4851 |
-
|
| 4852 |
-
# ============================================================
|
| 4853 |
-
# Hugging Face Spaces launch - simple stable mode
|
| 4854 |
-
# ============================================================
|
| 4855 |
-
|
| 4856 |
-
# ์ค์:
|
| 4857 |
-
# Hugging Face Spaces์์๋ share=True๊ฐ ํ์ ์๊ณ , ์ผ๋ถ Gradio 6 SSR/iframe ์กฐํฉ์์
|
| 4858 |
-
# App ํ๋ฉด์ด ๋น ํ๋ฉด์ผ๋ก ๋ฉ์ถ ์ ์์ด launch ์ต์
์ ์ต์ํํ๋ค.
|
| 4859 |
-
try:
|
| 4860 |
-
demo.queue()
|
| 4861 |
-
except Exception:
|
| 4862 |
-
pass
|
| 4863 |
-
|
| 4864 |
-
_launch_kwargs = {
|
| 4865 |
-
"server_name": "0.0.0.0",
|
| 4866 |
-
"server_port": 7860,
|
| 4867 |
-
"auth": auth_fn,
|
| 4868 |
-
"share": False,
|
| 4869 |
-
}
|
| 4870 |
-
|
| 4871 |
-
# ์ค์น๋ Gradio ๋ฒ์ ์ ์๋ ์ธ์๋ง ์ ๋ฌํ๋ค. Gradio 5.x์์๋ ssr_mode๊ฐ ์์ ์ ์๋ค.
|
| 4872 |
try:
|
| 4873 |
-
|
| 4874 |
-
|
| 4875 |
-
|
| 4876 |
-
|
| 4877 |
-
|
| 4878 |
-
|
| 4879 |
-
|
| 4880 |
-
# Gradio 6.x๋ css๋ฅผ launch()์์ ๋ฐ๋๋ค. Gradio 5.x๋ ์์ผ๋ฉด ์๋ ์ ์ธ๋๋ค.
|
| 4881 |
-
if not _launch_params or "css" in _launch_params:
|
| 4882 |
-
_launch_kwargs["css"] = custom_css
|
| 4883 |
-
|
| 4884 |
-
_launch_kwargs = {k: v for k, v in _launch_kwargs.items() if (not _launch_params or k in _launch_params)}
|
| 4885 |
-
|
| 4886 |
-
demo.launch(**_launch_kwargs)
|
|
|
|
| 35 |
# reBom Regulatory Screening AI - compact full app.py
|
| 36 |
# Excel/PDF/Image input + country folder RAG + local rules + single ingredient search
|
| 37 |
|
| 38 |
+
import os, re, json, base64, hashlib, traceback, sqlite3, secrets, datetime, time, sys, subprocess, time
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
from pathlib import Path
|
| 40 |
from collections import defaultdict
|
| 41 |
from functools import lru_cache
|
|
|
|
| 93 |
REG_TEXT_CACHE = {}
|
| 94 |
REG_SECTION_INDEX_CACHE = {}
|
| 95 |
|
| 96 |
+
COUNTRY_ORDER = ["ASEAN","CALIFORNIA","CHINA","EU (FUTURE)","EU","US","JAPAN","KOREA","MEXICO","SEPHORA","TARGET","UK","ULTA"]
|
| 97 |
COUNTRY_DISPLAY = {"EU":"EU","์ ๋ฝ":"EU","FDA":"US","๋ฏธ๊ตญ":"US","USA":"US","US":"US","KOREA":"Korea","ํ๊ตญ":"Korea","KR":"Korea","JAPAN":"์ผ๋ณธ","์ผ๋ณธ":"์ผ๋ณธ","JP":"์ผ๋ณธ","CHINA":"์ค๊ตญ","์ค๊ตญ":"์ค๊ตญ","CN":"์ค๊ตญ","ASEAN":"ASEAN","์์ธ์":"ASEAN","UK":"UK","์๊ตญ":"UK","EU (FUTURE)":"EU (FUTURE)","EU_FUTURE":"EU (FUTURE)","CALIFORNIA":"CALIFORNIA","MEXICO":"MEXICO","SEPHORA":"SEPHORA","TARGET":"TARGET","ULTA":"ULTA"}
|
| 98 |
COUNTRY_FOLDER_ALIASES = {"EU":"EU","์ ๋ฝ":"EU","FDA":"US","๋ฏธ๊ตญ":"US","USA":"US","US":"US","us":"us","KOREA":"KOREA","ํ๊ตญ":"KOREA","KR":"KOREA","JAPAN":"JAPAN","์ผ๋ณธ":"JAPAN","JP":"JAPAN","CHINA":"CHINA","์ค๊ตญ":"CHINA","CN":"CHINA","ASEAN":"ASEAN","์์ธ์":"ASEAN","UK":"UK","์๊ตญ":"UK","EU (FUTURE)":"EU (FUTURE)","EU_FUTURE":"EU (FUTURE)","EU FUTURE":"EU (FUTURE)","CALIFORNIA":"CALIFORNIA","MEXICO":"MEXICO","SEPHORA":"SEPHORA","TARGET":"TARGET","ULTA":"ULTA"}
|
| 99 |
+
BLOCKED_PATHS = [str(BASE_DIR / c) for c in COUNTRY_ORDER] + [str(BASE_DIR/FAISS_CACHE_DIR), str(BASE_DIR/'.env'), str(BASE_DIR/'__pycache__')]
|
| 100 |
ALLOWED_PATHS = [str(OUTPUT_DIR), str(BASE_DIR)]
|
| 101 |
SUPPORTED_INPUT_EXTENSIONS = {".xlsx",".xls",".pdf",".png",".jpg",".jpeg",".webp"}
|
| 102 |
SUPPORTED_REG_FILE_EXTENSIONS = {".pdf",".txt",".csv",".xlsx",".xls"}
|
|
|
|
| 164 |
def chunk_list(items,size):
|
| 165 |
for i in range(0,len(items),size): yield items[i:i+size]
|
| 166 |
|
| 167 |
+
def country_key(country):
|
| 168 |
+
t=safe_str(country).upper().replace("_"," ").replace("-"," "); t=re.sub(r"\s+"," ",t).strip()
|
| 169 |
+
m={"ํ๊ตญ":"KOREA","KOREA":"KOREA","KR":"KOREA","EU":"EU","EUROPE":"EU","์ ๋ฝ":"EU","EU FUTURE":"EU_FUTURE","EU (FUTURE)":"EU_FUTURE","JAPAN":"JAPAN","JP":"JAPAN","์ผ๋ณธ":"JAPAN","CHINA":"CHINA","CN":"CHINA","์ค๊ตญ":"CHINA","USA":"US","US":"US","๋ฏธ๊ตญ":"US","FDA":"US","ASEAN":"ASEAN","์์ธ์":"ASEAN","UK":"UK","์๊ตญ":"UK","SEPHORA":"SEPHORA","TARGET":"TARGET","ULTA":"ULTA"}
|
| 170 |
+
return m.get(t,t)
|
| 171 |
|
| 172 |
+
def display_country(country): return COUNTRY_DISPLAY.get(str(country).upper(),COUNTRY_DISPLAY.get(str(country),str(country)))
|
| 173 |
def get_embeddings():
|
| 174 |
global EMBEDDINGS_CACHE
|
| 175 |
if EMBEDDINGS_CACHE is None: EMBEDDINGS_CACHE=OpenAIEmbeddings(model="text-embedding-3-small")
|
|
|
|
| 257 |
identity=normalize_compact(" ".join([component.get("ํ๊ธ ์ฑ๋ถ๋ช
",""),component.get("INCI Name",""),component.get("FUNCTION",""),component.get("CAS.No",""),material.get("Trade name(๊ตญ๋ฌธ)",""),material.get("Trade name(์๋ฌธ)","")]))
|
| 258 |
return any(normalize_compact(w) in identity for w in ["ํฅ๋ฃ","fragrance","parfum","perfume","aroma"])
|
| 259 |
|
| 260 |
+
def evaluate_plain_fragrance_rule(country,material,component):
|
| 261 |
+
if not is_plain_fragrance_component(material,component): return None
|
| 262 |
+
return {"๋ํ INCI":safe_str(component.get("INCI Name","")) or "Fragrance","๊ฒฐ๊ณผ":f"ํฅ๋ฃ / {display_country(country)} ์๋ ๋ฅด๊ฒ ํ์์ฑ๋ถ ๋ฐ ์ธ๋ถ ์กฐ์ฑ ํ์ธ ํ์","ํ์๋ฌธ๊ตฌ":NEED_CHECK_TEXT,"๋น๊ณ ":"ํฅ๋ฃ๋ ์ธ๋ถ ๊ตฌ์ฑ์ฑ๋ถ ๋ฐ ์๋ ๋ฅด๊ฒ ํ์๋์ ์ฌ๋ถ ํ์ธ ํ์. ์๋ Pass ์ฒ๋ฆฌ ๊ธ์ง."}
|
| 263 |
|
| 264 |
def get_restricted_candidate_reason(material,component):
|
| 265 |
if is_always_pass_component(material,component): return ""
|
|
|
|
| 276 |
if normalize_compact(component.get("ํ๊ธ ์ฑ๋ถ๋ช
",""))==normalize_compact("์ด๋ฆฌ์ค๋ฆญ์ ์จ๋"): return "์ ํ ๊ฐ๋ฅ์ฑ ์ฑ๋ถ"
|
| 277 |
return ""
|
| 278 |
|
| 279 |
+
def is_country_result_issue(text):
|
| 280 |
+
text=safe_str(text)
|
| 281 |
+
if not text or text in ["-",NO_EVIDENCE_TEXT,"Pass","PASS","pass"]: return False
|
| 282 |
+
return any(k in text for k in ["๋ฐฐํฉ๊ธ์ง","๊ธ์ง","์ด๊ณผ","๋ถ์ ํฉ","์ฌ๊ฒํ ","ํ์ธ ํ์","์๋ฃ ํ์ธ","ํ์ ํ์","๏ฟฝ๏ฟฝ๋ฒจ๋ง","๋ถ๊ฐ","์ฃผ์","๊ฒฝ๊ณ ","๋ฐฐํฉํ๋ ํ์ธ ํ์","๊ธฐ๋ฅ์ฑ ํ์ธ","ํจ๋ ํ์ธ"])
|
| 283 |
|
| 284 |
def log_search_context(target_id,country,component,result_text,source,context):
|
| 285 |
RAW_SEARCH_LOGS.append({"target_id":target_id,"๊ตญ๊ฐ/์ฑ๋":display_country(country),"์ฑ๋ถ๋ช
":safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
","")),"INCI Name":safe_str(component.get("INCI Name","")),"ํ์ ":safe_str(result_text),"์ถ์ฒ":safe_str(source),"๊ฒ์ ์๋ฌธ":safe_str(context)[:3000]})
|
|
|
|
| 318 |
result_obj["๋น๊ณ "]=(note+" / "+ev) if note and note!="-" else ev
|
| 319 |
return result_obj
|
| 320 |
|
| 321 |
+
def normalize_formula_country_text(text,country_col="",inci_name="",amount_text=""):
|
| 322 |
+
text=safe_str(text); lower=text.lower(); inci_norm=normalize_compact(inci_name)
|
| 323 |
+
if not text or text=="-" or text==NO_EVIDENCE_TEXT: return "Pass"
|
| 324 |
+
if any(k in text for k in ["๋ฐฐํฉ๊ธ์ง","์ฌ์ฉ๊ธ์ง","๊ธ์ง"]) or any(k in lower for k in ["prohibited","banned","not allowed"]): return "๋ฐฐํฉ๊ธ์ง"
|
| 325 |
+
if LIMIT_CHECK_TEXT in text: return LIMIT_CHECK_TEXT
|
| 326 |
+
if NEED_CHECK_TEXT in text: return NEED_CHECK_TEXT
|
| 327 |
+
if "ํฅ๋ฃ" in text or "fragrance" in lower or "parfum" in lower: return NEED_CHECK_TEXT
|
| 328 |
+
if "๊ธฐ๋ฅ์ฑ" in text: return "๊ธฐ๋ฅ์ฑ ํ์ธ"
|
| 329 |
+
if "ํจ๋ ์ ๋ณด ์์" in text or "ํจ๋ ํ์ธ" in text: return "ํจ๋ ํ์ธ"
|
| 330 |
+
if "octocrylene" in inci_norm or "์ฅํ ํฌ๋ฆด๋ " in inci_norm:
|
| 331 |
+
if country_col=="EU": return "๋ฐฐํฉ ํ๋:\n์คํ๋ ์ด: 9% /\n๊ธฐํ์ ํ: 10%"
|
| 332 |
+
if country_col=="FDA": return "๋ผ๋ฒจ๋ง ํ์"
|
| 333 |
+
if country_col in ["Korea","์ผ๋ณธ"]: return "๋ฐฐํฉํ๋: 10%"
|
| 334 |
+
if "homosalate" in inci_norm or "ํธ๋ชจ์ด๋ ์ดํธ" in inci_norm:
|
| 335 |
+
if country_col=="ASEAN": return "๋ฐฐํฉํ๋: 10%"
|
| 336 |
+
if country_col=="EU": return "๋ฐฐํฉํ๋: 7.34%"
|
| 337 |
+
if country_col=="FDA": return "๋ฐฐํฉํ๋: 15%"
|
| 338 |
+
if country_col in ["Korea","์ผ๋ณธ"]: return "๋ฐฐํฉํ๋: 10%"
|
| 339 |
+
if "octisalate" in inci_norm or "ethylhexylsalicylate" in inci_norm or "์ฅํฐ์ด๋ ์ดํธ" in inci_norm: return "๋ฐฐํฉํ๋: 5%"
|
| 340 |
+
if "avobenzone" in inci_norm or "์๋ณด๋ฒค์กด" in inci_norm: return "๋ฐฐํฉํ๋: 3%" if country_col=="FDA" else "๋ฐฐํฉํ๋: 5%"
|
| 341 |
+
if any(k in text for k in ["์ด๊ณผ","๋ถ์ ํฉ","์ฌ์ฉ ๋ถ๊ฐ","์ฌ์ฉ๋ถ๊ฐ"]): return "ํ๋ ์ด๊ณผ"
|
| 342 |
+
if "ํ์ ํ์" in text or "๋ผ๋ฒจ" in text or "label" in lower: return "๋ผ๋ฒจ๋ง ํ์"
|
| 343 |
+
m=re.search(r"(?:๋ฐฐํฉ\s*ํ๋|๋ฐฐํฉํ๋|ํ๋|max|maximum|limit|์ต๋|์ดํ|์ด๋ด)\s*[:๏ผ]?\s*([0-9]+(?:\.[0-9]+)?\s*%)",text,flags=re.I)
|
| 344 |
+
if m: return "๋ฐฐํฉํ๋: "+m.group(1).replace(" ","")
|
| 345 |
+
if any(k in text for k in ["๋ฐฐํฉํ๋","๋ฐฐํฉ ํ๋","ํ๋","์ ํ"]) or any(k in lower for k in ["maximum","limit","restricted"]): return LIMIT_CHECK_TEXT
|
| 346 |
+
return text[:120]
|
| 347 |
|
| 348 |
|
| 349 |
def standardize_formula_dataframe(df):
|
|
|
|
| 594 |
return False
|
| 595 |
|
| 596 |
|
| 597 |
+
|
| 598 |
+
|
| 599 |
# ============================================================
|
| 600 |
# ๊ท์ ๋์์ด / CAS / ์ด์ฑ์ง์ฒด ๋ ์ง์คํธ๋ฆฌ
|
| 601 |
# - ๊ตญ๊ฐ๋ณ ํ์ผ ํ๊ธฐ๊ฐ INCI์ ๋ค๋ฅผ ๋ PASS ์คํ์ ๋ง๊ธฐ ์ํ ๋ณด์ ์ธต
|
|
|
|
| 1184 |
return False
|
| 1185 |
|
| 1186 |
|
| 1187 |
+
|
| 1188 |
+
|
| 1189 |
# country db
|
| 1190 |
|
| 1191 |
def resolve_country_folder(country):
|
|
|
|
| 1195 |
fmap={f.lower():f for f in os.listdir(".") if os.path.isdir(f)}
|
| 1196 |
return fmap.get(alias.lower(),alias)
|
| 1197 |
|
| 1198 |
+
def get_country_folders():
|
| 1199 |
exclude={".git",".cache","__pycache__",".ipynb_checkpoints",".venv","venv","node_modules",FAISS_CACHE_DIR,"outputs"}
|
| 1200 |
folders=[f for f in os.listdir(".") if os.path.isdir(f) and f not in exclude]
|
| 1201 |
existing=set(folders); ordered=[c for c in COUNTRY_ORDER if c in existing]; extras=sorted([f for f in folders if f not in COUNTRY_ORDER])
|
| 1202 |
return ordered+extras if ordered or extras else COUNTRY_ORDER.copy()
|
| 1203 |
|
| 1204 |
+
def refresh_country_choices_keep_selection(current_values=None):
|
| 1205 |
choices=get_country_folders(); kept=[v for v in (current_values or []) if v in choices]
|
| 1206 |
return gr.update(choices=choices,value=kept)
|
| 1207 |
|
| 1208 |
+
def refresh_country_choices_and_clear_cache(current_values=None):
|
| 1209 |
+
VECTOR_DB_CACHE.clear(); EVAL_CACHE.clear(); REG_TEXT_CACHE.clear(); REG_SECTION_INDEX_CACHE.clear(); return refresh_country_choices_keep_selection(current_values)
|
| 1210 |
|
| 1211 |
def get_regulatory_file_list(folder):
|
| 1212 |
files=[]
|
|
|
|
| 1505 |
return False
|
| 1506 |
|
| 1507 |
|
| 1508 |
+
|
| 1509 |
+
|
| 1510 |
def mfds_click_first_detail_result(page):
|
| 1511 |
"""
|
| 1512 |
์์ฝ์ฒ ๊ฒ์ ๊ฒฐ๊ณผ์์ ๊ฒ์์ด์ ๊ฒฐ๊ณผ๋ช
์นญ์ด ๋ค๋ฅผ ์ ์๋ค.
|
|
|
|
| 1795 |
return [], last_error[:300]
|
| 1796 |
|
| 1797 |
|
| 1798 |
+
|
| 1799 |
+
|
| 1800 |
def mfds_launch_chromium(playwright_obj):
|
| 1801 |
"""
|
| 1802 |
Playwright Chromium ๋ธ๋ผ์ฐ์ ์คํ ํจ์.
|
|
|
|
| 1991 |
}
|
| 1992 |
|
| 1993 |
|
| 1994 |
+
def evaluate_critical_country_rule(country,material,component):
|
| 1995 |
+
ckey=country_key(country); identity=get_identity_raw(material,component)
|
| 1996 |
+
for r in CRITICAL_COUNTRY_RULES.values():
|
| 1997 |
+
if any_exact_alias_match(r.get("aliases",[]), identity):
|
| 1998 |
+
cr=r.get(ckey)
|
| 1999 |
+
if not cr: return None
|
| 2000 |
+
if cr.get("status")=="prohibited": return {"๋ํ INCI":r.get("label","-"),"๊ฒฐ๊ณผ":cr.get("result","๋ฐฐํฉ๊ธ์ง"),"ํ์๋ฌธ๊ตฌ":cr.get("formula_text","๋ฐฐํฉ๊ธ์ง"),"๋น๊ณ ":cr.get("note","-")}
|
| 2001 |
+
if cr.get("status")=="restricted": return {"๋ํ INCI":r.get("label","-"),"๊ฒฐ๊ณผ":cr.get("result","์ ํ ์ฑ๋ถ"),"ํ์๋ฌธ๊ตฌ":cr.get("formula_text",LIMIT_CHECK_TEXT),"๋น๊ณ ":cr.get("note","-")}
|
| 2002 |
+
return None
|
| 2003 |
|
| 2004 |
def evaluate_limit_rule(country,material,component,group,name):
|
| 2005 |
key=match_rule_key(material,component,group)
|
|
|
|
| 2013 |
return {"๋ํ INCI":label,"๊ฒฐ๊ณผ":f"{name} / {label} ํ์ฌ ํจ๋ {at}%, ํ๋ {format_percent(lim)}% ์ด๋ด","ํ์๋ฌธ๊ตฌ":cr.get("formula_text") or f"๋ฐฐํฉํ๋: {format_percent(lim)}%","๋น๊ณ ":"-"}
|
| 2014 |
return {"๋ํ INCI":label,"๊ฒฐ๊ณผ":f"{name} / {label} / ํ๋๊ฐ ํ์ธ ํ์","ํ์๋ฌธ๊ตฌ":LIMIT_CHECK_TEXT,"๋น๊ณ ":"๋ก์ปฌ ๊ท์น์ ์ฑ๋ถ์ ์์ผ๋ ํ๋๊ฐ์ด ๋น์ด ์์."}
|
| 2015 |
|
| 2016 |
+
def evaluate_local_rules(country,material,component,ingredient_totals,ingredient_amount_parts):
|
| 2017 |
+
crit=evaluate_critical_country_rule(country,material,component)
|
| 2018 |
+
if crit: return crit
|
| 2019 |
+
if is_always_pass_component(material,component): return {"๋ํ INCI":safe_str(component.get("INCI Name","")) or "Water","๊ฒฐ๊ณผ":NO_EVIDENCE_TEXT,"ํ์๋ฌธ๊ตฌ":"Pass","๋น๊ณ ":"์ ์ ์/Water/Aqua ๊ธฐ๋ณธ Pass ์ฒ๋ฆฌ"}
|
| 2020 |
+
fr=evaluate_plain_fragrance_rule(country,material,component)
|
| 2021 |
+
if fr: return fr
|
| 2022 |
+
for group,name in [(UV_FILTER_RULES,"UV ํํฐ"),(PRESERVATIVE_RULES,"๋ณด์กด์ /์ ํ์ฑ๋ถ")]:
|
| 2023 |
+
res=evaluate_limit_rule(country,material,component,group,name)
|
| 2024 |
+
if res: return res
|
| 2025 |
+
fkey=match_rule_key(material,component,FUNCTIONAL_KOREA_RULES)
|
| 2026 |
+
if country_key(country)=="KOREA" and fkey:
|
| 2027 |
+
r=FUNCTIONAL_KOREA_RULES[fkey]; amount=format_percent(component.get("amount_float")) if component.get("amount_float") is not None else "ํจ๋ ํ์ธ ํ์"
|
| 2028 |
+
return {"๋ํ INCI":r["label"],"๊ฒฐ๊ณผ":r["result"].format(amount=amount),"ํ์๋ฌธ๊ตฌ":r.get("formula_text","๊ธฐ๋ฅ์ฑ ํ์ธ"),"๋น๊ณ ":"๊ธฐ๋ฅ์ฑ ํ์ยท๊ด๊ณ ์ฌ๋ถ ํ์ธ"}
|
| 2029 |
+
identity=get_identity_raw(material,component)
|
| 2030 |
+
for r in FRAGRANCE_ALLERGEN_RULES.values():
|
| 2031 |
+
if any_exact_alias_match(r.get("aliases",[]), identity): return {"๋ํ INCI":r["label"],"๊ฒฐ๊ณผ":f"ํฅ๋ฃ ์๋ ๋ฅด๊ฒ / {r['label']} / {display_country(country)} ํ์๊ธฐ์ค ํ์ธ ํ์","ํ์๋ฌธ๊ตฌ":NEED_CHECK_TEXT,"๋น๊ณ ":"ํฅ๋ฃ ์๋ ๋ฅด๊ฒ ํ๋ณด. ์ธ๋ถ ํ์๊ธฐ์ค ๋ฐ ์ ํ ์ ํ ํ์ธ ํ์."}
|
| 2032 |
+
if component.get("amount_float") is None: return {"๋ํ INCI":safe_str(component.get("INCI Name","")) or "-","๊ฒฐ๊ณผ":"ํจ๋ ์ ๋ณด ์์ / In formula(w/w %) ํ์ธ ํ์","ํ์๋ฌธ๊ตฌ":"ํจ๋ ํ์ธ","๋น๊ณ ":"-"}
|
| 2033 |
+
return None
|
| 2034 |
|
| 2035 |
def parse_country_response(text):
|
| 2036 |
res={"๋ํ INCI":"-","๊ฒฐ๊ณผ":NO_EVIDENCE_TEXT,"ํ์๋ฌธ๊ตฌ":"Pass","๋น๊ณ ":"-"}
|
|
|
|
| 2089 |
for cc in country_cols: total_row[cc]=""
|
| 2090 |
rows.append(total_row); return pd.DataFrame(rows)
|
| 2091 |
|
| 2092 |
+
def make_regulatory_summary_rows(row_items,country_cols):
|
| 2093 |
+
rows=[]
|
| 2094 |
+
for item in row_items:
|
| 2095 |
+
rd=item["row_data"]
|
| 2096 |
+
if not is_country_result_issue(rd.get("Result","")): continue
|
| 2097 |
+
row={"ํ๊ธ ์ฑ๋ถ๋ช
":rd.get("ํ๊ธ ์ฑ๋ถ๋ช
",""),"INCI Name":rd.get("INCI Name",""),"In formula(w/w %)":rd.get("In formula\n(w/w %)",""),"Result":rd.get("Result","")}
|
| 2098 |
+
for cc in country_cols: row[cc]=rd.get(cc,"") if is_country_result_issue(rd.get(cc,"")) else "-"
|
| 2099 |
+
row["๋น๊ณ "]=rd.get("๋น๊ณ ","-"); rows.append(row)
|
| 2100 |
+
cols=["ํ๊ธ ์ฑ๋ถ๋ช
","INCI Name","In formula(w/w %)","Result"]+country_cols+["๋น๊ณ "]
|
| 2101 |
+
return pd.DataFrame(rows,columns=cols)
|
| 2102 |
|
| 2103 |
def sum_formula_percent(df): return sum(to_number(r.get("%(w/w)","")) or 0 for _,r in df.iterrows() if not is_total_like_text(r.get("INGREDIENT NAME (INCI)","")))
|
| 2104 |
|
|
|
|
| 2121 |
for col in range(1,sheet.max_column+1): sheet.column_dimensions[get_column_letter(col)].width=18
|
| 2122 |
wb.save(path)
|
| 2123 |
|
| 2124 |
+
def build_integrated_result(rd,country_cols):
|
| 2125 |
+
issues=[cc for cc in country_cols if is_country_result_issue(rd.get(cc,""))]
|
| 2126 |
+
return "PASS" if not issues else "์ฌ๊ฒํ ํ์: "+", ".join(issues)
|
| 2127 |
|
| 2128 |
def process(countries,file,product_name="",use_mfds_live=False,live_max_terms=5,live_headless=True):
|
| 2129 |
"""
|
|
|
|
| 2399 |
return mat, comp, at
|
| 2400 |
|
| 2401 |
|
| 2402 |
+
|
| 2403 |
+
|
| 2404 |
+
|
| 2405 |
def get_country_regulatory_text_cached(country):
|
| 2406 |
"""
|
| 2407 |
๊ตญ๊ฐ๋ณ ๊ท์ ํ์ผ ์๋ฌธ์ ์ง์ ์ฝ์ด์ ์บ์ํ๋ค.
|
|
|
|
| 2635 |
return sections
|
| 2636 |
|
| 2637 |
|
| 2638 |
+
def get_country_section_index_cached(country):
|
| 2639 |
"""
|
| 2640 |
๋จ์ผ ์ฑ๋ถ ๊ฒ์ ๊ณ ์ํ์ฉ ์น์
์ธ๋ฑ์ค.
|
| 2641 |
๊ตญ๊ฐ๋ณ ํ์ผ์ ๋งค๋ฒ PDF/Excel ์ ์ฒด ์ฝ๊ธฐํ์ง ์๊ณ ,
|
|
|
|
| 2900 |
return "\n".join(messages) if messages else "์ ํ๋ ๊ตญ๊ฐ ์์"
|
| 2901 |
|
| 2902 |
|
| 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()
|
| 2935 |
+
if cleaned not in condition_lines:
|
| 2936 |
+
condition_lines.append(cleaned)
|
| 2937 |
+
|
| 2938 |
+
return ", ".join(limits[:5]), " / ".join(condition_lines[:5])[:700]
|
| 2939 |
+
|
| 2940 |
+
|
| 2941 |
def make_restricted_or_positive_result(country, component, match, reg_type):
|
| 2942 |
context = safe_str(match.get("context", "")) if isinstance(match, dict) else safe_str(match)
|
| 2943 |
label = safe_str(reg_type.get("label", "๊ท์ ๋ชฉ๋ก"))
|
|
|
|
| 3150 |
return records, "BUILT_SOURCE_RECORD_INDEX"
|
| 3151 |
|
| 3152 |
|
| 3153 |
+
def pick_best_source_record(records):
|
| 3154 |
+
priority = {
|
| 3155 |
+
"prohibited": 100,
|
| 3156 |
+
"restricted": 80,
|
| 3157 |
+
"positive_uv": 50,
|
| 3158 |
+
"positive_preservative": 50,
|
| 3159 |
+
"positive_colorant": 50,
|
| 3160 |
+
"unknown": 10,
|
| 3161 |
+
}
|
| 3162 |
+
|
| 3163 |
+
return sorted(
|
| 3164 |
+
records,
|
| 3165 |
+
key=lambda r: priority.get(r.get("regulation_type", {}).get("type", "unknown"), 0),
|
| 3166 |
+
reverse=True,
|
| 3167 |
+
)[0] if records else None
|
| 3168 |
+
|
| 3169 |
+
|
| 3170 |
+
def evaluate_component_from_uploaded_source_records(country, material, component, target_id=""):
|
| 3171 |
+
"""
|
| 3172 |
+
๊ตญ๊ฐ ํด๋ ํ์ผ๋ง ๋ณด๊ณ ํ์ .
|
| 3173 |
+
ํ์ผ record ์์ ํ์ฌ ์ฑ๋ถ๋ช
/๊ตญ๋ฌธ/CAS๊ฐ ์ง์ ์์ ๋๋ง ํ์ ํ๋ค.
|
| 3174 |
+
"""
|
| 3175 |
+
terms = source_match_terms_for_component(material, component)
|
| 3176 |
+
term_norms = [normalize_compact(t) for t in terms if len(normalize_compact(t)) >= 3]
|
| 3177 |
+
|
| 3178 |
+
representative = (
|
| 3179 |
+
safe_str(component.get("INCI Name", ""))
|
| 3180 |
+
or safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", ""))
|
| 3181 |
+
or safe_str(component.get("CAS.No", ""))
|
| 3182 |
+
or "-"
|
| 3183 |
+
)
|
| 3184 |
+
|
| 3185 |
+
if not term_norms:
|
| 3186 |
+
return None
|
| 3187 |
+
|
| 3188 |
+
records, status = build_country_source_record_index(country)
|
| 3189 |
+
hits = []
|
| 3190 |
+
|
| 3191 |
+
for rec in records:
|
| 3192 |
+
rec_norm = rec.get("text_norm", "")
|
| 3193 |
+
|
| 3194 |
+
if any(tn in rec_norm for tn in term_norms):
|
| 3195 |
+
hits.append(rec)
|
| 3196 |
+
|
| 3197 |
+
if not hits:
|
| 3198 |
+
return None
|
| 3199 |
+
|
| 3200 |
+
best = pick_best_source_record(hits)
|
| 3201 |
+
reg_type = best.get("regulation_type", {})
|
| 3202 |
+
reg_kind = reg_type.get("type", "unknown")
|
| 3203 |
+
reg_label = reg_type.get("label", "๊ท์ ์ ํ ๋ฏธ๋ถ๋ฅ")
|
| 3204 |
+
context = best.get("text", "")
|
| 3205 |
+
country_col = display_country(country)
|
| 3206 |
+
|
| 3207 |
+
if reg_kind == "prohibited":
|
| 3208 |
+
result = {
|
| 3209 |
+
"๋ํ INCI": representative,
|
| 3210 |
+
"๊ฒฐ๊ณผ": f"{country_col} {reg_label}์์ ์ฑ๋ถ ์ง์ ํ์ธ",
|
| 3211 |
+
"ํ์๋ฌธ๊ตฌ": "๋ฐฐํฉ๊ธ์ง",
|
| 3212 |
+
"๋น๊ณ ": f"[์ถ์ฒํ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
|
| 3213 |
+
}
|
| 3214 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "UPLOADED_SOURCE_RECORD_PROHIBITED", result["๋น๊ณ "])
|
| 3215 |
+
return result
|
| 3216 |
+
|
| 3217 |
+
if reg_kind == "restricted":
|
| 3218 |
+
limit_text, condition_text = extract_limit_condition_from_context(context)
|
| 3219 |
+
result = {
|
| 3220 |
+
"๋ํ INCI": representative,
|
| 3221 |
+
"๊ฒฐ๊ณผ": f"{country_col} {reg_label}์์ ์ฑ๋ถ ์ง์ ํ์ธ" + (f" / ์กฐ๊ฑด: {condition_text}" if condition_text else ""),
|
| 3222 |
+
"ํ์๋ฌธ๊ตฌ": f"๋ฐฐํฉํ๋: {limit_text}" if limit_text else NEED_CHECK_TEXT,
|
| 3223 |
+
"๋น๊ณ ": f"[์ถ์ฒํ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
|
| 3224 |
+
}
|
| 3225 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "UPLOADED_SOURCE_RECORD_RESTRICTED", result["๋น๊ณ "])
|
| 3226 |
+
return result
|
| 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 |
+
|
| 3251 |
+
def evaluate_component_from_country_files_only(country, material, component, target_id=""):
|
| 3252 |
+
"""
|
| 3253 |
+
๊ตญ๊ฐ๋ณ ์
๋ก๋ ํ์ผ ๊ธฐ๋ฐ ํ์ .
|
| 3254 |
+
์ฑ๋ถ๋ณ ํ๋์ฝ๋ฉ registry๋ณด๋ค ์
๋ก๋๋ ๊ตญ๊ฐ ํ์ผ row/line record๋ฅผ ์ฐ์ ์ฌ์ฉํ๋ค.
|
| 3255 |
+
|
| 3256 |
+
์์น:
|
| 3257 |
+
- ์
๋ก๋ ํ์ผ record์ ํ์ฌ ์ฑ๋ถ๋ช
/๊ตญ๋ฌธ/CAS๊ฐ ์ง์ ์์ผ๋ฉด ๊ทธ ํ์ผ ์ ํ์ ๋ฐ๋ผ ํ์
|
| 3258 |
+
- ๊ธ์ง/์ ํ/Positive List ํ์ผ๋ช
๋๋ row ๋ฌธ๋งฅ์ผ๋ก ์ ํ ํ๋จ
|
| 3259 |
+
- ํ์ผ์์ ์ง์ ๊ทผ๊ฑฐ๊ฐ ์์ผ๋ฉด Pass
|
| 3260 |
+
- broad alias/glycol/extract ๊ฐ์ ๋์ ๊ฒ์์ด๋ก ๊ธ์ง/์ ํ ๋ง๋ค์ง ์์
|
| 3261 |
+
"""
|
| 3262 |
+
country_col = display_country(country)
|
| 3263 |
+
|
| 3264 |
+
inci_name = safe_str(component.get("INCI Name", ""))
|
| 3265 |
+
korean_name = safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", ""))
|
| 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 = {
|
| 3288 |
+
"๋ํ INCI": representative if representative != "-" else "Water",
|
| 3289 |
+
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 3290 |
+
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 3291 |
+
"๋น๊ณ ": "์ ์ ์/Water/Aqua ๊ธฐ๋ณธ Pass ์ฒ๋ฆฌ",
|
| 3292 |
+
}
|
| 3293 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "ALWAYS_PASS_RULE", result["๋น๊ณ "])
|
| 3294 |
+
return result
|
| 3295 |
+
|
| 3296 |
+
source_result = evaluate_component_from_uploaded_source_records(
|
| 3297 |
+
country=country,
|
| 3298 |
+
material=material,
|
| 3299 |
+
component=component,
|
| 3300 |
+
target_id=target_id,
|
| 3301 |
+
)
|
| 3302 |
+
|
| 3303 |
+
if source_result is not None:
|
| 3304 |
+
return source_result
|
| 3305 |
+
|
| 3306 |
+
result = {
|
| 3307 |
+
"๋ํ INCI": representative,
|
| 3308 |
+
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 3309 |
+
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 3310 |
+
"๋น๊ณ ": "์
๋ก๋๋ ๊ตญ๊ฐ๋ณ ํ์ผ ๋ด ํ์ฌ ์ฑ๋ถ ์ง์ ๊ทผ๊ฑฐ ์์",
|
| 3311 |
+
}
|
| 3312 |
+
log_search_context(
|
| 3313 |
+
target_id,
|
| 3314 |
+
country,
|
| 3315 |
+
component,
|
| 3316 |
+
result["๊ฒฐ๊ณผ"],
|
| 3317 |
+
"UPLOADED_SOURCE_RECORD_NO_HIT",
|
| 3318 |
+
result["๋น๊ณ "],
|
| 3319 |
+
)
|
| 3320 |
+
return result
|
| 3321 |
+
|
| 3322 |
+
|
| 3323 |
+
|
| 3324 |
def shorten_for_table(value, max_len=80):
|
| 3325 |
value = safe_str(value)
|
| 3326 |
|
|
|
|
| 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 |
+
|
| 3646 |
+
def auth_fn(username, password):
|
| 3647 |
+
username = str(username).strip().lower()
|
| 3648 |
+
password = str(password).strip()
|
| 3649 |
+
|
| 3650 |
+
return USER_DB.get(username) == password
|
| 3651 |
+
|
| 3652 |
+
|
| 3653 |
+
|
| 3654 |
# ============================================================
|
| 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 |
+
|
| 3672 |
|
| 3673 |
# ============================================================
|
| 3674 |
# ๋ก๊ทธ์ธ ์ธ์ฆ
|
|
|
|
| 3676 |
# - USER_DB์ ์ฌ๋ฌ ์์ด๋/๋น๋ฐ๋ฒํธ๋ฅผ ์ง์ ๋ฑ๋ก
|
| 3677 |
# ============================================================
|
| 3678 |
|
| 3679 |
+
USER_DB = {
|
| 3680 |
+
"jin2li@rebom.kr": "qwer0515!",
|
| 3681 |
+
|
| 3682 |
+
# ์ฌ์ฉ์ ์ถ๊ฐ ์์:
|
| 3683 |
+
# "yubin.p@rebom.kr": "์ํ๋๋น๋ฐ๋ฒํธ",
|
| 3684 |
+
# "jkh@rebom.kr": "rebom123!",
|
| 3685 |
+
}
|
| 3686 |
+
|
| 3687 |
+
|
| 3688 |
+
def auth_fn(username, password):
|
| 3689 |
+
username = str(username).strip().lower()
|
| 3690 |
+
password = str(password).strip()
|
| 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 |
+
|
| 3708 |
|
| 3709 |
# ============================================================
|
| 3710 |
# ๋ก๊ทธ์ธ ์ธ์ฆ
|
|
|
|
| 3716 |
# "๋ฉ์ผ์ฃผ์": "๋น๋ฐ๋ฒํธ",
|
| 3717 |
# ============================================================
|
| 3718 |
|
| 3719 |
+
USER_DB = {
|
| 3720 |
+
"jin2li@rebom.kr": "qwer0515!",
|
| 3721 |
|
| 3722 |
+
# ์ฌ์ฉ์ ๋ฑ๋ก ์์:
|
| 3723 |
+
# "yubin.p@rebom.kr": "123456!",
|
| 3724 |
+
# "jkh@rebom.kr": "rebom123!",
|
| 3725 |
+
}
|
| 3726 |
|
| 3727 |
|
| 3728 |
+
def auth_fn(username, password):
|
| 3729 |
+
username = str(username).strip().lower()
|
| 3730 |
+
password = str(password).strip()
|
| 3731 |
+
return USER_DB.get(username) == password
|
|
|
|
| 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 |
|
| 3749 |
|
|
|
|
| 3752 |
# - Gradio ๊ธฐ๋ณธ ๋ก๊ทธ์ธ์ฐฝ ์ฌ์ฉ
|
| 3753 |
# - ์๋ USER_DB์ ๋ฉ์ผ/๋น๋ฐ๋ฒํธ๋ฅผ ์ง์ ๋ฑ๋ก
|
| 3754 |
# ============================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3755 |
|
| 3756 |
USER_DB = {
|
| 3757 |
"jin2li@rebom.kr": "qwer0515!",
|
|
|
|
|
|
|
| 3758 |
|
| 3759 |
# ์ฌ์ฉ์ ๋ฑ๋ก ์์:
|
| 3760 |
# "yubin.p@rebom.kr": "123456!",
|
| 3761 |
+
# "jkh@rebom.kr": "rebom123!",
|
| 3762 |
}
|
| 3763 |
|
| 3764 |
|
|
|
|
| 3781 |
single_use_mfds_live,
|
| 3782 |
)
|
| 3783 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3784 |
|
| 3785 |
+
|
| 3786 |
+
# ============================================================
|
| 3787 |
+
# ๋ก๊ทธ์ธ ์ธ์ฆ
|
| 3788 |
+
# - Gradio ๊ธฐ๋ณธ ๋ก๊ทธ์ธ์ฐฝ ์ฌ์ฉ
|
| 3789 |
+
# - ์๋ USER_DB์ ๋ฉ์ผ/๋น๋ฐ๋ฒํธ๋ฅผ ์ง์ ๋ฑ๋ก
|
| 3790 |
+
# ============================================================
|
| 3791 |
+
|
| 3792 |
+
USER_DB = {
|
| 3793 |
+
"jin2li@rebom.kr": "qwer0515!",
|
| 3794 |
+
|
| 3795 |
+
# ์ฌ์ฉ์ ๋ฑ๋ก ์์:
|
| 3796 |
+
# "yubin.p@rebom.kr": "123456!",
|
| 3797 |
+
# "jkh@rebom.kr": "rebom123!",
|
| 3798 |
+
}
|
| 3799 |
+
|
| 3800 |
+
|
| 3801 |
+
def auth_fn(username, password):
|
| 3802 |
+
username = str(username).strip().lower()
|
| 3803 |
+
password = str(password).strip()
|
| 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 |
+
|
| 3821 |
+
|
| 3822 |
+
# ============================================================
|
| 3823 |
+
# ๋ก๊ทธ์ธ ์ธ์ฆ
|
| 3824 |
+
# - Gradio ๊ธฐ๋ณธ ๋ก๊ทธ์ธ์ฐฝ ์ฌ์ฉ
|
| 3825 |
+
# - ์๋ USER_DB์ ๋ฉ์ผ/๋น๋ฐ๋ฒํธ๋ฅผ ์ง์ ๋ฑ๋ก
|
| 3826 |
+
|
| 3827 |
+
|
| 3828 |
+
|
| 3829 |
+
# ============================================================
|
| 3830 |
+
# ๋ก๊ทธ์ธ ์ธ์ฆ
|
| 3831 |
+
# - Gradio ๊ธฐ๋ณธ ๋ก๊ทธ์ธ์ฐฝ ์ฌ์ฉ
|
| 3832 |
+
# - ์๋ USER_DB์ ๋ฉ์ผ/๋น๋ฐ๋ฒํธ๋ฅผ ์ง์ ๋ฑ๋ก
|
| 3833 |
+
# ============================================================
|
| 3834 |
+
# ์ฌ์ฉ์ ์ถ๊ฐ ๋ฐฉ๋ฒ:
|
| 3835 |
+
# USER_DB ์์ "์์ด๋": "๋น๋ฐ๋ฒํธ", ํ์์ผ๋ก ํ ์ค์ฉ ์ถ๊ฐํ์ธ์.
|
| 3836 |
+
# ๊ฐ ์ค ๋์๋ ์ฝค๋ง(,)๋ฅผ ๋ถ์ด๋ ๊ฒ์ ๊ถ์ฅํฉ๋๋ค.
|
| 3837 |
+
# ============================================================
|
| 3838 |
+
|
| 3839 |
+
USER_DB = {
|
| 3840 |
+
"jin2li@rebom.kr": "qwer0515!",
|
| 3841 |
+
"jkh@rebom.kr": "rebom123!",
|
| 3842 |
+
"admin": "rebom123!",
|
| 3843 |
+
|
| 3844 |
+
# ์ฌ์ฉ์ ๋ฑ๋ก ์์:
|
| 3845 |
+
# "yubin.p@rebom.kr": "123456!",
|
| 3846 |
+
}
|
| 3847 |
+
|
| 3848 |
+
|
| 3849 |
+
def auth_fn(username, password):
|
| 3850 |
+
username = str(username).strip().lower()
|
| 3851 |
+
password = str(password).strip()
|
| 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 |
"๋ฐฐํฉ๊ธ์ง", "์ฌ์ฉ๊ธ์ง", "์ฌ์ฉ ๊ธ์ง", "๊ธ์ง์๋ฃ", "๊ธ์ง ์๋ฃ", "๊ธ์ง์ฑ๋ถ", "๊ธ์ง ์ฑ๋ถ",
|
|
|
|
| 4021 |
|
| 4022 |
return has_glycerin and has_deg and has_impurity_limit
|
| 4023 |
|
| 4024 |
+
def _v51_record_type(country, record, component=None):
|
| 4025 |
+
if component is not None and _v51_is_glycerin_deg_impurity_record(country, record, component):
|
| 4026 |
+
return "nonlegal_impurity"
|
| 4027 |
+
|
| 4028 |
+
category = _v51_folder_category(country, record)
|
| 4029 |
+
text = safe_str(record.get("text", ""))
|
| 4030 |
+
path_text = _v51_path_text(record)
|
| 4031 |
+
combined = path_text + "\n" + text[:1500]
|
| 4032 |
+
|
| 4033 |
+
if category in ["nonlegal_prop65", "nonlegal_retailer", "nonlegal_impurity", "nonlegal_voluntary", "nonlegal_labeling", "reference"]:
|
| 4034 |
+
return category
|
| 4035 |
+
if category in ["legal_prohibited", "legal_restricted", "positive_list"]:
|
| 4036 |
+
return category
|
| 4037 |
+
|
| 4038 |
+
# mixed legal file ๋ด๋ถ ๋ฌธ๋งฅ ๋ณด์
|
| 4039 |
+
if category == "legal_mixed":
|
| 4040 |
+
if _v51_text_has_any(combined, ["appendix 1", "annex ii", "prohibited", "๊ธ์ง", "์ฌ์ฉํ ์ ์๋ ์๋ฃ"]):
|
| 4041 |
+
return "legal_prohibited"
|
| 4042 |
+
if _v51_text_has_any(combined, ["appendix 2", "annex iii", "restricted", "์ ํ", "๋ฐฐํฉํ๋", "maximum amount"]):
|
| 4043 |
+
return "legal_restricted"
|
| 4044 |
+
if _v51_text_has_any(combined, ["appendix 3", "appendix 4", "annex iv", "annex v", "annex vi", "preservative", "uv absorber", "uv filter", "tar colors", "์์", "๋ณด์กด์ ", "์์ธ์ "]):
|
| 4045 |
+
return "positive_list"
|
| 4046 |
+
return "reference"
|
| 4047 |
+
|
| 4048 |
+
# ํด๋๋ช
์ด ๋ถ๋ช
ํํ ๊ฒฝ์ฐ ๋ฌธ๋งฅ๋ง์ผ๋ก ๋งค์ฐ ๋ณด์์ ์ผ๋ก ํ๋จ
|
| 4049 |
+
if _v51_text_has_any(combined, V51_PROHIBITED_TERMS):
|
| 4050 |
+
return "legal_prohibited"
|
| 4051 |
+
if _v51_text_has_any(combined, V51_RESTRICTED_TERMS):
|
| 4052 |
+
return "legal_restricted"
|
| 4053 |
+
if _v51_text_has_any(combined, ["positive list", "permitted", "ํ์ฉ๋ชฉ๋ก", "ํ์ฉ ๋ชฉ๋ก", "coloring agents", "preservatives", "uv filters"]):
|
| 4054 |
+
return "positive_list"
|
| 4055 |
+
return "unknown"
|
| 4056 |
|
| 4057 |
|
| 4058 |
def _v51_component_match_in_record(record_text, terms):
|
|
|
|
| 4144 |
return "Pass"
|
| 4145 |
|
| 4146 |
|
| 4147 |
+
def evaluate_critical_country_rule(country, material, component):
|
| 4148 |
+
if SOURCE_ONLY_MODE:
|
| 4149 |
+
return None
|
| 4150 |
+
return None
|
| 4151 |
+
|
| 4152 |
+
|
| 4153 |
+
def evaluate_plain_fragrance_rule(country, material, component):
|
| 4154 |
+
if SOURCE_ONLY_MODE:
|
| 4155 |
+
return None
|
| 4156 |
+
return None
|
| 4157 |
+
|
| 4158 |
+
|
| 4159 |
+
def evaluate_local_rules(country, material, component, ingredient_totals, ingredient_amount_parts):
|
| 4160 |
+
if SOURCE_ONLY_MODE:
|
| 4161 |
+
return None
|
| 4162 |
+
return None
|
| 4163 |
+
|
| 4164 |
+
|
| 4165 |
def _v51_nonlegal_result(kind, country, component, best, target_id=""):
|
| 4166 |
country_col = display_country(country)
|
| 4167 |
representative = safe_str(component.get("INCI Name", "")) or safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", "")) or safe_str(component.get("CAS.No", "")) or "-"
|
|
|
|
| 4236 |
return result
|
| 4237 |
|
| 4238 |
|
| 4239 |
+
def evaluate_component_from_uploaded_source_records(country, material, component, target_id=""):
|
| 4240 |
+
terms = source_match_terms_for_component(material, component)
|
| 4241 |
+
representative = safe_str(component.get("INCI Name", "")) or safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", "")) or safe_str(component.get("CAS.No", "")) or "-"
|
| 4242 |
+
if not terms:
|
| 4243 |
+
return None
|
| 4244 |
+
|
| 4245 |
+
records, status = build_country_source_record_index(country)
|
| 4246 |
+
hits = []
|
| 4247 |
+
for rec in records:
|
| 4248 |
+
rec_text = safe_str(rec.get("text", ""))
|
| 4249 |
+
if _v51_component_match_in_record(rec_text, terms):
|
| 4250 |
+
hits.append(rec)
|
| 4251 |
+
|
| 4252 |
+
if not hits:
|
| 4253 |
+
return None
|
| 4254 |
+
|
| 4255 |
+
priority = {
|
| 4256 |
+
"legal_prohibited": 100,
|
| 4257 |
+
"legal_restricted": 90,
|
| 4258 |
+
"positive_list": 70,
|
| 4259 |
+
"nonlegal_retailer": 60,
|
| 4260 |
+
"nonlegal_prop65": 58,
|
| 4261 |
+
"nonlegal_voluntary": 56,
|
| 4262 |
+
"nonlegal_impurity": 54,
|
| 4263 |
+
"nonlegal_labeling": 52,
|
| 4264 |
+
"reference": 20,
|
| 4265 |
+
"unknown": 10,
|
| 4266 |
+
}
|
| 4267 |
+
typed_hits = [(rec, _v51_record_type(country, rec, component)) for rec in hits]
|
| 4268 |
+
typed_hits.sort(key=lambda x: priority.get(x[1], 0), reverse=True)
|
| 4269 |
+
best, kind = typed_hits[0]
|
| 4270 |
+
context = safe_str(best.get("text", ""))
|
| 4271 |
+
src_note = f"[์ถ์ฒํ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}"
|
| 4272 |
+
country_col = display_country(country)
|
| 4273 |
+
|
| 4274 |
+
if kind == "legal_prohibited":
|
| 4275 |
+
result = {
|
| 4276 |
+
"๋ํ INCI": representative,
|
| 4277 |
+
"๊ฒฐ๊ณผ": f"{country_col}: ์
๋ก๋ ๋ฒ์ ๊ธ์ง ํด๋/ํ์ผ์์ ์ฑ๋ถ ์ง์ ํ์ธ",
|
| 4278 |
+
"ํ์๋ฌธ๊ตฌ": "๋ฐฐํฉ๊ธ์ง",
|
| 4279 |
+
"๋น๊ณ ": src_note,
|
| 4280 |
+
}
|
| 4281 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "V51_LEGAL_PROHIBITED", result["๋น๊ณ "])
|
| 4282 |
+
return result
|
| 4283 |
+
|
| 4284 |
+
if kind == "legal_restricted":
|
| 4285 |
+
limit_text, condition_text = extract_limit_condition_from_context(context)
|
| 4286 |
+
result = {
|
| 4287 |
+
"๋ํ INCI": representative,
|
| 4288 |
+
"๊ฒฐ๊ณผ": f"{country_col}: ์
๋ก๋ ๋ฒ์ ์ ํ ํด๋/ํ์ผ์์ ์ฑ๋ถ ์ง์ ํ์ธ" + (f" / ํ๋ {limit_text}" if limit_text else " / ํ๋ยท์กฐ๊ฑด ํ์ธ ํ์") + (f" / ์กฐ๊ฑด: {condition_text}" if condition_text else ""),
|
| 4289 |
+
"ํ์๋ฌธ๊ตฌ": f"๋ฐฐํฉํ๋: {limit_text}" if limit_text else NEED_CHECK_TEXT,
|
| 4290 |
+
"๋น๊ณ ": src_note,
|
| 4291 |
+
}
|
| 4292 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "V51_LEGAL_RESTRICTED", result["๋น๊ณ "])
|
| 4293 |
+
return result
|
| 4294 |
+
|
| 4295 |
+
if kind == "positive_list":
|
| 4296 |
+
limit_text, condition_text = extract_limit_condition_from_context(context)
|
| 4297 |
+
if limit_text:
|
| 4298 |
+
result = {
|
| 4299 |
+
"๋ํ INCI": representative,
|
| 4300 |
+
"๊ฒฐ๊ณผ": f"{country_col}: ํ์ฉ๋ชฉ๋ก์์ ์ฑ๋ถ ์ง์ ํ์ธ / ํ๋ {limit_text}" + (f" / ์กฐ๊ฑด: {condition_text}" if condition_text else ""),
|
| 4301 |
+
"ํ์๋ฌธ๊ตฌ": f"๋ฐฐํฉํ๋: {limit_text}",
|
| 4302 |
+
"๋น๊ณ ": src_note,
|
| 4303 |
+
}
|
| 4304 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "V51_POSITIVE_LIST_LIMIT", result["๋น๊ณ "])
|
| 4305 |
+
return result
|
| 4306 |
+
result = {
|
| 4307 |
+
"๋ํ INCI": representative,
|
| 4308 |
+
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 4309 |
+
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 4310 |
+
"๋น๊ณ ": "ํ์ฉ๋ชฉ๋ก์์ ์ฑ๋ถ๋ช
ํ์ธ. ๋ช
ํํ ๋ฐฐํฉํ๋ ์์น ๊ทผ๊ฑฐ ์์. " + src_note,
|
| 4311 |
+
}
|
| 4312 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "V51_POSITIVE_LIST_PASS", result["๋น๊ณ "])
|
| 4313 |
+
return result
|
| 4314 |
+
|
| 4315 |
+
if kind.startswith("nonlegal_") or kind == "reference":
|
| 4316 |
+
return _v51_nonlegal_result(kind, country, component, best, target_id)
|
| 4317 |
+
|
| 4318 |
+
result = {
|
| 4319 |
+
"๋ํ INCI": representative,
|
| 4320 |
+
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 4321 |
+
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 4322 |
+
"๋น๊ณ ": "์ฑ๋ถ๋ช
์ ์
๋ก๋ ํ์ผ์์ ๋ฐ๊ฒฌ๋์์ผ๋ ๊ธ์ง/์ ํ/ํ๋ ๊ทผ๊ฑฐ ์์. " + src_note,
|
| 4323 |
+
}
|
| 4324 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "V51_SOURCE_NAME_ONLY_PASS", result["๋น๊ณ "])
|
| 4325 |
+
return result
|
| 4326 |
+
|
| 4327 |
+
|
| 4328 |
+
def evaluate_component_from_country_files_only(country, material, component, target_id=""):
|
| 4329 |
+
representative = safe_str(component.get("INCI Name", "")) or safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", "")) or safe_str(component.get("CAS.No", "")) or "-"
|
| 4330 |
+
|
| 4331 |
+
if is_always_pass_component(material, component):
|
| 4332 |
+
result = {
|
| 4333 |
+
"๋ํ INCI": representative if representative != "-" else "Water",
|
| 4334 |
+
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 4335 |
+
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 4336 |
+
"๋น๊ณ ": "์ ์ ์/Water/Aqua ๊ธฐ๋ณธ Pass ์ฒ๋ฆฌ",
|
| 4337 |
+
}
|
| 4338 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "ALWAYS_PASS_RULE", result["๋น๊ณ "])
|
| 4339 |
+
return result
|
| 4340 |
+
|
| 4341 |
+
source_result = evaluate_component_from_uploaded_source_records(country, material, component, target_id)
|
| 4342 |
+
if source_result is not None:
|
| 4343 |
+
return source_result
|
| 4344 |
+
|
| 4345 |
+
result = {
|
| 4346 |
+
"๋ํ INCI": representative,
|
| 4347 |
+
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 4348 |
+
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 4349 |
+
"๋น๊ณ ": "์
๋ก๋๋ ๊ตญ๊ฐ๋ณ ํ์ผ ๋ด ํ์ฌ ์ฑ๋ถ ์ง์ ๊ทผ๊ฑฐ ์์",
|
| 4350 |
+
}
|
| 4351 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "V51_SOURCE_NO_HIT_PASS", result["๋น๊ณ "])
|
| 4352 |
+
return result
|
| 4353 |
+
|
| 4354 |
+
|
| 4355 |
+
def is_country_result_issue(text):
|
| 4356 |
+
text = safe_str(text)
|
| 4357 |
+
if not text or text in ["-", NO_EVIDENCE_TEXT, "Pass", "PASS", "pass"]:
|
| 4358 |
+
return False
|
| 4359 |
+
if "ํ์ฉ๋ชฉ๋ก" in text and not _v51_text_has_any(text, V51_RESTRICTED_TERMS + V51_PROHIBITED_TERMS):
|
| 4360 |
+
return False
|
| 4361 |
+
issue_markers = [
|
| 4362 |
+
"๋ฐฐํฉ๊ธ์ง", "๊ธ์ง", "๋ฐฐํฉํ๋", "ํ๋", "ํ์ธ ํ์", "๊ฒฝ๊ณ ํ์", "Clean ๊ธฐ์ค",
|
| 4363 |
+
"๋ถ์๋ฌผ", "์ค์ผ๋ฌผ์ง", "์์จ๊ธฐ์ค", "ํ์๊ธฐ์ค", "๋ถ์ ํฉ", "์ฌ๊ฒํ ", "์ฌ์ฉ ๋ถ๊ฐ", "์ฌ์ฉ๋ถ๊ฐ",
|
| 4364 |
+
]
|
| 4365 |
+
return _v51_text_has_any(text, issue_markers + V51_PROHIBITED_TERMS + V51_RESTRICTED_TERMS)
|
| 4366 |
+
|
| 4367 |
# ============================================================
|
| 4368 |
# END STRUCTURED FOLDER SCREENING PATCH V5.1
|
| 4369 |
# ============================================================
|
| 4370 |
|
| 4371 |
|
| 4372 |
+
|
| 4373 |
+
|
| 4374 |
# ============================================================
|
| 4375 |
# STRUCTURED FOLDER SCREENING PATCH V5.2
|
| 4376 |
# 2026-06: US ํด๋๋ช
๋ฐ์ + ์ฃผ์ ์คํ์ ์ฐจ๋จ
|
|
|
|
| 4380 |
# - Phenoxyethanol: EU/ASEAN/KOREA/JAPAN ๋ณด์กด์ ์ต๋ 1.0% ํ๋๋ก ๊ณ ์ ๋ณด์
|
| 4381 |
# ============================================================
|
| 4382 |
|
| 4383 |
+
COUNTRY_ORDER = ["ASEAN", "CALIFORNIA", "CHINA", "EU (FUTURE)", "EU", "US", "JAPAN", "KOREA", "MEXICO", "SEPHORA", "TARGET", "UK", "ULTA"]
|
| 4384 |
COUNTRY_DISPLAY.update({"FDA": "US", "๋ฏธ๊ตญ": "US", "USA": "US", "US": "US", "us": "US"})
|
| 4385 |
COUNTRY_FOLDER_ALIASES.update({"FDA": "US", "๋ฏธ๊ตญ": "US", "USA": "US", "US": "US", "us": "us"})
|
| 4386 |
+
BLOCKED_PATHS = [str(BASE_DIR / c) for c in COUNTRY_ORDER] + [str(BASE_DIR / "us")] + [str(BASE_DIR/FAISS_CACHE_DIR), str(BASE_DIR/'.env'), str(BASE_DIR/'__pycache__')]
|
| 4387 |
+
|
| 4388 |
+
|
| 4389 |
+
def country_key(country):
|
| 4390 |
+
t = safe_str(country).upper().replace("_", " ").replace("-", " ")
|
| 4391 |
+
t = re.sub(r"\s+", " ", t).strip()
|
| 4392 |
+
m = {
|
| 4393 |
+
"ํ๊ตญ": "KOREA", "KOREA": "KOREA", "KR": "KOREA",
|
| 4394 |
+
"EU": "EU", "EUROPE": "EU", "์ ๋ฝ": "EU",
|
| 4395 |
+
"EU FUTURE": "EU_FUTURE", "EU (FUTURE)": "EU_FUTURE",
|
| 4396 |
+
"JAPAN": "JAPAN", "JP": "JAPAN", "์ผ๋ณธ": "JAPAN",
|
| 4397 |
+
"CHINA": "CHINA", "CN": "CHINA", "์ค๊ตญ": "CHINA",
|
| 4398 |
+
"USA": "US", "US": "US", "๋ฏธ๊ตญ": "US", "FDA": "US",
|
| 4399 |
+
"ASEAN": "ASEAN", "์์ธ์": "ASEAN",
|
| 4400 |
+
"UK": "UK", "์๊ตญ": "UK",
|
| 4401 |
+
"SEPHORA": "SEPHORA", "TARGET": "TARGET", "ULTA": "ULTA",
|
| 4402 |
+
"CALIFORNIA": "CALIFORNIA", "MEXICO": "MEXICO",
|
| 4403 |
+
}
|
| 4404 |
+
return m.get(t, t)
|
| 4405 |
+
|
| 4406 |
+
|
| 4407 |
+
def display_country(country):
|
| 4408 |
+
c = country_key(country)
|
| 4409 |
+
if c == "US":
|
| 4410 |
+
return "US"
|
| 4411 |
+
return COUNTRY_DISPLAY.get(str(country).upper(), COUNTRY_DISPLAY.get(str(country), c))
|
| 4412 |
|
| 4413 |
|
| 4414 |
def _v52_component_blob(material, component):
|
|
|
|
| 4538 |
return "unknown"
|
| 4539 |
|
| 4540 |
|
| 4541 |
+
def evaluate_component_from_country_files_only(country, material, component, target_id=""):
|
| 4542 |
+
representative = safe_str(component.get("INCI Name", "")) or safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", "")) or safe_str(component.get("CAS.No", "")) or "-"
|
| 4543 |
+
|
| 4544 |
+
if is_always_pass_component(material, component):
|
| 4545 |
+
result = {
|
| 4546 |
+
"๋ํ INCI": representative if representative != "-" else "Water",
|
| 4547 |
+
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 4548 |
+
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 4549 |
+
"๋น๊ณ ": "์ ์ ์/Water/Aqua ๊ธฐ๋ณธ Pass ์ฒ๏ฟฝ๏ฟฝ๏ฟฝ",
|
| 4550 |
+
}
|
| 4551 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "ALWAYS_PASS_RULE", result["๋น๊ณ "])
|
| 4552 |
+
return result
|
| 4553 |
+
|
| 4554 |
+
correction = _v52_known_correction(country, material, component, target_id)
|
| 4555 |
+
if correction is not None:
|
| 4556 |
+
return correction
|
| 4557 |
+
|
| 4558 |
+
source_result = evaluate_component_from_uploaded_source_records(country, material, component, target_id)
|
| 4559 |
+
if source_result is not None:
|
| 4560 |
+
return source_result
|
| 4561 |
+
|
| 4562 |
+
result = {
|
| 4563 |
+
"๋ํ INCI": representative,
|
| 4564 |
+
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 4565 |
+
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 4566 |
+
"๋น๊ณ ": "์
๋ก๋๋ ๊ตญ๊ฐ๋ณ ํ์ผ ๋ด ํ์ฌ ์ฑ๋ถ ์ง์ ๊ทผ๊ฑฐ ์์",
|
| 4567 |
+
}
|
| 4568 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "V52_SOURCE_NO_HIT_PASS", result["๋น๊ณ "])
|
| 4569 |
+
return result
|
| 4570 |
|
| 4571 |
# ============================================================
|
| 4572 |
# END STRUCTURED FOLDER SCREENING PATCH V5.2
|
|
|
|
| 4583 |
# - ํ์ผ๋ช
/๋ฌธ์ ์ ์ฒด์ prohibited/limit ํค์๋๋ง์ผ๋ก ์ฑ๋ถ ํ์ ๊ธ์ง
|
| 4584 |
# ============================================================
|
| 4585 |
|
| 4586 |
+
SOURCE_ONLY_MODE = True
|
| 4587 |
+
TREAT_POSITIVE_LIST_AS_PASS = True
|
| 4588 |
+
COUNTRY_ORDER = ["ASEAN", "CALIFORNIA", "CHINA", "EU (FUTURE)", "EU", "US", "us", "JAPAN", "KOREA", "MEXICO", "SEPHORA", "TARGET", "UK", "ULTA"]
|
| 4589 |
COUNTRY_DISPLAY.update({"FDA": "US", "๋ฏธ๊ตญ": "US", "USA": "US", "US": "US", "us": "US"})
|
| 4590 |
COUNTRY_FOLDER_ALIASES.update({"FDA": "US", "๋ฏธ๊ตญ": "US", "USA": "US", "US": "US", "us": "us", "Us": "US"})
|
| 4591 |
+
BLOCKED_PATHS = [str(BASE_DIR / c) for c in COUNTRY_ORDER] + [str(BASE_DIR/FAISS_CACHE_DIR), str(BASE_DIR/'.env'), str(BASE_DIR/'__pycache__')]
|
| 4592 |
|
| 4593 |
|
| 4594 |
def country_key(country):
|
|
|
|
| 4609 |
return m.get(t, t)
|
| 4610 |
|
| 4611 |
|
| 4612 |
+
def display_country(country):
|
| 4613 |
+
c = country_key(country)
|
| 4614 |
+
if c == "US":
|
| 4615 |
+
return "US"
|
| 4616 |
+
if c == "KOREA":
|
| 4617 |
+
return "Korea"
|
| 4618 |
+
if c == "JAPAN":
|
| 4619 |
+
return "์ผ๋ณธ"
|
| 4620 |
+
if c == "CHINA":
|
| 4621 |
+
return "์ค๊ตญ"
|
| 4622 |
+
return COUNTRY_DISPLAY.get(str(country).upper(), COUNTRY_DISPLAY.get(str(country), c))
|
| 4623 |
+
|
| 4624 |
+
|
| 4625 |
def _v6_path_text(record):
|
| 4626 |
return f"{safe_str(record.get('source_file',''))}\n{safe_str(record.get('sheet',''))}".replace('\\', '/')
|
| 4627 |
|
|
|
|
| 4868 |
return _v6_result(representative, NO_EVIDENCE_TEXT, "Pass", src, target_id, country, component, "V6_REFERENCE_ONLY_NO_LEGAL_CLASSIFICATION")
|
| 4869 |
|
| 4870 |
|
| 4871 |
+
def pick_best_source_record(records):
|
| 4872 |
+
priority = {
|
| 4873 |
+
"legal_prohibited": 100,
|
| 4874 |
+
"legal_restricted": 80,
|
| 4875 |
+
"positive_list": 60,
|
| 4876 |
+
"nonlegal_prop65": 45,
|
| 4877 |
+
"nonlegal_retailer": 40,
|
| 4878 |
+
"nonlegal_impurity": 35,
|
| 4879 |
+
"nonlegal_voluntary": 30,
|
| 4880 |
+
"nonlegal_labeling": 30,
|
| 4881 |
+
"reference_microplastics": 20,
|
| 4882 |
+
"reference": 10,
|
| 4883 |
+
"unknown": 0,
|
| 4884 |
+
}
|
| 4885 |
+
return sorted(records, key=lambda r: priority.get(r.get("v6_type", "unknown"), 0), reverse=True)[0] if records else None
|
| 4886 |
+
|
| 4887 |
+
|
| 4888 |
+
def evaluate_component_from_uploaded_source_records(country, material, component, target_id=""):
|
| 4889 |
+
"""
|
| 4890 |
+
V6 source-table-row engine.
|
| 4891 |
+
์ฑ๋ถ๋ช
/CAS๊ฐ ๊ฐ์ row/window์ ์ง์ ์๋ ๊ฒฝ์ฐ๋ง hit๋ก ์ธ์ ํ๊ณ ,
|
| 4892 |
+
ํด๋/Annex/Appendix ๊ตฌ์กฐ๊ฐ ๋ฒ์ ์ ํ์ ๊ฒฐ์ ํ๋ค.
|
| 4893 |
+
"""
|
| 4894 |
+
terms = _v6_component_terms(material, component)
|
| 4895 |
+
representative = safe_str(component.get("INCI Name", "")) or safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", "")) or safe_str(component.get("CAS.No", "")) or "-"
|
| 4896 |
+
if not terms:
|
| 4897 |
+
return None
|
| 4898 |
+
|
| 4899 |
+
records, status = build_country_source_record_index(country)
|
| 4900 |
+
hits = []
|
| 4901 |
+
for rec in records:
|
| 4902 |
+
if not _v6_row_direct_match(rec.get("text", ""), terms):
|
| 4903 |
+
continue
|
| 4904 |
+
rtype = _v6_record_type(country, rec, material, component)
|
| 4905 |
+
rec2 = dict(rec)
|
| 4906 |
+
rec2["v6_type"] = rtype
|
| 4907 |
+
hits.append(rec2)
|
| 4908 |
+
|
| 4909 |
+
if not hits:
|
| 4910 |
+
return None
|
| 4911 |
+
|
| 4912 |
+
best = pick_best_source_record(hits)
|
| 4913 |
+
rtype = best.get("v6_type", "unknown")
|
| 4914 |
+
context = safe_str(best.get("text", ""))
|
| 4915 |
+
src_note = f"[์ถ์ฒํ์ผ: {best.get('source_file','')}] [row: {best.get('row_index','')}] {context[:900]}"
|
| 4916 |
+
cdisp = display_country(country)
|
| 4917 |
+
|
| 4918 |
+
if rtype == "legal_prohibited":
|
| 4919 |
+
return _v6_result(
|
| 4920 |
+
representative,
|
| 4921 |
+
f"{cdisp}: ๋ฒ์ ๊ธ์ง๋ชฉ๋ก์์ ์ฑ๋ถ ์ง์ ํ์ธ",
|
| 4922 |
+
"๋ฐฐํฉ๊ธ์ง",
|
| 4923 |
+
src_note,
|
| 4924 |
+
target_id, country, component, "V6_ROW_MATCH_PROHIBITED_FOLDER",
|
| 4925 |
+
)
|
| 4926 |
+
|
| 4927 |
+
if rtype == "legal_restricted":
|
| 4928 |
+
limit_text, condition_text = _v6_extract_limit_condition_from_row(context)
|
| 4929 |
+
formula = f"๋ฐฐํฉํ๋: {limit_text}" if limit_text else NEED_CHECK_TEXT
|
| 4930 |
+
result_text = f"{cdisp}: ๋ฒ์ ์ ํ๋ชฉ๋ก์์ ์ฑ๋ถ ์ง์ ํ์ธ" + (f" / ์กฐ๊ฑด: {condition_text}" if condition_text else "")
|
| 4931 |
+
return _v6_result(
|
| 4932 |
+
representative,
|
| 4933 |
+
result_text,
|
| 4934 |
+
formula,
|
| 4935 |
+
src_note,
|
| 4936 |
+
target_id, country, component, "V6_ROW_MATCH_RESTRICTED_FOLDER",
|
| 4937 |
+
)
|
| 4938 |
+
|
| 4939 |
+
if rtype == "positive_list":
|
| 4940 |
+
limit_text, condition_text = _v6_extract_limit_condition_from_row(context)
|
| 4941 |
+
formula = f"๋ฐฐํฉํ๋: {limit_text}" if limit_text else "ํ์ฉ๋ชฉ๋ก ๋ฑ์ฌ / ํ๋ ํ์ธ ํ์"
|
| 4942 |
+
result_text = f"{cdisp}: ํ์ฉ๋ชฉ๋ก์์ ์ฑ๋ถ ์ง์ ํ์ธ" + (f" / ์กฐ๊ฑด: {condition_text}" if condition_text else "")
|
| 4943 |
+
source_tag = "V6_ROW_MATCH_POSITIVE_LIST_LIMIT" if limit_text else "V6_ROW_MATCH_POSITIVE_LIST"
|
| 4944 |
+
return _v6_result(
|
| 4945 |
+
representative,
|
| 4946 |
+
result_text,
|
| 4947 |
+
formula,
|
| 4948 |
+
src_note,
|
| 4949 |
+
target_id, country, component, source_tag,
|
| 4950 |
+
)
|
| 4951 |
+
|
| 4952 |
+
if rtype in ["nonlegal_prop65", "nonlegal_retailer", "nonlegal_impurity", "nonlegal_voluntary", "nonlegal_labeling", "reference", "reference_microplastics"]:
|
| 4953 |
+
return _v6_nonlegal_result(country, material, component, best, rtype, target_id)
|
| 4954 |
+
|
| 4955 |
+
# unknown ํด๋/ํ์ผ์ ์ฑ๋ถ๋ช
์ด ์์ด๋ ๋ฒ์ ๊ธ์งยทํ๋ ํ์ ์ ๋ง๋ค์ง ์๋๋ค.
|
| 4956 |
+
return _v6_result(
|
| 4957 |
+
representative,
|
| 4958 |
+
NO_EVIDENCE_TEXT,
|
| 4959 |
+
"Pass",
|
| 4960 |
+
src_note + " / ํ์ผ ์ ํ ๋ฏธ๋ถ๋ฅ: ๋ฒ์ ๊ธ์งยทํ๋ ์๋ํ์ ์ ์ธ",
|
| 4961 |
+
target_id, country, component, "V6_UNKNOWN_SOURCE_NO_LEGAL_CLASSIFICATION",
|
| 4962 |
+
)
|
| 4963 |
+
|
| 4964 |
+
|
| 4965 |
+
def evaluate_component_from_country_files_only(country, material, component, target_id=""):
|
| 4966 |
+
representative = safe_str(component.get("INCI Name", "")) or safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", "")) or safe_str(component.get("CAS.No", "")) or "-"
|
| 4967 |
+
|
| 4968 |
+
if is_always_pass_component(material, component):
|
| 4969 |
+
return _v6_result(
|
| 4970 |
+
representative if representative != "-" else "Water",
|
| 4971 |
+
NO_EVIDENCE_TEXT,
|
| 4972 |
+
"Pass",
|
| 4973 |
+
"์ ์ ์/Water/Aqua ๊ธฐ๋ณธ Pass ์ฒ๋ฆฌ",
|
| 4974 |
+
target_id, country, component, "ALWAYS_PASS_RULE",
|
| 4975 |
+
)
|
| 4976 |
+
|
| 4977 |
+
source_result = evaluate_component_from_uploaded_source_records(country, material, component, target_id)
|
| 4978 |
+
if source_result is not None:
|
| 4979 |
+
return source_result
|
| 4980 |
+
|
| 4981 |
+
return _v6_result(
|
| 4982 |
+
representative,
|
| 4983 |
+
NO_EVIDENCE_TEXT,
|
| 4984 |
+
"Pass",
|
| 4985 |
+
"์
๋ก๋๋ ๊ตญ๊ฐ๋ณ ํ์ผ ๋ด ํ์ฌ ์ฑ๋ถ์ ๊ฐ์ ํ/๊ทผ์ ํ ์ง์ ๊ทผ๊ฑฐ ์์",
|
| 4986 |
+
target_id, country, component, "V6_NO_ROW_MATCH_PASS",
|
| 4987 |
+
)
|
| 4988 |
+
|
| 4989 |
+
|
| 4990 |
def evaluate_critical_country_rule(country, material, component):
|
| 4991 |
if SOURCE_ONLY_MODE:
|
| 4992 |
return None
|
|
|
|
| 5005 |
return None
|
| 5006 |
|
| 5007 |
|
| 5008 |
+
def is_country_result_issue(text):
|
| 5009 |
+
text = safe_str(text)
|
| 5010 |
+
if not text or text in ["-", NO_EVIDENCE_TEXT, "Pass", "PASS", "pass"]:
|
| 5011 |
+
return False
|
| 5012 |
+
if "ํ์ฉ๋ชฉ๋ก" in text and not _v6_has(text, ["๋ฐฐํฉํ๋", "ํ๋", "์กฐ๊ฑด", "ํ์ธ ํ์"]):
|
| 5013 |
+
return False
|
| 5014 |
+
return _v6_has(text, [
|
| 5015 |
+
"๋ฐฐํฉ๊ธ์ง", "๋ฐฐํฉํ๋", "ํ๋", "ํ์ธ ํ์", "๊ฒฝ๊ณ ํ์", "Clean ๊ธฐ์ค", "๋ถ์๋ฌผ", "์ค์ผ๋ฌผ์ง",
|
| 5016 |
+
"์์จ๊ธฐ์ค", "ํ์๊ธฐ์ค", "๋ถ์ ํฉ", "์ฌ๊ฒํ ", "์ฌ์ฉ ๋ถ๊ฐ", "์ฌ์ฉ๋ถ๊ฐ", "Microplastics",
|
| 5017 |
+
])
|
| 5018 |
|
| 5019 |
# ============================================================
|
| 5020 |
# END SOURCE TABLE ROW ENGINE PATCH V6
|
|
|
|
| 5433 |
# ============================================================
|
| 5434 |
|
| 5435 |
|
| 5436 |
+
|
| 5437 |
+
|
| 5438 |
# ============================================================
|
| 5439 |
# USER PATCH 2026-06-15
|
| 5440 |
# 1) Output country/channel display names forced to English
|
|
|
|
| 5495 |
return COUNTRY_DISPLAY.get(str(country).upper(), COUNTRY_DISPLAY.get(str(country), c))
|
| 5496 |
|
| 5497 |
|
| 5498 |
+
_ORIGINAL_get_country_folders = get_country_folders
|
| 5499 |
|
| 5500 |
|
| 5501 |
def get_country_folders():
|
|
|
|
| 5503 |
return [c for c in _ORIGINAL_get_country_folders() if not _is_hidden_always_folder(c)]
|
| 5504 |
|
| 5505 |
|
| 5506 |
+
_ORIGINAL_refresh_country_choices_keep_selection = refresh_country_choices_keep_selection
|
| 5507 |
|
| 5508 |
|
| 5509 |
def refresh_country_choices_keep_selection(current_values=None):
|
|
|
|
| 5520 |
return refresh_country_choices_keep_selection(current_values)
|
| 5521 |
|
| 5522 |
|
| 5523 |
+
_ORIGINAL_get_country_section_index_cached = get_country_section_index_cached
|
| 5524 |
|
| 5525 |
|
| 5526 |
def get_country_section_index_cached(country):
|
|
|
|
| 5556 |
return list(sections or []) + extra_sections, status
|
| 5557 |
|
| 5558 |
|
| 5559 |
+
with gr.Blocks(css=custom_css) as demo:
|
| 5560 |
current_user = gr.State({})
|
| 5561 |
gr.Markdown("# ๐ reBom")
|
| 5562 |
gr.HTML("""
|
|
|
|
| 5635 |
</script>
|
| 5636 |
|
| 5637 |
|
| 5638 |
+
|
| 5639 |
+
|
| 5640 |
""")
|
| 5641 |
gr.Markdown("### Screening")
|
| 5642 |
|
|
|
|
| 5688 |
inputs=[current_user,single_country,single_query,single_amount,single_function],
|
| 5689 |
outputs=[single_df_out,single_msg_out],
|
| 5690 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5691 |
try:
|
| 5692 |
+
demo.launch(
|
| 5693 |
+
auth=auth_fn,
|
| 5694 |
+
server_name="0.0.0.0",server_port=7860,share=True,ssr_mode=False,allowed_paths=ALLOWED_PATHS,blocked_paths=BLOCKED_PATHS,show_api=False,footer_links=[],app_kwargs={"docs_url":None,"redoc_url":None,"openapi_url":None})
|
| 5695 |
+
except TypeError:
|
| 5696 |
+
demo.launch(
|
| 5697 |
+
auth=auth_fn,
|
| 5698 |
+
server_name="0.0.0.0",server_port=7860,share=True,allowed_paths=ALLOWED_PATHS,blocked_paths=BLOCKED_PATHS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|