jin2li commited on
Commit
4726139
ยท
verified ยท
1 Parent(s): 5cdb3e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +702 -14
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","FDA","JAPAN","KOREA","MEXICO","SEPHORA","TARGET","UK","ULTA"]
97
- COUNTRY_DISPLAY = {"EU":"EU","์œ ๋Ÿฝ":"EU","FDA":"FDA","๋ฏธ๊ตญ":"FDA","USA":"FDA","US":"FDA","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":"FDA","๋ฏธ๊ตญ":"FDA","USA":"FDA","US":"FDA","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,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":"FDA","US":"FDA","๋ฏธ๊ตญ":"FDA","FDA":"FDA","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,7 +1574,7 @@ def country_aliases_for_mfds(country):
1574
  alias_map = {
1575
  "ASEAN": ["์•„์„ธ์•ˆ", "ASEAN"],
1576
  "EU": ["์œ ๋Ÿฝ", "EU", "์œ ๋Ÿฝ์—ฐํ•ฉ", "European Union", "Europe"],
1577
- "FDA": ["๋ฏธ๊ตญ", "USA", "US", "United States", "FDA"],
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
- ("FDA", ["๋ฏธ๊ตญ", "USA", "United States", "FDA"]),
1610
  ("Korea", ["ํ•œ๊ตญ", "๋Œ€ํ•œ๋ฏผ๊ตญ", "Korea"]),
1611
  ("์ผ๋ณธ", ["์ผ๋ณธ", "Japan"]),
1612
  ("์ค‘๊ตญ", ["์ค‘๊ตญ", "China"]),
@@ -3983,7 +3983,48 @@ def _v51_folder_category(country, record):
3983
  return "unknown"
3984
 
3985
 
3986
- def _v51_record_type(country, record):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3987
  category = _v51_folder_category(country, record)
3988
  text = safe_str(record.get("text", ""))
3989
  path_text = _v51_path_text(record)
@@ -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,use_mfds_live,live_max_terms,live_headless],
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,single_use_mfds_live],
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: