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

Update app.py

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