Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 826 |
-
- Annex II
|
| 827 |
-
-
|
| 828 |
-
|
| 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 |
-
|
|
|
|
|
|
|
| 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":
|
| 861 |
"display": "๋ฐฐํฉ๊ธ์ง",
|
| 862 |
}
|
| 863 |
|
| 864 |
-
#
|
| 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":
|
| 883 |
"display": NEED_CHECK_TEXT,
|
| 884 |
}
|
| 885 |
|
| 886 |
-
#
|
| 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 |
-
|
| 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 |
-
|
| 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":
|
| 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 |
-
|
| 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
|
| 1258 |
"""
|
| 1259 |
-
|
| 1260 |
-
์ค์ ํ์ ์ find_matching_regulatory_sections()๋ฅผ ์ฐ์ ์ฌ์ฉํ๋ค.
|
| 1261 |
"""
|
| 1262 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1273 |
|
| 1274 |
-
return
|
| 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 |
|