jin2li commited on
Commit
be79381
ยท
verified ยท
1 Parent(s): 2a90dae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -83
app.py CHANGED
@@ -373,7 +373,7 @@ def refresh_country_choices_keep_selection(current_values=None):
373
  return gr.update(choices=choices,value=kept)
374
 
375
  def refresh_country_choices_and_clear_cache(current_values=None):
376
- VECTOR_DB_CACHE.clear(); EVAL_CACHE.clear(); return refresh_country_choices_keep_selection(current_values)
377
 
378
  def get_regulatory_file_list(folder):
379
  files=[]
@@ -771,6 +771,7 @@ def build_single_component_from_query(query, amount="", function="", single_amou
771
 
772
 
773
 
 
774
  def get_country_regulatory_text_cached(country):
775
  """
776
  ๊ตญ๊ฐ€๋ณ„ ๊ทœ์ œ ํŒŒ์ผ ์›๋ฌธ์„ ์ง์ ‘ ์ฝ์–ด์„œ ์บ์‹œํ•œ๋‹ค.
@@ -818,28 +819,26 @@ def get_country_regulatory_text_cached(country):
818
  return combined, "READ_FILES"
819
 
820
 
821
- def infer_regulation_type_from_source_text(source_text):
822
  """
823
  ํŒŒ์ผ๋ช…/์‹œํŠธ๋ช…/๋ฌธ์„œ ์ œ๋ชฉ ๊ธฐ์ค€์œผ๋กœ ๊ทœ์ œ ์œ ํ˜•์„ ํŒ๋‹จํ•œ๋‹ค.
824
 
825
- EU / ASEAN ๊ณตํ†ต:
826
- - Annex II = Negative List / Prohibited Substances / ์‚ฌ์šฉ ๊ธˆ์ง€
827
- - Annex III = Negative List / Restricted Substances / ์ œํ•œ ์„ฑ๋ถ„
828
- - Annex IV = Positive List / Coloring Agents / ํ—ˆ์šฉ ์ƒ‰์†Œ
829
- - Annex V = Positive List / Preservatives / ํ—ˆ์šฉ ๋ณด์กด์ œ
830
- - Annex VI = Positive List / UV Filters / ํ—ˆ์šฉ ์ž์™ธ์„ ์ฐจ๋‹จ์ œ
831
-
832
- ํ•ต์‹ฌ:
833
- Annex II ์•ˆ์—์„œ ์„ฑ๋ถ„์ด ๋ฐœ๊ฒฌ๋˜๋ฉด ์ฃผ๋ณ€ ํ–‰์— '๊ธˆ์ง€'๋ผ๋Š” ๋‹จ์–ด๊ฐ€ ์—†์–ด๋„ ๋ฐฐํ•ฉ๊ธˆ์ง€๋กœ ํŒ์ •ํ•œ๋‹ค.
834
  """
835
  text = safe_str(source_text)
836
  low = text.lower()
837
  compact = normalize_compact(text)
 
838
 
839
  def has_any(patterns):
840
  return any(p in low or normalize_compact(p) in compact for p in patterns)
841
 
842
- # Annex II / Prohibited / Negative List
 
 
843
  if has_any([
844
  "annex ii",
845
  "annex 2",
@@ -848,20 +847,27 @@ def infer_regulation_type_from_source_text(source_text):
848
  "prohibited substances",
849
  "list of substances prohibited",
850
  "negative list",
851
- "์‚ฌ์šฉ ๊ธˆ์ง€",
852
- "์‚ฌ์šฉ๊ธˆ์ง€",
853
- "๊ธˆ์ง€ ์„ฑ๋ถ„",
854
- "๊ธˆ์ง€์„ฑ๋ถ„",
 
855
  "๊ธˆ์ง€์›๋ฃŒ",
 
 
 
856
  "๋ฐฐํ•ฉ๊ธˆ์ง€",
 
 
857
  ]):
 
858
  return {
859
  "type": "prohibited",
860
- "label": "Annex II / Negative List / Prohibited Substances",
861
  "display": "๋ฐฐํ•ฉ๊ธˆ์ง€",
862
  }
863
 
864
- # Annex III / Restricted / Negative List
865
  if has_any([
866
  "annex iii",
867
  "annex 3",
@@ -871,20 +877,27 @@ def infer_regulation_type_from_source_text(source_text):
871
  "list of substances which cosmetic products must not contain except subject to the restrictions",
872
  "restriction",
873
  "restricted",
 
 
 
 
 
874
  "์‚ฌ์šฉ ์ œํ•œ",
875
  "์‚ฌ์šฉ์ œํ•œ",
876
- "์ œํ•œ ์„ฑ๋ถ„",
877
  "์ œํ•œ์„ฑ๋ถ„",
 
878
  "๋ฐฐํ•ฉํ•œ๋„",
879
  ]):
 
880
  return {
881
  "type": "restricted",
882
- "label": "Annex III / Negative List / Restricted Substances",
883
  "display": NEED_CHECK_TEXT,
884
  }
885
 
886
- # Annex IV / Colorants / Positive List
887
- if has_any([
888
  "annex iv",
889
  "annex 4",
890
  "annex_iv",
@@ -901,8 +914,7 @@ def infer_regulation_type_from_source_text(source_text):
901
  "display": "ํ—ˆ์šฉ๋ชฉ๋ก ๋“ฑ์žฌ",
902
  }
903
 
904
- # Annex V / Preservatives / Positive List
905
- if has_any([
906
  "annex v",
907
  "annex 5",
908
  "annex_v",
@@ -918,8 +930,7 @@ def infer_regulation_type_from_source_text(source_text):
918
  "display": "ํ—ˆ์šฉ๋ชฉ๋ก ๋“ฑ์žฌ",
919
  }
920
 
921
- # Annex VI / UV Filters / Positive List
922
- if has_any([
923
  "annex vi",
924
  "annex 6",
925
  "annex_vi",
@@ -937,6 +948,28 @@ def infer_regulation_type_from_source_text(source_text):
937
  "display": "ํ—ˆ์šฉ๋ชฉ๋ก ๋“ฑ์žฌ",
938
  }
939
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
940
  return {
941
  "type": "unknown",
942
  "label": "๊ทœ์ œ ์œ ํ˜• ๋ฏธ๋ถ„๋ฅ˜",
@@ -947,7 +980,6 @@ def infer_regulation_type_from_source_text(source_text):
947
  def split_regulatory_text_into_sections(raw_text):
948
  """
949
  get_country_regulatory_text_cached()์—์„œ ๋งŒ๋“  ํ…์ŠคํŠธ๋ฅผ ํŒŒ์ผ/์‹œํŠธ/ํŽ˜์ด์ง€ ๋‹จ์œ„ ์„น์…˜์œผ๋กœ ๋‚˜๋ˆˆ๋‹ค.
950
- ๊ฐ ์„น์…˜ ์•ž๋ถ€๋ถ„์—๋Š” [์ถœ์ฒ˜ํŒŒ์ผ: ...] ์ •๋ณด๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์œผ๋ฏ€๋กœ, ํ•ด๋‹น ํŒŒ์ผ์ด Annex II์ธ์ง€ III์ธ์ง€ ํŒ๋‹จํ•  ์ˆ˜ ์žˆ๋‹ค.
951
  """
952
  raw_text = safe_str(raw_text)
953
 
@@ -973,20 +1005,11 @@ def split_regulatory_text_into_sections(raw_text):
973
  return sections
974
 
975
 
976
-
977
  def get_country_section_index_cached(country):
978
  """
979
  ๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰ ๊ณ ์†ํ™”์šฉ ์„น์…˜ ์ธ๋ฑ์Šค.
980
  ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ์„ ๋งค๋ฒˆ PDF/Excel ์ „์ฒด ์ฝ๊ธฐํ•˜์ง€ ์•Š๊ณ ,
981
  ํŒŒ์ผ/์‹œํŠธ/ํŽ˜์ด์ง€ ์„น์…˜ ๋‹จ์œ„๋กœ ์บ์‹œํ•œ๋‹ค.
982
-
983
- ์ตœ์ดˆ 1ํšŒ:
984
- - ํ•ด๋‹น ๊ตญ๊ฐ€ ํŒŒ์ผ์„ ์ฝ์–ด ์„น์…˜ ์ธ๋ฑ์Šค ์ƒ์„ฑ
985
- - .reg_index_cache ํด๋”์— json ์ €์žฅ
986
-
987
- ์ดํ›„:
988
- - ํŒŒ์ผ ๋ณ€๊ฒฝ์ด ์—†์œผ๋ฉด json ์บ์‹œ๋ฅผ ๋ฐ”๋กœ ๋กœ๋“œ
989
- - ๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰์€ ๋ฌธ์ž์—ด contains๋งŒ ์ˆ˜ํ–‰ํ•˜๋ฏ€๋กœ ๋งค์šฐ ๋น ๋ฆ„
990
  """
991
  global REG_SECTION_INDEX_CACHE
992
 
@@ -1036,13 +1059,9 @@ def get_country_section_index_cached(country):
1036
 
1037
  rel = item.get("relative_path", "")
1038
  ext = item.get("ext", "")
1039
-
1040
- # ํŒŒ์ผ๋ช…/๊ฒฝ๋กœ ์ž์ฒด๋กœ Annex II/III/IV/V/VI๋ฅผ ํŒ๋‹จํ•  ์ˆ˜ ์žˆ๋„๋ก header์— ๋ช…ํ™•ํžˆ ๋„ฃ๋Š”๋‹ค.
1041
  source_header = f"[๊ตญ๊ฐ€/์ฑ„๋„: {folder}] [์ถœ์ฒ˜ํŒŒ์ผ: {rel}] [ํ™•์žฅ์ž: {ext}]"
1042
- reg_type = infer_regulation_type_from_source_text(source_header + "\n" + raw[:1500])
1043
 
1044
- # ๋„ˆ๋ฌด ํฐ ํŒŒ์ผ๋„ ์ค„ ๋‹จ์œ„ ๊ฒ€์ƒ‰๋งŒ ํ•˜๋„๋ก ์„น์…˜ 1๊ฐœ๋กœ ์ €์žฅํ•œ๋‹ค.
1045
- # ๊ฒ€์ƒ‰ ์‹œ matching line ์ฃผ๋ณ€๋งŒ ์ž˜๋ผ ์“ฐ๋ฏ€๋กœ ์ „์ฒด ํ…์ŠคํŠธ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์–ด๋„ ๋น ๋ฅด๋‹ค.
1046
  sections.append({
1047
  "folder": folder,
1048
  "source_file": rel,
@@ -1079,7 +1098,6 @@ def find_matching_regulatory_sections_fast(country, ingredient_names, max_sectio
1079
  """
1080
  ๊ณ ์† ๋‹จ์ผ ๊ฒ€์ƒ‰.
1081
  get_country_section_index_cached()๊ฐ€ ๋งŒ๋“  ์„น์…˜ ์ธ๋ฑ์Šค์—์„œ ์„ฑ๋ถ„๋ช…/INCI/CAS๋ฅผ ์ง์ ‘ ๊ฒ€์ƒ‰ํ•œ๋‹ค.
1082
- PDF/Excel ์žฌ์ฝ๊ธฐ์™€ FAISS/์ž„๋ฒ ๋”ฉ์„ ํ•˜์ง€ ์•Š๋Š”๋‹ค.
1083
  """
1084
  sections, status = get_country_section_index_cached(country)
1085
 
@@ -1134,14 +1152,16 @@ def find_matching_regulatory_sections_fast(country, ingredient_names, max_sectio
1134
  else:
1135
  context = header + "\n" + text[:2000]
1136
 
 
 
 
 
 
 
1137
  matches.append({
1138
  "header": header,
1139
  "context": context[:8000],
1140
- "regulation_type": section.get("regulation_type", {
1141
- "type": "unknown",
1142
- "label": "๊ทœ์ œ ์œ ํ˜• ๋ฏธ๋ถ„๋ฅ˜",
1143
- "display": NEED_CHECK_TEXT,
1144
- }),
1145
  })
1146
 
1147
  if len(matches) >= max_sections:
@@ -1150,28 +1170,9 @@ def find_matching_regulatory_sections_fast(country, ingredient_names, max_sectio
1150
  return matches, status
1151
 
1152
 
1153
- def warmup_country_indexes(countries):
1154
- """
1155
- ์„ ํƒ ๊ตญ๊ฐ€์˜ ๋‹จ์ผ ๊ฒ€์ƒ‰ ์ธ๋ฑ์Šค๋ฅผ ๋ฏธ๋ฆฌ ๋งŒ๋“ ๋‹ค.
1156
- ์‚ฌ์šฉ์ž๊ฐ€ '๊ตญ๊ฐ€/๊ทœ์ œํŒŒ์ผ ์ƒˆ๋กœ๊ณ ์นจ'์„ ๋ˆŒ๋ €์„ ๋•Œ ์บ์‹œ๊นŒ์ง€ ๊ฐ™์ด ์ค€๋น„ํ•  ์ˆ˜ ์žˆ๋‹ค.
1157
- """
1158
- messages = []
1159
-
1160
- for country in countries or []:
1161
- try:
1162
- sections, status = get_country_section_index_cached(country)
1163
- messages.append(f"{display_country(country)}: {status}, sections={len(sections)}")
1164
- except Exception as e:
1165
- messages.append(f"{display_country(country)}: ์ธ๋ฑ์Šค ์ƒ์„ฑ ์‹คํŒจ - {e}")
1166
-
1167
- return "\n".join(messages) if messages else "์„ ํƒ๋œ ๊ตญ๊ฐ€ ์—†์Œ"
1168
-
1169
-
1170
-
1171
  def find_matching_regulatory_sections(raw_text, ingredient_names, max_sections=20):
1172
  """
1173
- ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ ์›๋ฌธ์—์„œ ํ˜„์žฌ ์„ฑ๋ถ„๋ช…/INCI/CAS๊ฐ€ ์ง์ ‘ ํฌํ•จ๋œ ์„น์…˜์„ ์ฐพ๋Š”๋‹ค.
1174
- ๊ธฐ์กด line-window ๋ฐฉ์‹์ด ์•„๋‹ˆ๋ผ ์„น์…˜ ์ „์ฒด์˜ ํŒŒ์ผ๋ช…/์‹œํŠธ๋ช…๊นŒ์ง€ ๊ฐ™์ด ๋ณด์กดํ•œ๋‹ค.
1175
  """
1176
  names_norm = [
1177
  normalize_compact(x)
@@ -1189,7 +1190,6 @@ def find_matching_regulatory_sections(raw_text, ingredient_names, max_sections=2
1189
  text_norm = normalize_compact(text)
1190
 
1191
  if any(name in text_norm for name in names_norm):
1192
- # ์„ฑ๋ถ„์ด ์žˆ๋Š” ์ค„ ์ฃผ๋ณ€๋„ ๊ฐ™์ด ์ถ”์ถœ
1193
  lines = [safe_str(x) for x in text.splitlines() if safe_str(x)]
1194
  hit_indices = []
1195
 
@@ -1214,7 +1214,7 @@ def find_matching_regulatory_sections(raw_text, ingredient_names, max_sections=2
1214
  context_lines.append(lines[j])
1215
 
1216
  context = section["header"] + "\n" + "\n".join(context_lines)
1217
- reg_type = infer_regulation_type_from_source_text(section["header"] + "\n" + text[:1200])
1218
 
1219
  matches.append({
1220
  "header": section["header"],
@@ -1254,24 +1254,20 @@ def pick_best_regulatory_match(matches):
1254
  return matches[0]
1255
 
1256
 
1257
- def extract_relevant_context_direct(raw_text, ingredient_names, window=2, max_blocks=12):
1258
  """
1259
- ๊ตฌ๋ฒ„์ „ ํ˜ธํ™˜์šฉ ํ•จ์ˆ˜.
1260
- ์‹ค์ œ ํŒ์ •์€ find_matching_regulatory_sections()๋ฅผ ์šฐ์„  ์‚ฌ์šฉํ•œ๋‹ค.
1261
  """
1262
- raw_text = safe_str(raw_text)
1263
-
1264
- if not raw_text:
1265
- return "", False
1266
-
1267
- matches = find_matching_regulatory_sections(raw_text, ingredient_names, max_sections=max_blocks)
1268
-
1269
- if not matches:
1270
- return "", False
1271
 
1272
- context = "\n\n".join([m["context"] for m in matches[:max_blocks]])
 
 
 
 
 
1273
 
1274
- return context[:8000], True
1275
 
1276
 
1277
 
 
373
  return gr.update(choices=choices,value=kept)
374
 
375
  def refresh_country_choices_and_clear_cache(current_values=None):
376
+ VECTOR_DB_CACHE.clear(); EVAL_CACHE.clear(); REG_TEXT_CACHE.clear(); REG_SECTION_INDEX_CACHE.clear(); return refresh_country_choices_keep_selection(current_values)
377
 
378
  def get_regulatory_file_list(folder):
379
  files=[]
 
771
 
772
 
773
 
774
+
775
  def get_country_regulatory_text_cached(country):
776
  """
777
  ๊ตญ๊ฐ€๋ณ„ ๊ทœ์ œ ํŒŒ์ผ ์›๋ฌธ์„ ์ง์ ‘ ์ฝ์–ด์„œ ์บ์‹œํ•œ๋‹ค.
 
819
  return combined, "READ_FILES"
820
 
821
 
822
+ def infer_regulation_type_from_source_text(source_text, country=""):
823
  """
824
  ํŒŒ์ผ๋ช…/์‹œํŠธ๋ช…/๋ฌธ์„œ ์ œ๋ชฉ ๊ธฐ์ค€์œผ๋กœ ๊ทœ์ œ ์œ ํ˜•์„ ํŒ๋‹จํ•œ๋‹ค.
825
 
826
+ ์ค‘์š”:
827
+ - Annex II/III/IV/V/VI ๋ช…์นญ์€ EU์™€ ASEAN์—๋งŒ ์‚ฌ์šฉํ•œ๋‹ค.
828
+ - KOREA/FDA/JAPAN/CHINA ๋“ฑ์€ Annex๋ผ๊ณ  ํ‘œ์‹œํ•˜์ง€ ์•Š๊ณ 
829
+ '๊ตญ๊ฐ€๋ณ„ ๊ธˆ์ง€์„ฑ๋ถ„ ๋ชฉ๋ก', '๊ตญ๊ฐ€๋ณ„ ์ œํ•œ์„ฑ๋ถ„ ๋ชฉ๋ก'์ฒ˜๋Ÿผ ํ‘œ์‹œํ•œ๋‹ค.
 
 
 
 
 
830
  """
831
  text = safe_str(source_text)
832
  low = text.lower()
833
  compact = normalize_compact(text)
834
+ ckey = country_key(country)
835
 
836
  def has_any(patterns):
837
  return any(p in low or normalize_compact(p) in compact for p in patterns)
838
 
839
+ is_eu_or_asean = ckey in ["EU", "ASEAN", "EU_FUTURE"]
840
+
841
+ # 1) ๊ธˆ์ง€ ๋ชฉ๋ก
842
  if has_any([
843
  "annex ii",
844
  "annex 2",
 
847
  "prohibited substances",
848
  "list of substances prohibited",
849
  "negative list",
850
+ "์‚ฌ์šฉ๊ธˆ์ง€์›๋ฃŒ",
851
+ "์‚ฌ์šฉ๊ธˆ์ง€ ์›๋ฃŒ",
852
+ "์‚ฌ์šฉ ๊ธˆ์ง€ ์›๋ฃŒ",
853
+ "์‚ฌ์šฉ๊ธˆ์ง€์„ฑ๋ถ„",
854
+ "์‚ฌ์šฉ ๊ธˆ์ง€ ์„ฑ๋ถ„",
855
  "๊ธˆ์ง€์›๋ฃŒ",
856
+ "๊ธˆ์ง€ ์›๋ฃŒ",
857
+ "๊ธˆ์ง€์„ฑ๋ถ„",
858
+ "๊ธˆ์ง€ ์„ฑ๋ถ„",
859
  "๋ฐฐํ•ฉ๊ธˆ์ง€",
860
+ "์‚ฌ์šฉ๊ธˆ์ง€",
861
+ "์‚ฌ์šฉ ๊ธˆ์ง€",
862
  ]):
863
+ label = "Annex II / Negative List / Prohibited Substances" if is_eu_or_asean else "๊ตญ๊ฐ€๋ณ„ ๊ธˆ์ง€์„ฑ๋ถ„ ๋ชฉ๋ก / Prohibited Substances"
864
  return {
865
  "type": "prohibited",
866
+ "label": label,
867
  "display": "๋ฐฐํ•ฉ๊ธˆ์ง€",
868
  }
869
 
870
+ # 2) ์ œํ•œ ๋ชฉ๋ก
871
  if has_any([
872
  "annex iii",
873
  "annex 3",
 
877
  "list of substances which cosmetic products must not contain except subject to the restrictions",
878
  "restriction",
879
  "restricted",
880
+ "์‚ฌ์šฉ์ œํ•œ์›๋ฃŒ",
881
+ "์‚ฌ์šฉ์ œํ•œ ์›๋ฃŒ",
882
+ "์‚ฌ์šฉ ์ œํ•œ ์›๋ฃŒ",
883
+ "์‚ฌ์šฉ์ œํ•œ์„ฑ๋ถ„",
884
+ "์‚ฌ์šฉ ์ œํ•œ ์„ฑ๋ถ„",
885
  "์‚ฌ์šฉ ์ œํ•œ",
886
  "์‚ฌ์šฉ์ œํ•œ",
887
+ "์ œํ•œ ์›๋ฃŒ",
888
  "์ œํ•œ์„ฑ๋ถ„",
889
+ "์ œํ•œ ์„ฑ๋ถ„",
890
  "๋ฐฐํ•ฉํ•œ๋„",
891
  ]):
892
+ label = "Annex III / Negative List / Restricted Substances" if is_eu_or_asean else "๊ตญ๊ฐ€๋ณ„ ์ œํ•œ์„ฑ๋ถ„ ๋ชฉ๋ก / Restricted Substances"
893
  return {
894
  "type": "restricted",
895
+ "label": label,
896
  "display": NEED_CHECK_TEXT,
897
  }
898
 
899
+ # 3) EU/ASEAN Positive Lists๋งŒ Annex IV/V/VI๋กœ ํ‘œ์‹œ
900
+ if is_eu_or_asean and has_any([
901
  "annex iv",
902
  "annex 4",
903
  "annex_iv",
 
914
  "display": "ํ—ˆ์šฉ๋ชฉ๋ก ๋“ฑ์žฌ",
915
  }
916
 
917
+ if is_eu_or_asean and has_any([
 
918
  "annex v",
919
  "annex 5",
920
  "annex_v",
 
930
  "display": "ํ—ˆ์šฉ๋ชฉ๋ก ๋“ฑ์žฌ",
931
  }
932
 
933
+ if is_eu_or_asean and has_any([
 
934
  "annex vi",
935
  "annex 6",
936
  "annex_vi",
 
948
  "display": "ํ—ˆ์šฉ๋ชฉ๋ก ๋“ฑ์žฌ",
949
  }
950
 
951
+ # 4) EU/ASEAN ์™ธ ๊ตญ๊ฐ€์˜ Positive List ๊ณ„์—ด์€ Annex ํ‘œ์‹œ ์—†์ด ์ผ๋ฐ˜ ํ‘œ์‹œ
952
+ if has_any(["์ƒ‰์†Œ", "coloring agents", "colouring agents", "colorants", "colorant"]):
953
+ return {
954
+ "type": "positive_colorant",
955
+ "label": "๊ตญ๊ฐ€๋ณ„ ํ—ˆ์šฉ ์ƒ‰์†Œ ๋ชฉ๋ก / Coloring Agents",
956
+ "display": "ํ—ˆ์šฉ๋ชฉ๋ก ๋“ฑ์žฌ",
957
+ }
958
+
959
+ if has_any(["๋ณด์กด์ œ", "๋ฐฉ๋ถ€์ œ", "preservatives", "preservative"]):
960
+ return {
961
+ "type": "positive_preservative",
962
+ "label": "๊ตญ๊ฐ€๋ณ„ ํ—ˆ์šฉ ๋ณด์กด์ œ ๋ชฉ๋ก / Preservatives",
963
+ "display": "ํ—ˆ์šฉ๋ชฉ๋ก ๋“ฑ์žฌ",
964
+ }
965
+
966
+ if has_any(["์ž์™ธ์„ ", "์ž์™ธ์„ ์ฐจ๋‹จ", "uv filters", "uv filter", "ultraviolet filters", "sunscreen agents"]):
967
+ return {
968
+ "type": "positive_uv",
969
+ "label": "๊ตญ๊ฐ€๋ณ„ ํ—ˆ์šฉ ์ž์™ธ์„ ์ฐจ๋‹จ์ œ ๋ชฉ๋ก / UV Filters",
970
+ "display": "ํ—ˆ์šฉ๋ชฉ๋ก ๋“ฑ์žฌ",
971
+ }
972
+
973
  return {
974
  "type": "unknown",
975
  "label": "๊ทœ์ œ ์œ ํ˜• ๋ฏธ๋ถ„๋ฅ˜",
 
980
  def split_regulatory_text_into_sections(raw_text):
981
  """
982
  get_country_regulatory_text_cached()์—์„œ ๋งŒ๋“  ํ…์ŠคํŠธ๋ฅผ ํŒŒ์ผ/์‹œํŠธ/ํŽ˜์ด์ง€ ๋‹จ์œ„ ์„น์…˜์œผ๋กœ ๋‚˜๋ˆˆ๋‹ค.
 
983
  """
984
  raw_text = safe_str(raw_text)
985
 
 
1005
  return sections
1006
 
1007
 
 
1008
  def get_country_section_index_cached(country):
1009
  """
1010
  ๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰ ๊ณ ์†ํ™”์šฉ ์„น์…˜ ์ธ๋ฑ์Šค.
1011
  ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ์„ ๋งค๋ฒˆ PDF/Excel ์ „์ฒด ์ฝ๊ธฐํ•˜์ง€ ์•Š๊ณ ,
1012
  ํŒŒ์ผ/์‹œํŠธ/ํŽ˜์ด์ง€ ์„น์…˜ ๋‹จ์œ„๋กœ ์บ์‹œํ•œ๋‹ค.
 
 
 
 
 
 
 
 
1013
  """
1014
  global REG_SECTION_INDEX_CACHE
1015
 
 
1059
 
1060
  rel = item.get("relative_path", "")
1061
  ext = item.get("ext", "")
 
 
1062
  source_header = f"[๊ตญ๊ฐ€/์ฑ„๋„: {folder}] [์ถœ์ฒ˜ํŒŒ์ผ: {rel}] [ํ™•์žฅ์ž: {ext}]"
1063
+ reg_type = infer_regulation_type_from_source_text(source_header + "\n" + raw[:1500], country=country)
1064
 
 
 
1065
  sections.append({
1066
  "folder": folder,
1067
  "source_file": rel,
 
1098
  """
1099
  ๊ณ ์† ๋‹จ์ผ ๊ฒ€์ƒ‰.
1100
  get_country_section_index_cached()๊ฐ€ ๋งŒ๋“  ์„น์…˜ ์ธ๋ฑ์Šค์—์„œ ์„ฑ๋ถ„๋ช…/INCI/CAS๋ฅผ ์ง์ ‘ ๊ฒ€์ƒ‰ํ•œ๋‹ค.
 
1101
  """
1102
  sections, status = get_country_section_index_cached(country)
1103
 
 
1152
  else:
1153
  context = header + "\n" + text[:2000]
1154
 
1155
+ # ๋””์Šคํฌ ์บ์‹œ๊ฐ€ ์˜ค๋ž˜๋œ label์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ header ๊ธฐ์ค€์œผ๋กœ ํ•œ๋ฒˆ ๋” ๋ณด์ •
1156
+ reg_type = infer_regulation_type_from_source_text(
1157
+ header + "\n" + text[:1500],
1158
+ country=country,
1159
+ )
1160
+
1161
  matches.append({
1162
  "header": header,
1163
  "context": context[:8000],
1164
+ "regulation_type": reg_type,
 
 
 
 
1165
  })
1166
 
1167
  if len(matches) >= max_sections:
 
1170
  return matches, status
1171
 
1172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1173
  def find_matching_regulatory_sections(raw_text, ingredient_names, max_sections=20):
1174
  """
1175
+ ๊ตฌ๋ฒ„์ „ ํ˜ธํ™˜์šฉ. ์‹ ๊ทœ ๋‹จ์ผ ๊ฒ€์ƒ‰์€ find_matching_regulatory_sections_fast()๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
 
1176
  """
1177
  names_norm = [
1178
  normalize_compact(x)
 
1190
  text_norm = normalize_compact(text)
1191
 
1192
  if any(name in text_norm for name in names_norm):
 
1193
  lines = [safe_str(x) for x in text.splitlines() if safe_str(x)]
1194
  hit_indices = []
1195
 
 
1214
  context_lines.append(lines[j])
1215
 
1216
  context = section["header"] + "\n" + "\n".join(context_lines)
1217
+ reg_type = infer_regulation_type_from_source_text(section["header"] + "\n" + text[:1200], country="")
1218
 
1219
  matches.append({
1220
  "header": section["header"],
 
1254
  return matches[0]
1255
 
1256
 
1257
+ def warmup_country_indexes(countries):
1258
  """
1259
+ ์„ ํƒ ๊ตญ๊ฐ€์˜ ๋‹จ์ผ ๊ฒ€์ƒ‰ ์ธ๋ฑ์Šค๋ฅผ ๋ฏธ๋ฆฌ ๋งŒ๋“ ๋‹ค.
 
1260
  """
1261
+ messages = []
 
 
 
 
 
 
 
 
1262
 
1263
+ for country in countries or []:
1264
+ try:
1265
+ sections, status = get_country_section_index_cached(country)
1266
+ messages.append(f"{display_country(country)}: {status}, sections={len(sections)}")
1267
+ except Exception as e:
1268
+ messages.append(f"{display_country(country)}: ์ธ๋ฑ์Šค ์ƒ์„ฑ ์‹คํŒจ - {e}")
1269
 
1270
+ return "\n".join(messages) if messages else "์„ ํƒ๋œ ๊ตญ๊ฐ€ ์—†์Œ"
1271
 
1272
 
1273