Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -93,9 +93,9 @@ RAW_SEARCH_LOGS = []
|
|
| 93 |
REG_TEXT_CACHE = {}
|
| 94 |
REG_SECTION_INDEX_CACHE = {}
|
| 95 |
|
| 96 |
-
COUNTRY_ORDER = ["ASEAN","CALIFORNIA","CHINA","EU (FUTURE)","EU","
|
| 97 |
-
COUNTRY_DISPLAY = {"EU":"EU","์ ๋ฝ":"EU","FDA":"
|
| 98 |
-
COUNTRY_FOLDER_ALIASES = {"EU":"EU","์ ๋ฝ":"EU","FDA":"
|
| 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"}
|
|
@@ -166,7 +166,7 @@ def chunk_list(items,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":"
|
| 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)))
|
|
@@ -1574,7 +1574,7 @@ def country_aliases_for_mfds(country):
|
|
| 1574 |
alias_map = {
|
| 1575 |
"ASEAN": ["์์ธ์", "ASEAN"],
|
| 1576 |
"EU": ["์ ๋ฝ", "EU", "์ ๋ฝ์ฐํฉ", "European Union", "Europe"],
|
| 1577 |
-
"
|
| 1578 |
"KOREA": ["ํ๊ตญ", "๋ํ๋ฏผ๊ตญ", "Korea", "KOREA"],
|
| 1579 |
"JAPAN": ["์ผ๋ณธ", "Japan", "JAPAN"],
|
| 1580 |
"CHINA": ["์ค๊ตญ", "China", "CHINA"],
|
|
@@ -1606,7 +1606,7 @@ def parse_mfds_detail_text(term, text):
|
|
| 1606 |
country_candidates = [
|
| 1607 |
("ASEAN", ["์์ธ์", "ASEAN"]),
|
| 1608 |
("EU", ["์ ๋ฝ", "EU", "์ ๋ฝ์ฐํฉ"]),
|
| 1609 |
-
("
|
| 1610 |
("Korea", ["ํ๊ตญ", "๋ํ๋ฏผ๊ตญ", "Korea"]),
|
| 1611 |
("์ผ๋ณธ", ["์ผ๋ณธ", "Japan"]),
|
| 1612 |
("์ค๊ตญ", ["์ค๊ตญ", "China"]),
|
|
@@ -3983,7 +3983,48 @@ def _v51_folder_category(country, record):
|
|
| 3983 |
return "unknown"
|
| 3984 |
|
| 3985 |
|
| 3986 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3987 |
category = _v51_folder_category(country, record)
|
| 3988 |
text = safe_str(record.get("text", ""))
|
| 3989 |
path_text = _v51_path_text(record)
|
|
@@ -4223,7 +4264,7 @@ def evaluate_component_from_uploaded_source_records(country, material, component
|
|
| 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", ""))
|
|
@@ -4328,6 +4369,657 @@ def is_country_result_issue(text):
|
|
| 4328 |
# ============================================================
|
| 4329 |
|
| 4330 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4331 |
with gr.Blocks(css=custom_css) as demo:
|
| 4332 |
current_user = gr.State({})
|
| 4333 |
gr.Markdown("# ๐ reBom")
|
|
@@ -4426,9 +5118,6 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 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,7 +5128,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 4439 |
|
| 4440 |
btn.click(
|
| 4441 |
process_with_auth,
|
| 4442 |
-
inputs=[current_user,country,file,product_name
|
| 4443 |
outputs=[df_out,file_out,msg_out],
|
| 4444 |
)
|
| 4445 |
|
|
@@ -4452,7 +5141,6 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 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,7 +5149,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 4461 |
|
| 4462 |
single_btn.click(
|
| 4463 |
process_single_ingredient_with_auth,
|
| 4464 |
-
inputs=[current_user,single_country,single_query,single_amount,single_function
|
| 4465 |
outputs=[single_df_out,single_msg_out],
|
| 4466 |
)
|
| 4467 |
try:
|
|
|
|
| 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"}
|
|
|
|
| 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)))
|
|
|
|
| 1574 |
alias_map = {
|
| 1575 |
"ASEAN": ["์์ธ์", "ASEAN"],
|
| 1576 |
"EU": ["์ ๋ฝ", "EU", "์ ๋ฝ์ฐํฉ", "European Union", "Europe"],
|
| 1577 |
+
"US": ["๋ฏธ๊ตญ", "USA", "US", "United States", "FDA"],
|
| 1578 |
"KOREA": ["ํ๊ตญ", "๋ํ๋ฏผ๊ตญ", "Korea", "KOREA"],
|
| 1579 |
"JAPAN": ["์ผ๋ณธ", "Japan", "JAPAN"],
|
| 1580 |
"CHINA": ["์ค๊ตญ", "China", "CHINA"],
|
|
|
|
| 1606 |
country_candidates = [
|
| 1607 |
("ASEAN", ["์์ธ์", "ASEAN"]),
|
| 1608 |
("EU", ["์ ๋ฝ", "EU", "์ ๋ฝ์ฐํฉ"]),
|
| 1609 |
+
("US", ["๋ฏธ๊ตญ", "USA", "United States", "FDA"]),
|
| 1610 |
("Korea", ["ํ๊ตญ", "๋ํ๋ฏผ๊ตญ", "Korea"]),
|
| 1611 |
("์ผ๋ณธ", ["์ผ๋ณธ", "Japan"]),
|
| 1612 |
("์ค๊ตญ", ["์ค๊ตญ", "China"]),
|
|
|
|
| 3983 |
return "unknown"
|
| 3984 |
|
| 3985 |
|
| 3986 |
+
|
| 3987 |
+
def _v51_is_glycerin_deg_impurity_record(country, record, component):
|
| 3988 |
+
"""
|
| 3989 |
+
์ผ๋ณธ Standards for Cosmetics section 5 ์์ธ ์ฒ๋ฆฌ.
|
| 3990 |
+
Glycerin ๋ฌธ์ฅ์ ๊ธ๋ฆฌ์ธ๋ฆฐ ๋ฐฐํฉ๊ธ์ง๊ฐ ์๋๋ผ, ๊ธ๋ฆฌ์ธ๋ฆฐ ์๋ฃ ์ค Diethylene Glycol ๋ถ์๋ฌผ ๊ธฐ์ค์ด๋ค.
|
| 3991 |
+
๋ฐ๋ผ์ legal_mixed ๋ฌธ์ ์์ ์์ด๋ ๊ธ์ง/์ ํ์ผ๋ก ๋ถ๋ฅํ์ง ์๋๋ค.
|
| 3992 |
+
"""
|
| 3993 |
+
ckey = country_key(country)
|
| 3994 |
+
if ckey != "JAPAN":
|
| 3995 |
+
return False
|
| 3996 |
+
|
| 3997 |
+
comp_text = " ".join([
|
| 3998 |
+
safe_str(component.get("INCI Name", "")),
|
| 3999 |
+
safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", "")),
|
| 4000 |
+
safe_str(component.get("CAS.No", "")),
|
| 4001 |
+
])
|
| 4002 |
+
comp_norm = normalize_compact(comp_text)
|
| 4003 |
+
|
| 4004 |
+
is_glycerin_component = (
|
| 4005 |
+
"glycerin" in comp_norm
|
| 4006 |
+
or "glycerol" in comp_norm
|
| 4007 |
+
or "๊ธ๋ฆฌ์ธ๋ฆฐ" in comp_norm
|
| 4008 |
+
or "๊ธ๋ฆฌ์ธ๋กค" in comp_norm
|
| 4009 |
+
or "56-81-5" in comp_text
|
| 4010 |
+
)
|
| 4011 |
+
if not is_glycerin_component:
|
| 4012 |
+
return False
|
| 4013 |
+
|
| 4014 |
+
text = safe_str(record.get("text", ""))
|
| 4015 |
+
low = text.lower()
|
| 4016 |
+
compact = normalize_compact(text)
|
| 4017 |
+
|
| 4018 |
+
has_glycerin = "glycerin" in low or "glycerol" in low or "๊ธ๋ฆฌ์ธ๋ฆฐ" in compact or "๊ธ๋ฆฌ์ธ๋กค" in compact
|
| 4019 |
+
has_deg = "diethylene glycol" in low or "๋์ํธ๋ ๊ธ๋ผ์ด์ฝ" in compact or "๋์์น ๋ ๊ธ๋ฆฌ์ฝ" in compact or "deg" in low
|
| 4020 |
+
has_impurity_limit = "0.1g" in compact or "0.1 g" in low or "less than" in low or "์ดํ" in text or "๋ฏธ๋ง" in text
|
| 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)
|
|
|
|
| 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", ""))
|
|
|
|
| 4369 |
# ============================================================
|
| 4370 |
|
| 4371 |
|
| 4372 |
+
|
| 4373 |
+
|
| 4374 |
+
# ============================================================
|
| 4375 |
+
# STRUCTURED FOLDER SCREENING PATCH V5.2
|
| 4376 |
+
# 2026-06: US ํด๋๋ช
๋ฐ์ + ์ฃผ์ ์คํ์ ์ฐจ๋จ
|
| 4377 |
+
# - FDA ํ๊ธฐ๋ฅผ US๋ก ํต์ผ
|
| 4378 |
+
# - ์ผ๋ณธ Glycerin ๋ฐฐํฉ๊ธ์ง ์คํ์ ์ฐจ๋จ
|
| 4379 |
+
# - EU Carbomer / Adenosine ๋ฐฐํฉ๊ธ์ง ์คํ์ ์ฐจ๋จ
|
| 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):
|
| 4415 |
+
parts = []
|
| 4416 |
+
for obj in [material or {}, component or {}]:
|
| 4417 |
+
if isinstance(obj, dict):
|
| 4418 |
+
for k, v in obj.items():
|
| 4419 |
+
if k in ["INCI Name", "ํ๊ธ ์ฑ๋ถ๋ช
", "CAS.No", "CAS", "์ฑ๋ถ๋ช
", "ํ์ค๋ช
", "์๋ฌธ๋ช
", "Raw", "์๋ฃ๋ช
"]:
|
| 4420 |
+
parts.append(safe_str(v))
|
| 4421 |
+
return " ".join([p for p in parts if p])
|
| 4422 |
+
|
| 4423 |
+
|
| 4424 |
+
def _v52_is_component(material, component, aliases):
|
| 4425 |
+
blob = _v52_component_blob(material, component)
|
| 4426 |
+
low = blob.lower()
|
| 4427 |
+
compact = normalize_compact(blob)
|
| 4428 |
+
for alias in aliases:
|
| 4429 |
+
a = safe_str(alias)
|
| 4430 |
+
if not a:
|
| 4431 |
+
continue
|
| 4432 |
+
if is_cas_like(a) and a in blob:
|
| 4433 |
+
return True
|
| 4434 |
+
ac = normalize_compact(a)
|
| 4435 |
+
if len(ac) >= 3 and ac in compact:
|
| 4436 |
+
return True
|
| 4437 |
+
if a.lower() in low:
|
| 4438 |
+
return True
|
| 4439 |
+
return False
|
| 4440 |
+
|
| 4441 |
+
|
| 4442 |
+
def _v52_result(representative, result_text, formula_text, note, target_id, country, component, source_tag):
|
| 4443 |
+
out = {
|
| 4444 |
+
"๋ํ INCI": representative,
|
| 4445 |
+
"๊ฒฐ๊ณผ": result_text,
|
| 4446 |
+
"ํ์๋ฌธ๊ตฌ": formula_text,
|
| 4447 |
+
"๋น๊ณ ": note,
|
| 4448 |
+
}
|
| 4449 |
+
log_search_context(target_id, country, component, out["๊ฒฐ๊ณผ"], source_tag, out["๋น๊ณ "])
|
| 4450 |
+
return out
|
| 4451 |
+
|
| 4452 |
+
|
| 4453 |
+
def _v52_known_correction(country, material, component, target_id=""):
|
| 4454 |
+
ckey = country_key(country)
|
| 4455 |
+
cdisp = display_country(country)
|
| 4456 |
+
representative = safe_str(component.get("INCI Name", "")) or safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", "")) or safe_str(component.get("CAS.No", "")) or "-"
|
| 4457 |
+
|
| 4458 |
+
# Phenoxyethanol์ EU/ASEAN/ํ๊ตญ/์ผ๋ณธ์์ ๋ณด์กด์ ๋ก ์ต๋ 1.0% ํ๋. ํ๊ตญ ๋ฐฐํฉ๊ธ์ง ์๋.
|
| 4459 |
+
if _v52_is_component(material, component, ["phenoxyethanol", "phenoxy ethanol", "ํ๋
น์์ํ์ฌ", "ํ๋
น์ ์ํ์ฌ", "122-99-6"]):
|
| 4460 |
+
if ckey in ["EU", "ASEAN", "KOREA", "JAPAN"]:
|
| 4461 |
+
return _v52_result(
|
| 4462 |
+
representative or "Phenoxyethanol",
|
| 4463 |
+
f"{cdisp}: ๋ณด์กด์ ์ฌ์ฉํ๋ ์ต๋ 1.0%",
|
| 4464 |
+
"๋ฐฐํฉํ๋: 1.0%",
|
| 4465 |
+
"Phenoxyethanol/ํ๋
น์์ํ์ฌ์ ํด๋น ๊ตญ๊ฐ ๊ธฐ์ค์์ ๋ฐฐํฉ๊ธ์ง๊ฐ ์๋๋ผ ๋ณด์กด์ ์ฌ์ฉํ๋ 1.0%๋ก ์ฒ๋ฆฌ. restricted/positive preservative ๋ฌธ๋งฅ์ prohibited๋ก ์คํ์ ํ์ง ์๋๋ก ๋ณด์ .",
|
| 4466 |
+
target_id, country, component, "V52_FIXED_PHENOXYETHANOL_1_PERCENT",
|
| 4467 |
+
)
|
| 4468 |
+
|
| 4469 |
+
# ์ผ๋ณธ Glycerin ๋ฌธ๊ตฌ๋ Diethylene Glycol ๋ถ์๋ฌผ ๊ธฐ์ค. ๊ธ๋ฆฌ์ธ๋ฆฐ ๋ฐฐํฉ๊ธ์ง/๋ฐฐํฉํ๋ ์๋.
|
| 4470 |
+
if ckey == "JAPAN" and _v52_is_component(material, component, ["glycerin", "glycerol", "๊ธ๋ฆฌ์ธ๋ฆฐ", "๊ธ๋ฆฌ์ธ๋กค", "56-81-5"]):
|
| 4471 |
+
return _v52_result(
|
| 4472 |
+
representative or "Glycerin",
|
| 4473 |
+
"์ผ๋ณธ: ๊ธ๋ฆฌ์ธ๋ฆฐ ์๋ฃ ๋ถ์๋ฌผ ๊ธฐ์ค ํ์ธ ํ์",
|
| 4474 |
+
"๋ถ์๋ฌผ/์ค์ผ๋ฌผ์ง ํ์ธ",
|
| 4475 |
+
"์ผ๋ณธ Standards for Cosmetics์ 'Glycerin mixed with cosmetics should contain diethylene glycol less than 0.1g per 100g glycerin' ๋ฌธ๊ตฌ๋ ๊ธ๋ฆฌ์ธ๋ฆฐ ๋ฐฐํฉ๊ธ์ง๊ฐ ์๋๋ผ ๊ธ๋ฆฌ์ธ๋ฆฐ ์๋ฃ ์ค Diethylene Glycol ๋ถ์๋ฌผ ๊ธฐ์ค. ๋ฐฐํฉ๊ธ์ง/๋ฐฐํฉํ๋๋ก ํ์ ํ์ง ์์.",
|
| 4476 |
+
target_id, country, component, "V52_JP_GLYCERIN_DEG_IMPURITY_NOT_PROHIBITED",
|
| 4477 |
+
)
|
| 4478 |
+
|
| 4479 |
+
# EU Carbomer๋ ์ฑ๋ถ๋ช
์์ฒด๋ฅผ Annex II ๋ฐฐํฉ๊ธ์ง๋ก ๋จ์ ํ์ง ์๋๋ค.
|
| 4480 |
+
# microplastics/๊ณ ๋ถ์ ๋ฏธ๋ฆฝ์ ํด๋น์ฑ์ ์ ํ ํํยท์
์์ฑยท๋ถ์ฉ์ฑยท์
์ํฌ๊ธฐ ๊ธฐ์ค ๋ณ๋ ๊ฒํ .
|
| 4481 |
+
if ckey == "EU" and _v52_is_component(material, component, ["carbomer", "์นด๋ณด๋จธ", "์นด๋ณดํด", "9003-01-4", "9007-20-9"]):
|
| 4482 |
+
return _v52_result(
|
| 4483 |
+
representative or "Carbomer",
|
| 4484 |
+
"EU: Microplastics ํด๋น์ฑ ํ์ธ ํ์ / Carbomer ์์ฒด ๋ฐฐํฉ๊ธ์ง ์๋",
|
| 4485 |
+
NEED_CHECK_TEXT,
|
| 4486 |
+
"Carbomer๋ EU Annex II ๋ฐฐํฉ๊ธ์ง ์ฑ๋ถ์ผ๋ก ์๋ ํ์ ํ์ง ์์. REACH microplastics๋ ํน์ ํด๋ฆฌ๋จธ๋ช
์ ์ผ๊ด ๊ธ์งํ๋ ๊ตฌ์กฐ๊ฐ ์๋๋ผ ๊ณ ์ฒดยท๋ถ์ฉ์ฑยท์
์ํฌ๊ธฐยท์ฌ์ฉํํ ๋ฑ synthetic polymer microparticles ํด๋น์ฑ์ ๊ฒํ ํ๋ ๊ธฐ์ค์ผ๋ก ๋ถ๋ฆฌ.",
|
| 4487 |
+
target_id, country, component, "V52_EU_CARBOMER_MICROPLASTICS_REVIEW_NOT_PROHIBITED",
|
| 4488 |
+
)
|
| 4489 |
+
|
| 4490 |
+
# EU Adenosine์ Annex II/III ์ง์ ๊ทผ๊ฑฐ ์์ผ๋ฉด Pass. ํ๊ตญ ๊ธฐ๋ฅ์ฑ ๋ก์ง์ด EU๋ก ๋ฒ์ง์ง ์๊ฒ ์ฐจ๋จ.
|
| 4491 |
+
if ckey == "EU" and _v52_is_component(material, component, ["adenosine", "์๋ฐ๋
ธ์ ", "58-61-7"]):
|
| 4492 |
+
return _v52_result(
|
| 4493 |
+
representative or "Adenosine",
|
| 4494 |
+
NO_EVIDENCE_TEXT,
|
| 4495 |
+
"Pass",
|
| 4496 |
+
"EU ๊ธ์ง/์ ํ ์๋ฌธ์์ Adenosine ์ง์ ๊ธ์งยท์ ํ ๊ทผ๊ฑฐ ์์. ํ๊ตญ ๊ธฐ๋ฅ์ฑํ์ฅํ ์ฑ๋ถ ๋ก์ง์ EU ๋ฐฐํฉ๊ธ์ง๋ก ์ ์ฉํ์ง ์๋๋ก ๋ณด์ .",
|
| 4497 |
+
target_id, country, component, "V52_EU_ADENOSINE_PASS_NOT_PROHIBITED",
|
| 4498 |
+
)
|
| 4499 |
+
|
| 4500 |
+
return None
|
| 4501 |
+
|
| 4502 |
+
|
| 4503 |
+
# V5.2: mixed legal ๋ฌธ์ ๋ด๋ถ ๋ถ๋ฅ ๋ณด์ .
|
| 4504 |
+
def _v51_record_type(country, record, component=None):
|
| 4505 |
+
if component is not None and _v51_is_glycerin_deg_impurity_record(country, record, component):
|
| 4506 |
+
return "nonlegal_impurity"
|
| 4507 |
+
|
| 4508 |
+
category = _v51_folder_category(country, record)
|
| 4509 |
+
text = safe_str(record.get("text", ""))
|
| 4510 |
+
path_text = _v51_path_text(record)
|
| 4511 |
+
combined = path_text + "\n" + text[:1500]
|
| 4512 |
+
|
| 4513 |
+
# EU microplastics / CELEX 2023/2055 ๋ฌธ์๋ ์ฑ๋ถ๋ช
์ง์ ๋ฐฐํฉ๊ธ์ง ํ์ผ๋ก ์ฐ์ง ์๋๋ค.
|
| 4514 |
+
if country_key(country) == "EU" and _v51_text_has_any(combined, ["microplastic", "microplastics", "synthetic polymer microparticles", "celex_32023r2055", "2023r2055", "2023/2055"]):
|
| 4515 |
+
return "reference"
|
| 4516 |
+
|
| 4517 |
+
if category in ["nonlegal_prop65", "nonlegal_retailer", "nonlegal_impurity", "nonlegal_voluntary", "nonlegal_labeling", "reference"]:
|
| 4518 |
+
return category
|
| 4519 |
+
if category in ["legal_prohibited", "legal_restricted", "positive_list"]:
|
| 4520 |
+
return category
|
| 4521 |
+
|
| 4522 |
+
if category == "legal_mixed":
|
| 4523 |
+
# ์ผ๋ณธ Standards for Cosmetics: Appendix 3/4 ๋ณด์กด์ ยทUV๋ positive_list๊ฐ ์ฐ์ .
|
| 4524 |
+
if _v51_text_has_any(combined, ["appendix 3", "appendix 4", "preservative", "preservatives", "uv absorber", "uv absorbers", "uv filter", "uv filters", "tar colors", "์์", "๋ณด์กด๏ฟฝ๏ฟฝ๏ฟฝ", "์์ธ์ "]):
|
| 4525 |
+
return "positive_list"
|
| 4526 |
+
if _v51_text_has_any(combined, ["appendix 2", "annex iii", "restricted", "์ ํ", "๋ฐฐํฉํ๋", "maximum amount"]):
|
| 4527 |
+
return "legal_restricted"
|
| 4528 |
+
if _v51_text_has_any(combined, ["appendix 1", "annex ii", "prohibited", "๊ธ์ง", "์ฌ์ฉํ ์ ์๋ ์๋ฃ"]):
|
| 4529 |
+
return "legal_prohibited"
|
| 4530 |
+
return "reference"
|
| 4531 |
+
|
| 4532 |
+
if _v51_text_has_any(combined, V51_PROHIBITED_TERMS):
|
| 4533 |
+
return "legal_prohibited"
|
| 4534 |
+
if _v51_text_has_any(combined, V51_RESTRICTED_TERMS):
|
| 4535 |
+
return "legal_restricted"
|
| 4536 |
+
if _v51_text_has_any(combined, ["positive list", "permitted", "ํ์ฉ๋ชฉ๋ก", "ํ์ฉ ๋ชฉ๋ก", "coloring agents", "preservatives", "uv filters"]):
|
| 4537 |
+
return "positive_list"
|
| 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
|
| 4573 |
+
# ============================================================
|
| 4574 |
+
|
| 4575 |
+
|
| 4576 |
+
# ============================================================
|
| 4577 |
+
# SOURCE TABLE ROW ENGINE PATCH V6
|
| 4578 |
+
# ๋ชฉ์ : ์ฑ๋ถ๋ณ ์์ธ ํ๋์ฝ๋ฉ์ด ์๋๋ผ ํด๋/ํ/ํ ๊ธฐ๋ฐ์ผ๋ก๋ง ๋ฒ์ ๊ธ์งยทํ๋ ํ์
|
| 4579 |
+
# ์์น:
|
| 4580 |
+
# - ๊ธ์ง: prohibited ํด๋ ๋๋ ๋ฒ์ Annex/Appendix ๊ธ์ง ์น์
์์ ์ฑ๋ถ์ด ๊ฐ์ ํ/๊ทผ์ ํ์ ์ง์ ์์ ๋๋ง
|
| 4581 |
+
# - ํ๋: restricted/positive_preservatives/positive_uv/positive_colorants ํ์ ์ฑ๋ถ๊ณผ ์์น๊ฐ ์ง์ ์์ ๋๋ง
|
| 4582 |
+
# - reference/impurity/labeling/retailer/Prop65/voluntary ๋ฌธ์๋ ๋ฒ์ ๊ธ์งยทํ๋ ์์ฑ ๊ธ์ง
|
| 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):
|
| 4595 |
+
t = safe_str(country).upper().replace("_", " ").replace("-", " ")
|
| 4596 |
+
t = re.sub(r"\s+", " ", t).strip()
|
| 4597 |
+
m = {
|
| 4598 |
+
"ํ๊ตญ": "KOREA", "KOREA": "KOREA", "KR": "KOREA",
|
| 4599 |
+
"EU": "EU", "EUROPE": "EU", "์ ๋ฝ": "EU",
|
| 4600 |
+
"EU FUTURE": "EU_FUTURE", "EU (FUTURE)": "EU_FUTURE",
|
| 4601 |
+
"JAPAN": "JAPAN", "JP": "JAPAN", "์ผ๋ณธ": "JAPAN",
|
| 4602 |
+
"CHINA": "CHINA", "CN": "CHINA", "์ค๊ตญ": "CHINA",
|
| 4603 |
+
"USA": "US", "US": "US", "๋ฏธ๊ตญ": "US", "FDA": "US",
|
| 4604 |
+
"ASEAN": "ASEAN", "์์ธ์": "ASEAN",
|
| 4605 |
+
"UK": "UK", "์๊ตญ": "UK",
|
| 4606 |
+
"SEPHORA": "SEPHORA", "TARGET": "TARGET", "ULTA": "ULTA",
|
| 4607 |
+
"CALIFORNIA": "CALIFORNIA", "MEXICO": "MEXICO",
|
| 4608 |
+
}
|
| 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 |
+
|
| 4628 |
+
|
| 4629 |
+
def _v6_has(text, terms):
|
| 4630 |
+
low = safe_str(text).lower()
|
| 4631 |
+
comp = normalize_compact(text)
|
| 4632 |
+
for term in terms:
|
| 4633 |
+
term = safe_str(term)
|
| 4634 |
+
if not term:
|
| 4635 |
+
continue
|
| 4636 |
+
if term.lower() in low:
|
| 4637 |
+
return True
|
| 4638 |
+
tc = normalize_compact(term)
|
| 4639 |
+
if tc and tc in comp:
|
| 4640 |
+
return True
|
| 4641 |
+
return False
|
| 4642 |
+
|
| 4643 |
+
|
| 4644 |
+
def _v6_folder_category(record):
|
| 4645 |
+
"""
|
| 4646 |
+
์ค์ง ํด๋/ํ์ผ ๊ฒฝ๋ก๋ง์ผ๋ก ๋ฌธ์ ์ฑ๊ฒฉ์ ๋ถ๋ฅํ๋ค.
|
| 4647 |
+
๋ฌธ์ ๋ณธ๋ฌธ ํค์๋๋ง์ผ๋ก legal_prohibited/legal_restricted๋ฅผ ๋ง๋ค์ง ์๋๋ค.
|
| 4648 |
+
"""
|
| 4649 |
+
path = _v6_path_text(record)
|
| 4650 |
+
low = path.lower()
|
| 4651 |
+
compact = normalize_compact(path)
|
| 4652 |
+
|
| 4653 |
+
# ๋ฒ์ ํ์ ์ ์ธ ๊ณ์ด์ ์ต์ฐ์ ๋ถ๋ฆฌ
|
| 4654 |
+
if _v6_has(path, ["prop65", "proposition_65", "proposition 65", "california_prop65", "california_prop65_warning"]):
|
| 4655 |
+
return "nonlegal_prop65"
|
| 4656 |
+
if _v6_has(path, ["retailer", "sephora", "target", "ulta", "clean_standard", "clean"]):
|
| 4657 |
+
return "nonlegal_retailer"
|
| 4658 |
+
if _v6_has(path, ["impurity", "impurities", "contaminant", "contaminants", "contaminant_impurity_limits", "colorants_impurity_reference", "์ํ๋ฌผ์ง", "๋ถ์๋ฌผ", "์ค์ผ๋ฌผ์ง"]):
|
| 4659 |
+
return "nonlegal_impurity"
|
| 4660 |
+
if _v6_has(path, ["voluntary", "jcia", "์์จ", "์์", "์์ ", "voluntary_restriction", "voluntary_silicone_restriction"]):
|
| 4661 |
+
return "nonlegal_voluntary"
|
| 4662 |
+
if _v6_has(path, ["fragrance_allergen_labelling", "fragrance_allergen_labeling", "labeling", "labelling", "ํ์", "advertising"]):
|
| 4663 |
+
return "nonlegal_labeling"
|
| 4664 |
+
if _v6_has(path, ["microplastic", "microplastics", "synthetic_polymer", "celex_32023r2055", "2023r2055", "2023_2055"]):
|
| 4665 |
+
return "reference_microplastics"
|
| 4666 |
+
if _v6_has(path, ["reference", "archive", "test_method", "test-method", "์ํ๋ฐฉ๋ฒ", "functional_cosmetics_reference", "safety_assessment", "historical_use", "used_ingredient_inventory", "regulatory_framework", "ingredient_review_procedure", "human_cell_tissue_culture", "microbiological_quality"]):
|
| 4667 |
+
return "reference"
|
| 4668 |
+
|
| 4669 |
+
# ๋ฒ์ ๊ธ์ง/์ ํ ํด๋
|
| 4670 |
+
if "/prohibited/" in low or low.startswith("prohibited/") or "annex_ii_prohibited" in low or "annex ii prohibited" in low or "annex_1_prohibited" in low or "annex 1 prohibited" in low:
|
| 4671 |
+
return "legal_prohibited"
|
| 4672 |
+
if "๋ณํ1" in compact and ("์ฌ์ฉํ ์์๋" in compact or "prohibited" in low):
|
| 4673 |
+
return "legal_prohibited"
|
| 4674 |
+
|
| 4675 |
+
if "/restricted/" in low or low.startswith("restricted/") or "annex_iii_restricted" in low or "annex iii restricted" in low or "annex_2_restricted" in low or "restricted_ingredients" in low:
|
| 4676 |
+
return "legal_restricted"
|
| 4677 |
+
if "๋ณํ2" in compact and ("์ ํ" in compact or "restricted" in low):
|
| 4678 |
+
return "legal_restricted"
|
| 4679 |
+
|
| 4680 |
+
# Positive list ๊ณ์ด: ํ์ฉ๋ชฉ๋ก์ด์ง ๊ธ์ง๋ชฉ๋ก์ด ์๋
|
| 4681 |
+
if _v6_has(path, [
|
| 4682 |
+
"positive_colorants", "positive_colorant", "positive_preservatives", "positive_preservative",
|
| 4683 |
+
"positive_uv_filters", "positive_uv", "colorants_permitted", "permitted_colorants", "tar_colorants_permitted",
|
| 4684 |
+
"annex_iv", "annex-iv", "annex iv", "annex_v", "annex-v", "annex v", "annex_vi", "annex-vi", "annex vi",
|
| 4685 |
+
"permitted_preservatives", "permitted_uv", "ํ์ฉ์์", "ํ์ฉ ์์",
|
| 4686 |
+
]):
|
| 4687 |
+
return "positive_list"
|
| 4688 |
+
|
| 4689 |
+
# ํ ํ์ผ์ ์ฌ๋ฌ Annex/Appendix๊ฐ ๋ค์ด์๋ ๋ํ ๋ฒ์ ๋ฌธ์
|
| 4690 |
+
if _v6_has(path, ["annexes_main_screening", "cosmetic_standards_main", "standards_for_cosmetics", "jp_standards_for_cosmetics", "asean_acd_annexes", "annexes-of-the-asean-cosmetic-directive"]):
|
| 4691 |
+
return "legal_mixed"
|
| 4692 |
+
|
| 4693 |
+
return "unknown"
|
| 4694 |
+
|
| 4695 |
+
|
| 4696 |
+
def _v6_component_terms(material=None, component=None):
|
| 4697 |
+
terms = source_match_terms_for_component(material or {}, component or {})
|
| 4698 |
+
clean = []
|
| 4699 |
+
for t in terms:
|
| 4700 |
+
t = safe_str(t)
|
| 4701 |
+
if not t or is_broad_lookup_term(t):
|
| 4702 |
+
continue
|
| 4703 |
+
if len(normalize_compact(t)) < 3 and not is_cas_like(t):
|
| 4704 |
+
continue
|
| 4705 |
+
if t not in clean:
|
| 4706 |
+
clean.append(t)
|
| 4707 |
+
return clean
|
| 4708 |
+
|
| 4709 |
+
|
| 4710 |
+
def _v6_row_direct_match(record_text, terms):
|
| 4711 |
+
text = safe_str(record_text)
|
| 4712 |
+
if not text:
|
| 4713 |
+
return False
|
| 4714 |
+
found_cas = [normalize_compact(x) for x in re.findall(r"\d{2,7}-\d{2}-\d", text)]
|
| 4715 |
+
for term in terms:
|
| 4716 |
+
term = safe_str(term)
|
| 4717 |
+
if not term:
|
| 4718 |
+
continue
|
| 4719 |
+
if is_cas_like(term):
|
| 4720 |
+
if normalize_compact(term) in found_cas:
|
| 4721 |
+
return True
|
| 4722 |
+
continue
|
| 4723 |
+
if exact_ingredient_match(term, text):
|
| 4724 |
+
return True
|
| 4725 |
+
return False
|
| 4726 |
+
|
| 4727 |
+
|
| 4728 |
+
def _v6_is_component_alias(material, component, aliases):
|
| 4729 |
+
blob = " ".join([
|
| 4730 |
+
safe_str(component.get("INCI Name", "")),
|
| 4731 |
+
safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", "")),
|
| 4732 |
+
safe_str(component.get("CAS.No", "")),
|
| 4733 |
+
safe_str(material.get("Trade name(๊ตญ๋ฌธ)", "")),
|
| 4734 |
+
safe_str(material.get("Trade name(์๋ฌธ)", "")),
|
| 4735 |
+
])
|
| 4736 |
+
return _v6_row_direct_match(blob, aliases)
|
| 4737 |
+
|
| 4738 |
+
|
| 4739 |
+
def _v6_is_jp_glycerin_impurity_record(country, record, material, component):
|
| 4740 |
+
if country_key(country) != "JAPAN":
|
| 4741 |
+
return False
|
| 4742 |
+
if not _v6_is_component_alias(material, component, ["glycerin", "glycerol", "๊ธ๋ฆฌ์ธ๋ฆฐ", "๊ธ๋ฆฌ์ธ๋กค", "56-81-5"]):
|
| 4743 |
+
return False
|
| 4744 |
+
text = safe_str(record.get("text", ""))
|
| 4745 |
+
return _v6_has(text, ["diethylene glycol", "๋์ํธ๋ ๊ธ๋ผ์ด์ฝ", "๋์์น ๋ ๊ธ๋ฆฌ์ฝ"]) and _v6_has(text, ["0.1g", "0.1 g", "less than", "๋ฏธ๋ง"])
|
| 4746 |
+
|
| 4747 |
+
|
| 4748 |
+
def _v6_record_type(country, record, material=None, component=None):
|
| 4749 |
+
"""
|
| 4750 |
+
์ต์ข
record ์ ํ. V6์์๋ ๋ฌธ์ ์ ์ฒด ํค์๋ fallback ๊ธ์ง.
|
| 4751 |
+
legal_mixed๋ง ํ/๋ถ์์ heading์ผ๋ก ๋ด๋ถ ๋ถ๋ฅํ๋ค.
|
| 4752 |
+
"""
|
| 4753 |
+
folder_cat = _v6_folder_category(record)
|
| 4754 |
+
text = safe_str(record.get("text", ""))
|
| 4755 |
+
basis = _v6_path_text(record) + "\n" + text[:1500]
|
| 4756 |
+
|
| 4757 |
+
if component is not None and _v6_is_jp_glycerin_impurity_record(country, record, material or {}, component or {}):
|
| 4758 |
+
return "nonlegal_impurity"
|
| 4759 |
+
|
| 4760 |
+
if folder_cat in [
|
| 4761 |
+
"legal_prohibited", "legal_restricted", "positive_list", "nonlegal_prop65", "nonlegal_retailer",
|
| 4762 |
+
"nonlegal_impurity", "nonlegal_voluntary", "nonlegal_labeling", "reference", "reference_microplastics",
|
| 4763 |
+
"unknown",
|
| 4764 |
+
]:
|
| 4765 |
+
return folder_cat
|
| 4766 |
+
|
| 4767 |
+
if folder_cat == "legal_mixed":
|
| 4768 |
+
ckey = country_key(country)
|
| 4769 |
+
# ์ผ๋ณธ Standards for Cosmetics: Appendix ๋ฒํธ ๊ธฐ์ค์ผ๋ก๋ง ํ์
|
| 4770 |
+
if ckey == "JAPAN":
|
| 4771 |
+
if _v6_has(basis, ["appendix 1"]):
|
| 4772 |
+
return "legal_prohibited"
|
| 4773 |
+
if _v6_has(basis, ["appendix 2"]):
|
| 4774 |
+
return "legal_restricted"
|
| 4775 |
+
if _v6_has(basis, ["appendix 3", "appendix 4", "tar colors", "preservatives", "uv absorbers", "uv filters"]):
|
| 4776 |
+
return "positive_list"
|
| 4777 |
+
return "reference"
|
| 4778 |
+
# ASEAN ACD Annexes: Annex ๋ฒํธ ๊ธฐ์ค์ผ๋ก๋ง ํ์
|
| 4779 |
+
if ckey == "ASEAN":
|
| 4780 |
+
if _v6_has(basis, ["annex ii", "annex โ
ก"]):
|
| 4781 |
+
return "legal_prohibited"
|
| 4782 |
+
if _v6_has(basis, ["annex iii", "annex โ
ข"]):
|
| 4783 |
+
return "legal_restricted"
|
| 4784 |
+
if _v6_has(basis, ["annex iv", "annex โ
ฃ", "annex vi", "annex โ
ฅ", "annex vii", "annex โ
ฆ"]):
|
| 4785 |
+
return "positive_list"
|
| 4786 |
+
return "reference"
|
| 4787 |
+
# EU ํตํฉ annex ๋ฌธ์๊ฐ ์์ ๊ฒฝ์ฐ๋ Annex ๋ฒํธ ๊ธฐ์ค
|
| 4788 |
+
if ckey == "EU":
|
| 4789 |
+
if _v6_has(basis, ["annex ii", "annex โ
ก"]):
|
| 4790 |
+
return "legal_prohibited"
|
| 4791 |
+
if _v6_has(basis, ["annex iii", "annex โ
ข"]):
|
| 4792 |
+
return "legal_restricted"
|
| 4793 |
+
if _v6_has(basis, ["annex iv", "annex โ
ฃ", "annex v", "annex โ
ค", "annex vi", "annex โ
ฅ"]):
|
| 4794 |
+
return "positive_list"
|
| 4795 |
+
return "reference"
|
| 4796 |
+
return "reference"
|
| 4797 |
+
|
| 4798 |
+
return "unknown"
|
| 4799 |
+
|
| 4800 |
+
|
| 4801 |
+
def _v6_extract_limit_condition_from_row(context):
|
| 4802 |
+
text = safe_str(context)
|
| 4803 |
+
flat = re.sub(r"\s+", " ", text).strip()
|
| 4804 |
+
if not flat:
|
| 4805 |
+
return "", ""
|
| 4806 |
+
|
| 4807 |
+
# ๋ถ์๋ฌผ/์ค์ผ๋ฌผ์ง ppm/ng ๋ฑ์ ๋ฐฐํฉํ๋๋ก ์ฐ์ง ์๋๋ค.
|
| 4808 |
+
if _v6_has(flat, ["impurity", "impurities", "contaminant", "contaminants", "๋ถ์๋ฌผ", "์ค์ผ๋ฌผ์ง", "๊ฒ์ถํ๊ณ", "๊ด๋ฆฌ๊ฐ", "๊ด๋ฆฌ์น", "safe harbor", "exposure"]):
|
| 4809 |
+
if not re.search(r"\b\d+(?:\.\d+)?\s*%", flat):
|
| 4810 |
+
return "", ""
|
| 4811 |
+
|
| 4812 |
+
limits = []
|
| 4813 |
+
# % ํ๋
|
| 4814 |
+
for m in re.finditer(r"\b(\d+(?:\.\d+)?)\s*%", flat):
|
| 4815 |
+
v = m.group(1).rstrip("0").rstrip(".") if "." in m.group(1) else m.group(1)
|
| 4816 |
+
item = f"{v}%"
|
| 4817 |
+
if item not in limits:
|
| 4818 |
+
limits.append(item)
|
| 4819 |
+
# g per 100 g = ์ฌ์ค์ %
|
| 4820 |
+
for m in re.finditer(r"\b(\d+(?:\.\d+)?)\s*g\s*(?:/|per)\s*100\s*g", flat, flags=re.IGNORECASE):
|
| 4821 |
+
v = m.group(1).rstrip("0").rstrip(".") if "." in m.group(1) else m.group(1)
|
| 4822 |
+
item = f"{v}%"
|
| 4823 |
+
if item not in limits:
|
| 4824 |
+
limits.append(item)
|
| 4825 |
+
# '1.0 g' ์ ์ผ๋ณธ ํ๋ Appendix 3/4 row์์ ์ฌ์ฉ๋จ. per 100g heading์ด row์ ์์ ์ ์์ด ์ ํ์ ์ผ๋ก ์ด๋ฆผ.
|
| 4826 |
+
if not limits and _v6_has(flat, ["maximum amount", "maximum concentration", "๋ฐฐํฉํ๋", "์ฌ์ฉํ๋", "ingredient per 100 g", "per 100g"]):
|
| 4827 |
+
for m in re.finditer(r"\b(\d+(?:\.\d+)?)\s*g\b", flat, flags=re.IGNORECASE):
|
| 4828 |
+
v = m.group(1).rstrip("0").rstrip(".") if "." in m.group(1) else m.group(1)
|
| 4829 |
+
item = f"{v}%"
|
| 4830 |
+
if item not in limits:
|
| 4831 |
+
limits.append(item)
|
| 4832 |
+
|
| 4833 |
+
condition_lines = []
|
| 4834 |
+
for line in [safe_str(x) for x in text.splitlines() if safe_str(x)]:
|
| 4835 |
+
if _v6_has(line, ["leave-on", "rinse-off", "washed away", "mucosa", "oral", "์ ๋ง", "๊ตฌ๊ฐ", "์ฌ์ฉ์กฐ๊ฑด", "condition", "warning", "์ฃผ์", "aerosol", "spray"]):
|
| 4836 |
+
if line not in condition_lines:
|
| 4837 |
+
condition_lines.append(line[:220])
|
| 4838 |
+
condition = " / ".join(condition_lines[:3])
|
| 4839 |
+
return "; ".join(limits[:5]), condition
|
| 4840 |
+
|
| 4841 |
+
|
| 4842 |
+
def _v6_result(representative, result_text, formula_text, note, target_id, country, component, source_tag):
|
| 4843 |
+
out = {"๋ํ INCI": representative, "๊ฒฐ๊ณผ": result_text, "ํ์๋ฌธ๊ตฌ": formula_text, "๋น๊ณ ": note}
|
| 4844 |
+
log_search_context(target_id, country, component, out["๊ฒฐ๊ณผ"], source_tag, out["๋น๊ณ "])
|
| 4845 |
+
return out
|
| 4846 |
+
|
| 4847 |
+
|
| 4848 |
+
def _v6_nonlegal_result(country, material, component, record, rtype, target_id=""):
|
| 4849 |
+
representative = safe_str(component.get("INCI Name", "")) or safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", "")) or safe_str(component.get("CAS.No", "")) or "-"
|
| 4850 |
+
cdisp = display_country(country)
|
| 4851 |
+
context = safe_str(record.get("text", ""))
|
| 4852 |
+
src = f"[์ถ์ฒํ์ผ: {record.get('source_file','')}] [row: {record.get('row_index','')}] {context[:900]}"
|
| 4853 |
+
|
| 4854 |
+
if rtype == "nonlegal_prop65":
|
| 4855 |
+
return _v6_result(representative, f"{cdisp}: CA Prop 65 ๊ฒฝ๊ณ ํ์ ๊ฒํ ํ์", "๊ฒฝ๊ณ ํ์ ๊ฒํ ", src, target_id, country, component, "V6_NONLEGAL_PROP65_ONLY")
|
| 4856 |
+
if rtype == "nonlegal_retailer":
|
| 4857 |
+
return _v6_result(representative, f"{cdisp}: ๋ฆฌํ
์ผ๋ฌ Clean ๊ธฐ์ค ํ์ธ", "Clean ๊ธฐ์ค ํ์ธ", src, target_id, country, component, "V6_RETAILER_CLEAN_ONLY")
|
| 4858 |
+
if rtype == "nonlegal_impurity":
|
| 4859 |
+
return _v6_result(representative, f"{cdisp}: ๋ถ์๋ฌผ/์ค์ผ๋ฌผ์ง ๊ธฐ์ค ํ์ธ ํ์", "๋ถ์๋ฌผ/์ค์ผ๋ฌผ์ง ํ์ธ", src, target_id, country, component, "V6_IMPURITY_REFERENCE_ONLY")
|
| 4860 |
+
if rtype == "nonlegal_voluntary":
|
| 4861 |
+
return _v6_result(representative, f"{cdisp}: ์์จ๊ธฐ์ค ํ์ธ", "์์จ๊ธฐ์ค ํ์ธ", src, target_id, country, component, "V6_VOLUNTARY_REFERENCE_ONLY")
|
| 4862 |
+
if rtype == "nonlegal_labeling":
|
| 4863 |
+
return _v6_result(representative, f"{cdisp}: ํ์๊ธฐ์ค ํ์ธ", "ํ์๊ธฐ์ค ํ์ธ", src, target_id, country, component, "V6_LABELING_REFERENCE_ONLY")
|
| 4864 |
+
if rtype == "reference_microplastics":
|
| 4865 |
+
if _v6_is_component_alias(material, component, ["carbomer", "์นด๋ณด๋จธ", "acrylates", "polymer", "ํด๋ฆฌ๋จธ"]):
|
| 4866 |
+
return _v6_result(representative, f"{cdisp}: Microplastics ํด๋น์ฑ ํ์ธ ํ์ / ์ฑ๋ถ๋ช
์์ฒด ๋ฐฐํฉ๊ธ์ง ์๋", NEED_CHECK_TEXT, src, target_id, country, component, "V6_REFERENCE_MICROPLASTICS_NOT_PROHIBITED")
|
| 4867 |
+
return _v6_result(representative, NO_EVIDENCE_TEXT, "Pass", src, target_id, country, component, "V6_REFERENCE_ONLY_NO_LEGAL_CLASSIFICATION")
|
| 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
|
| 4993 |
+
return None
|
| 4994 |
+
|
| 4995 |
+
|
| 4996 |
+
def evaluate_plain_fragrance_rule(country, material, component):
|
| 4997 |
+
if SOURCE_ONLY_MODE:
|
| 4998 |
+
return None
|
| 4999 |
+
return None
|
| 5000 |
+
|
| 5001 |
+
|
| 5002 |
+
def evaluate_local_rules(country, material, component, ingredient_totals, ingredient_amount_parts):
|
| 5003 |
+
if SOURCE_ONLY_MODE:
|
| 5004 |
+
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
|
| 5021 |
+
# ============================================================
|
| 5022 |
+
|
| 5023 |
with gr.Blocks(css=custom_css) as demo:
|
| 5024 |
current_user = gr.State({})
|
| 5025 |
gr.Markdown("# ๐ reBom")
|
|
|
|
| 5118 |
refresh=gr.Button("๐ ํด๋/๊ท์ ํ์ผ ์๋ก๊ณ ์นจ")
|
| 5119 |
product_name=gr.Textbox(label="์ ํ๋ช
/ PRODUCT NAME",placeholder="์: ๋ง๋ฐ์นดํฌ๋ฆผ")
|
| 5120 |
file=gr.File(label="์ ์ฑ๋ถ ํ์ผ ์
๋ก๋",file_types=[".xlsx",".xls",".pdf",".png",".jpg",".jpeg",".webp"])
|
|
|
|
|
|
|
|
|
|
| 5121 |
btn=gr.Button("๐ ๋ถ์ ์์",variant="primary")
|
| 5122 |
df_out=gr.Dataframe(label="๋ฏธ๋ฆฌ๋ณด๊ธฐ - Formula Ingredients Statement",wrap=True,interactive=False)
|
| 5123 |
file_out=gr.File(label="๊ฒฐ๊ณผ ๋ค์ด๋ก๋")
|
|
|
|
| 5128 |
|
| 5129 |
btn.click(
|
| 5130 |
process_with_auth,
|
| 5131 |
+
inputs=[current_user,country,file,product_name],
|
| 5132 |
outputs=[df_out,file_out,msg_out],
|
| 5133 |
)
|
| 5134 |
|
|
|
|
| 5141 |
with gr.Row():
|
| 5142 |
single_amount=gr.Textbox(label="ํจ๋ %(w/w) ์ ํ ์
๋ ฅ",placeholder="์: 7.2")
|
| 5143 |
single_function=gr.Textbox(label="FUNCTION ์ ํ ์
๋ ฅ",placeholder="์: Sunscreen Agent")
|
|
|
|
| 5144 |
single_btn=gr.Button("๐ ๋จ์ผ ์ฑ๋ถ ๊ฒ์ ์์",variant="primary")
|
| 5145 |
single_df_out=gr.Dataframe(label="๋จ์ผ ์ฑ๋ถ ๊ฒ์ ๊ฒฐ๊ณผ",wrap=True,interactive=False)
|
| 5146 |
single_msg_out=gr.Textbox(label="๊ฒ์ ์ํ / ๋ฉ์์ง",interactive=False,lines=8)
|
|
|
|
| 5149 |
|
| 5150 |
single_btn.click(
|
| 5151 |
process_single_ingredient_with_auth,
|
| 5152 |
+
inputs=[current_user,single_country,single_query,single_amount,single_function],
|
| 5153 |
outputs=[single_df_out,single_msg_out],
|
| 5154 |
)
|
| 5155 |
try:
|