jin2li commited on
Commit
f610890
ยท
verified ยท
1 Parent(s): 1efc57c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +406 -20
app.py CHANGED
@@ -1,35 +1,57 @@
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,6 +97,19 @@ REG_INDEX_CACHE_DIR = ".reg_index_cache"
75
  NO_EVIDENCE_TEXT = "ํ•ด๋‹น ์ž๋ฃŒ ๋‚ด ์ œํ•œ ๊ทผ๊ฑฐ ์—†์Œ"
76
  NEED_CHECK_TEXT = "ํ™•์ธ ํ•„์š”"
77
  LIMIT_CHECK_TEXT = "๋ฐฐํ•ฉํ•œ๋„ ํ™•์ธ ํ•„์š”"
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
  # ============================================================
80
  # SOURCE_ONLY_MODE
@@ -3946,6 +3981,357 @@ def process_single_ingredient_with_auth(user, countries, single_query, single_am
3946
  )
3947
 
3948
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3949
  with gr.Blocks(css=custom_css) as demo:
3950
  current_user = gr.State({})
3951
  gr.Markdown("# ๐ŸŒ reBom")
 
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 ์‹ค์‹œ๊ฐ„ ์กฐํšŒ ๋ฐฐ์น˜ ๋น„ํ™œ์„ฑํ™”
28
+ # - ๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰: ์„ ํƒ ์‹œ MFDS ์‹ค์‹œ๊ฐ„ ์กฐํšŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅ
 
 
 
 
 
 
 
 
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
  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
 
3981
  )
3982
 
3983
 
3984
+
3985
+ # ============================================================
3986
+ # SOURCE ONLY STRICT PATCH v3
3987
+ # ๋ชฉ์ :
3988
+ # - ์—…๋กœ๋“œํ•œ ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ์—์„œ ์ง์ ‘ ํ™•์ธ๋œ ๊ทผ๊ฑฐ๋งŒ ์‚ฌ์šฉ
3989
+ # - ํ•˜๋“œ์ฝ”๋”ฉ UV/๋ณด์กด์ œ/๊ธฐ๋Šฅ์„ฑ/ํ–ฅ๋ฃŒ/critical ๊ทœ์น™ ์ž๋™ํŒ์ • ์ฐจ๋‹จ
3990
+ # - ๋งˆ์ง€๋ง‰ ํ‘œ ์ƒ์„ฑ ๋‹จ๊ณ„์—์„œ ์„ฑ๋ถ„๋ช…๋งŒ ๋ณด๊ณ  ํ•œ๋„ ์žฌ์ƒ์„ฑ๋˜๋Š” ๋ฌธ์ œ ์ฐจ๋‹จ
3991
+ # - Positive List๋Š” ํ•œ๋„ ์ˆ˜์น˜๊ฐ€ ๋ช…ํ™•ํ•  ๋•Œ๋งŒ ํ•œ๋„ ํ‘œ์‹œ, ์•„๋‹ˆ๋ฉด Pass
3992
+ # - ๊ธˆ์ง€/์ œํ•œ ๋ฌธ๊ตฌ๊ฐ€ ๋ช…ํ™•ํ•˜์ง€ ์•Š์œผ๋ฉด ๋ฌธ์ œ ์„ฑ๋ถ„์œผ๋กœ ๋งŒ๋“ค์ง€ ์•Š์Œ
3993
+ # ============================================================
3994
+
3995
+ SOURCE_ONLY_MODE = True
3996
+ TREAT_POSITIVE_LIST_AS_PASS = True
3997
+
3998
+ STRICT_PROHIBITED_TERMS = [
3999
+ "๋ฐฐํ•ฉ๊ธˆ์ง€", "์‚ฌ์šฉ๊ธˆ์ง€", "์‚ฌ์šฉ ๊ธˆ์ง€", "๊ธˆ์ง€์›๋ฃŒ", "๊ธˆ์ง€ ์›๋ฃŒ", "๊ธˆ์ง€์„ฑ๋ถ„", "๊ธˆ์ง€ ์„ฑ๋ถ„",
4000
+ "prohibited", "banned", "not allowed", "shall not be used", "must not be used",
4001
+ "shall not contain", "must not contain", "forbidden",
4002
+ ]
4003
+
4004
+ STRICT_RESTRICTED_TERMS = [
4005
+ "๋ฐฐํ•ฉํ•œ๋„", "๋ฐฐํ•ฉ ํ•œ๋„", "์‚ฌ์šฉํ•œ๋„", "์‚ฌ์šฉ ํ•œ๋„", "์‚ฌ์šฉ์ œํ•œ", "์‚ฌ์šฉ ์ œํ•œ",
4006
+ "์ œํ•œ์‚ฌํ•ญ", "์ œํ•œ ์‚ฌํ•ญ", "์ œํ•œ์„ฑ๋ถ„", "์ œํ•œ ์„ฑ๋ถ„",
4007
+ "restricted", "restriction", "maximum concentration", "maximum amount",
4008
+ "max concentration", "not exceeding", "not exceed", "limit",
4009
+ ]
4010
+
4011
+ POSITIVE_LIST_TERMS = [
4012
+ "positive list", "ํ—ˆ์šฉ๋ชฉ๋ก", "ํ—ˆ์šฉ ๋ชฉ๋ก", "annex iv", "annex v", "annex vi",
4013
+ "coloring agents", "colouring agents", "colorants", "preservatives",
4014
+ "uv filters", "sunscreen agents", "์ƒ‰์†Œ", "๋ณด์กด์ œ", "๋ฐฉ๋ถ€์ œ", "์ž์™ธ์„ ", "์ž์™ธ์„ ์ฐจ๋‹จ",
4015
+ ]
4016
+
4017
+ FALSE_LIMIT_CONTEXT_TERMS = [
4018
+ "label", "labelling", "labeling", "๋ผ๋ฒจ", "ํ‘œ์‹œ", "warning", "๊ฒฝ๊ณ ",
4019
+ "allergen", "์•Œ๋ ˆ๋ฅด๊ฒ", "impurity", "impurities", "๋ถˆ์ˆœ๋ฌผ",
4020
+ "test method", "์‹œํ—˜๋ฒ•", "์‹œํ—˜", "analysis", "๋ถ„์„", "purity", "์ˆœ๋„",
4021
+ "๊ฒ€์ถœํ•œ๊ณ„", "๊ด€๋ฆฌ๊ฐ’", "๊ด€๋ฆฌ์น˜", "peroxide value",
4022
+ ]
4023
+
4024
+ def _strict_contains_any(text, terms):
4025
+ text = safe_str(text)
4026
+ low = text.lower()
4027
+ compact = normalize_compact(text)
4028
+ for term in terms:
4029
+ t = safe_str(term)
4030
+ if not t:
4031
+ continue
4032
+ if t.lower() in low:
4033
+ return True
4034
+ if normalize_compact(t) and normalize_compact(t) in compact:
4035
+ return True
4036
+ return False
4037
+
4038
+ def _strict_component_match_in_record(record_text, terms):
4039
+ record_text = safe_str(record_text)
4040
+ if not record_text:
4041
+ return False
4042
+ for term in terms:
4043
+ term = safe_str(term)
4044
+ if not term:
4045
+ continue
4046
+ if len(normalize_compact(term)) < 3:
4047
+ continue
4048
+ if is_broad_lookup_term(term):
4049
+ continue
4050
+ if is_cas_like(term):
4051
+ found_cas = re.findall(r"\d{2,7}-\d{2}-\d", record_text)
4052
+ if normalize_compact(term) in [normalize_compact(x) for x in found_cas]:
4053
+ return True
4054
+ continue
4055
+ if exact_ingredient_match(term, record_text):
4056
+ return True
4057
+ return False
4058
+
4059
+ def _strict_get_record_type(country, record):
4060
+ source_file = safe_str(record.get("source_file", ""))
4061
+ sheet = safe_str(record.get("sheet", ""))
4062
+ text = safe_str(record.get("text", ""))
4063
+ meta = f"{source_file}\n{sheet}"
4064
+ meta_low = meta.lower()
4065
+
4066
+ if (
4067
+ "annex ii" in meta_low or "annex_ii" in meta_low or "annex-ii" in meta_low
4068
+ or "negative list" in meta_low or "prohibited" in meta_low or "๊ธˆ์ง€" in meta
4069
+ ):
4070
+ return "prohibited"
4071
+
4072
+ if (
4073
+ "annex iii" in meta_low or "annex_iii" in meta_low or "annex-iii" in meta_low
4074
+ or "restricted" in meta_low or "restriction" in meta_low
4075
+ or "์ œํ•œ" in meta or "๋ฐฐํ•ฉํ•œ๋„" in meta
4076
+ ):
4077
+ return "restricted"
4078
+
4079
+ if (
4080
+ "annex iv" in meta_low or "annex v" in meta_low or "annex vi" in meta_low
4081
+ or "positive" in meta_low or "colorant" in meta_low or "coloring" in meta_low
4082
+ or "colouring" in meta_low or "preservative" in meta_low
4083
+ or "uv filter" in meta_low or "sunscreen" in meta_low
4084
+ or "์ƒ‰์†Œ" in meta or "๋ณด์กด์ œ" in meta or "๋ฐฉ๋ถ€์ œ" in meta or "์ž์™ธ์„ " in meta
4085
+ ):
4086
+ return "positive"
4087
+
4088
+ if _strict_contains_any(text, STRICT_PROHIBITED_TERMS):
4089
+ return "prohibited"
4090
+ if _strict_contains_any(text, STRICT_RESTRICTED_TERMS):
4091
+ return "restricted"
4092
+ if _strict_contains_any(text, POSITIVE_LIST_TERMS):
4093
+ return "positive"
4094
+ return "unknown"
4095
+
4096
+ def extract_limit_condition_from_context(context):
4097
+ text = safe_str(context)
4098
+ compact = re.sub(r"\s+", " ", text).strip()
4099
+ if not compact:
4100
+ return "", ""
4101
+ if _strict_contains_any(compact, FALSE_LIMIT_CONTEXT_TERMS):
4102
+ return "", ""
4103
+ if not _strict_contains_any(compact, STRICT_RESTRICTED_TERMS):
4104
+ return "", ""
4105
+
4106
+ patterns = [
4107
+ r"([0-9]+(?:\.[0-9]+)?\s*%)",
4108
+ r"([0-9]+(?:\.[0-9]+)?\s*g\s*/\s*100\s*g)",
4109
+ r"([0-9]+(?:\.[0-9]+)?\s*g\s+per\s+100\s*g)",
4110
+ ]
4111
+ limits = []
4112
+ for pat in patterns:
4113
+ for m in re.finditer(pat, compact, flags=re.IGNORECASE):
4114
+ v = m.group(1).replace(" ", "")
4115
+ if v not in limits:
4116
+ limits.append(v)
4117
+
4118
+ condition_keywords = [
4119
+ "leave-on", "rinse-off", "oral", "mucosa", "washed away",
4120
+ "๋ณด์กด์ œ", "๋ฐฉ๋ถ€์ œ", "์ž์™ธ์„ ", "์ƒ‰์†Œ", "์ ๋ง‰", "๊ตฌ๊ฐ•",
4121
+ "์ œํ•œ์‚ฌํ•ญ", "condition", "์‚ฌ์šฉ์กฐ๊ฑด", "์‚ฌ์šฉ ์กฐ๊ฑด",
4122
+ ]
4123
+ condition_lines = []
4124
+ for line in [safe_str(x) for x in text.splitlines() if safe_str(x)]:
4125
+ line_low = line.lower()
4126
+ if any(k.lower() in line_low for k in condition_keywords):
4127
+ cleaned = re.sub(r"\s+", " ", line).strip()
4128
+ if cleaned not in condition_lines:
4129
+ condition_lines.append(cleaned)
4130
+ return ", ".join(limits[:5]), " / ".join(condition_lines[:5])[:700]
4131
+
4132
+ def normalize_formula_country_text(text, country_col="", inci_name="", amount_text=""):
4133
+ text = safe_str(text)
4134
+ if not text:
4135
+ return "Pass"
4136
+ if text in ["-", NO_EVIDENCE_TEXT, "Pass", "PASS", "pass"]:
4137
+ return "Pass"
4138
+ if _strict_contains_any(text, STRICT_PROHIBITED_TERMS):
4139
+ return "๋ฐฐํ•ฉ๊ธˆ์ง€"
4140
+ limit_text, condition_text = extract_limit_condition_from_context(text)
4141
+ if limit_text:
4142
+ return f"๋ฐฐํ•ฉํ•œ๋„: {limit_text}"
4143
+ if _strict_contains_any(text, STRICT_RESTRICTED_TERMS):
4144
+ return NEED_CHECK_TEXT
4145
+ if _strict_contains_any(text, POSITIVE_LIST_TERMS):
4146
+ return "Pass"
4147
+ if NEED_CHECK_TEXT in text or LIMIT_CHECK_TEXT in text:
4148
+ return NEED_CHECK_TEXT
4149
+ if "ํ•จ๋Ÿ‰ ํ™•์ธ" in text:
4150
+ return "ํ•จ๋Ÿ‰ ํ™•์ธ"
4151
+ return "Pass"
4152
+
4153
+ def evaluate_critical_country_rule(country, material, component):
4154
+ if SOURCE_ONLY_MODE:
4155
+ return None
4156
+ return None
4157
+
4158
+ def evaluate_plain_fragrance_rule(country, material, component):
4159
+ if SOURCE_ONLY_MODE:
4160
+ return None
4161
+ return None
4162
+
4163
+ def evaluate_local_rules(country, material, component, ingredient_totals, ingredient_amount_parts):
4164
+ if SOURCE_ONLY_MODE:
4165
+ return None
4166
+ return None
4167
+
4168
+ def evaluate_component_from_uploaded_source_records(country, material, component, target_id=""):
4169
+ terms = source_match_terms_for_component(material, component)
4170
+ representative = (
4171
+ safe_str(component.get("INCI Name", ""))
4172
+ or safe_str(component.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""))
4173
+ or safe_str(component.get("CAS.No", ""))
4174
+ or "-"
4175
+ )
4176
+ if not terms:
4177
+ return None
4178
+
4179
+ records, status = build_country_source_record_index(country)
4180
+ hits = []
4181
+ for rec in records:
4182
+ rec_text = safe_str(rec.get("text", ""))
4183
+ if _strict_component_match_in_record(rec_text, terms):
4184
+ hits.append(rec)
4185
+
4186
+ if not hits:
4187
+ return None
4188
+
4189
+ country_col = display_country(country)
4190
+ prohibited_hits = []
4191
+ restricted_hits = []
4192
+ positive_hits = []
4193
+ unknown_hits = []
4194
+
4195
+ for rec in hits:
4196
+ rec_type = _strict_get_record_type(country, rec)
4197
+ if rec_type == "prohibited":
4198
+ prohibited_hits.append(rec)
4199
+ elif rec_type == "restricted":
4200
+ restricted_hits.append(rec)
4201
+ elif rec_type == "positive":
4202
+ positive_hits.append(rec)
4203
+ else:
4204
+ unknown_hits.append(rec)
4205
+
4206
+ if prohibited_hits:
4207
+ best = prohibited_hits[0]
4208
+ context = safe_str(best.get("text", ""))
4209
+ result = {
4210
+ "๋Œ€ํ‘œ INCI": representative,
4211
+ "๊ฒฐ๊ณผ": f"{country_col} ์—…๋กœ๋“œ ํŒŒ์ผ์—์„œ ๊ธˆ์ง€ ๊ทผ๊ฑฐ ์ง์ ‘ ํ™•์ธ",
4212
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": "๋ฐฐํ•ฉ๊ธˆ์ง€",
4213
+ "๋น„๊ณ ": f"[์ถœ์ฒ˜ํŒŒ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
4214
+ }
4215
+ log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "STRICT_SOURCE_PROHIBITED", result["๋น„๊ณ "])
4216
+ return result
4217
+
4218
+ if restricted_hits:
4219
+ best = restricted_hits[0]
4220
+ context = safe_str(best.get("text", ""))
4221
+ limit_text, condition_text = extract_limit_condition_from_context(context)
4222
+ if limit_text:
4223
+ result = {
4224
+ "๋Œ€ํ‘œ INCI": representative,
4225
+ "๊ฒฐ๊ณผ": f"{country_col} ์—…๋กœ๋“œ ํŒŒ์ผ์—์„œ ์ œํ•œ ๊ทผ๊ฑฐ ์ง์ ‘ ํ™•์ธ / ํ•œ๋„ {limit_text}" + (f" / ์กฐ๊ฑด: {condition_text}" if condition_text else ""),
4226
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": f"๋ฐฐํ•ฉํ•œ๋„: {limit_text}",
4227
+ "๋น„๊ณ ": f"[์ถœ์ฒ˜ํŒŒ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
4228
+ }
4229
+ else:
4230
+ result = {
4231
+ "๋Œ€ํ‘œ INCI": representative,
4232
+ "๊ฒฐ๊ณผ": f"{country_col} ์—…๋กœ๋“œ ํŒŒ์ผ์—์„œ ์ œํ•œ ๊ทผ๊ฑฐ ์ง์ ‘ ํ™•์ธ / ํ•œ๋„ ์ˆ˜์น˜ ํ™•์ธ ํ•„์š”",
4233
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
4234
+ "๋น„๊ณ ": f"[์ถœ์ฒ˜ํŒŒ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
4235
+ }
4236
+ log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "STRICT_SOURCE_RESTRICTED", result["๋น„๊ณ "])
4237
+ return result
4238
+
4239
+ if positive_hits:
4240
+ best = positive_hits[0]
4241
+ context = safe_str(best.get("text", ""))
4242
+ limit_text, condition_text = extract_limit_condition_from_context(context)
4243
+ if limit_text:
4244
+ result = {
4245
+ "๋Œ€ํ‘œ INCI": representative,
4246
+ "๊ฒฐ๊ณผ": f"{country_col} ํ—ˆ์šฉ๋ชฉ๋ก์—์„œ ์„ฑ๋ถ„ ์ง์ ‘ ํ™•์ธ / ํ•œ๋„ {limit_text}" + (f" / ์กฐ๊ฑด: {condition_text}" if condition_text else ""),
4247
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": f"๋ฐฐํ•ฉํ•œ๋„: {limit_text}",
4248
+ "๋น„๊ณ ": f"[์ถœ์ฒ˜ํŒŒ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
4249
+ }
4250
+ log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "STRICT_SOURCE_POSITIVE_LIMIT", result["๋น„๊ณ "])
4251
+ return result
4252
+
4253
+ result = {
4254
+ "๋Œ€ํ‘œ INCI": representative,
4255
+ "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
4256
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
4257
+ "๋น„๊ณ ": f"ํ—ˆ์šฉ๋ชฉ๋ก์—์„œ ์„ฑ๋ถ„๋ช… ํ™•์ธ. ๋ช…ํ™•ํ•œ ๊ธˆ์ง€/์ œํ•œ/ํ•œ๋„ ๊ทผ๊ฑฐ ์—†์Œ. [์ถœ์ฒ˜ํŒŒ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
4258
+ }
4259
+ log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "STRICT_SOURCE_POSITIVE_PASS", result["๋น„๊ณ "])
4260
+ return result
4261
+
4262
+ best = unknown_hits[0] if unknown_hits else hits[0]
4263
+ context = safe_str(best.get("text", ""))
4264
+ result = {
4265
+ "๋Œ€ํ‘œ INCI": representative,
4266
+ "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
4267
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
4268
+ "๋น„๊ณ ": f"์„ฑ๋ถ„๋ช…์€ ์—…๋กœ๋“œ ํŒŒ์ผ์—์„œ ๋ฐœ๊ฒฌ๋˜์—ˆ์œผ๋‚˜ ๊ธˆ์ง€/์ œํ•œ/ํ•œ๋„ ๊ทผ๊ฑฐ ์—†์Œ. [์ถœ์ฒ˜ํŒŒ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
4269
+ }
4270
+ log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "STRICT_SOURCE_NAME_ONLY_PASS", result["๋น„๊ณ "])
4271
+ return result
4272
+
4273
+ def evaluate_component_from_country_files_only(country, material, component, target_id=""):
4274
+ country_col = display_country(country)
4275
+ inci_name = safe_str(component.get("INCI Name", ""))
4276
+ korean_name = safe_str(component.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""))
4277
+ cas_no = safe_str(component.get("CAS.No", ""))
4278
+ representative = inci_name or korean_name or cas_no or "-"
4279
+
4280
+ if is_always_pass_component(material, component):
4281
+ result = {
4282
+ "๋Œ€ํ‘œ INCI": representative if representative != "-" else "Water",
4283
+ "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
4284
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
4285
+ "๋น„๊ณ ": "์ •์ œ์ˆ˜/Water/Aqua ๊ธฐ๋ณธ Pass ์ฒ˜๋ฆฌ",
4286
+ }
4287
+ log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "ALWAYS_PASS_RULE", result["๋น„๊ณ "])
4288
+ return result
4289
+
4290
+ source_result = evaluate_component_from_uploaded_source_records(
4291
+ country=country,
4292
+ material=material,
4293
+ component=component,
4294
+ target_id=target_id,
4295
+ )
4296
+ if source_result is not None:
4297
+ return source_result
4298
+
4299
+ result = {
4300
+ "๋Œ€ํ‘œ INCI": representative,
4301
+ "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
4302
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
4303
+ "๋น„๊ณ ": "์—…๋กœ๋“œ๋œ ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ ๋‚ด ํ˜„์žฌ ์„ฑ๋ถ„ ์ง์ ‘ ๊ทผ๊ฑฐ ์—†์Œ",
4304
+ }
4305
+ log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "STRICT_SOURCE_NO_HIT_PASS", result["๋น„๊ณ "])
4306
+ return result
4307
+
4308
+ def is_country_result_issue(text):
4309
+ text = safe_str(text)
4310
+ if not text:
4311
+ return False
4312
+ if text in ["-", NO_EVIDENCE_TEXT, "Pass", "PASS", "pass"]:
4313
+ return False
4314
+ if "ํ—ˆ์šฉ๋ชฉ๋ก" in text and not _strict_contains_any(text, STRICT_RESTRICTED_TERMS + STRICT_PROHIBITED_TERMS):
4315
+ return False
4316
+ if _strict_contains_any(text, STRICT_PROHIBITED_TERMS):
4317
+ return True
4318
+ if NEED_CHECK_TEXT in text:
4319
+ return True
4320
+ if LIMIT_CHECK_TEXT in text:
4321
+ return True
4322
+ if "ํ•œ๋„ ์ดˆ๊ณผ" in text:
4323
+ return True
4324
+ if "๋ถ€์ ํ•ฉ" in text or "์žฌ๊ฒ€ํ† " in text or "์‚ฌ์šฉ ๋ถˆ๊ฐ€" in text or "์‚ฌ์šฉ๋ถˆ๊ฐ€" in text:
4325
+ return True
4326
+ if _strict_contains_any(text, STRICT_RESTRICTED_TERMS):
4327
+ return True
4328
+ return False
4329
+
4330
+ # ============================================================
4331
+ # END SOURCE ONLY STRICT PATCH v3
4332
+ # ============================================================
4333
+
4334
+
4335
  with gr.Blocks(css=custom_css) as demo:
4336
  current_user = gr.State({})
4337
  gr.Markdown("# ๐ŸŒ reBom")