Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -60,6 +60,7 @@ BASE_DIR = Path.cwd().resolve()
|
|
| 60 |
OUTPUT_DIR = BASE_DIR / "outputs"
|
| 61 |
OUTPUT_DIR.mkdir(exist_ok=True)
|
| 62 |
FAISS_CACHE_DIR = ".faiss_cache"
|
|
|
|
| 63 |
NO_EVIDENCE_TEXT = "ํด๋น ์๋ฃ ๋ด ์ ํ ๊ทผ๊ฑฐ ์์"
|
| 64 |
NEED_CHECK_TEXT = "ํ์ธ ํ์"
|
| 65 |
LIMIT_CHECK_TEXT = "๋ฐฐํฉํ๋ ํ์ธ ํ์"
|
|
@@ -68,6 +69,7 @@ EVAL_CACHE = {}
|
|
| 68 |
EMBEDDINGS_CACHE = None
|
| 69 |
RAW_SEARCH_LOGS = []
|
| 70 |
REG_TEXT_CACHE = {}
|
|
|
|
| 71 |
|
| 72 |
COUNTRY_ORDER = ["ASEAN","CALIFORNIA","CHINA","EU (FUTURE)","EU","FDA","JAPAN","KOREA","MEXICO","SEPHORA","TARGET","UK","ULTA"]
|
| 73 |
COUNTRY_DISPLAY = {"EU":"EU","์ ๋ฝ":"EU","FDA":"FDA","๋ฏธ๊ตญ":"FDA","USA":"FDA","US":"FDA","KOREA":"Korea","ํ๊ตญ":"Korea","KR":"Korea","JAPAN":"์ผ๋ณธ","์ผ๋ณธ":"์ผ๋ณธ","JP":"์ผ๋ณธ","CHINA":"์ค๊ตญ","์ค๊ตญ":"์ค๊ตญ","CN":"์ค๊ตญ","ASEAN":"ASEAN","์์ธ์":"ASEAN","UK":"UK","์๊ตญ":"UK","EU (FUTURE)":"EU (FUTURE)","EU_FUTURE":"EU (FUTURE)","CALIFORNIA":"CALIFORNIA","MEXICO":"MEXICO","SEPHORA":"SEPHORA","TARGET":"TARGET","ULTA":"ULTA"}
|
|
@@ -971,6 +973,201 @@ def split_regulatory_text_into_sections(raw_text):
|
|
| 971 |
return sections
|
| 972 |
|
| 973 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 974 |
def find_matching_regulatory_sections(raw_text, ingredient_names, max_sections=20):
|
| 975 |
"""
|
| 976 |
๊ตญ๊ฐ๋ณ ํ์ผ ์๋ฌธ์์ ํ์ฌ ์ฑ๋ถ๋ช
/INCI/CAS๊ฐ ์ง์ ํฌํจ๋ ์น์
์ ์ฐพ๋๋ค.
|
|
@@ -1131,27 +1328,8 @@ def evaluate_component_from_country_files_only(country, material, component, tar
|
|
| 1131 |
)
|
| 1132 |
return result
|
| 1133 |
|
| 1134 |
-
|
| 1135 |
-
|
| 1136 |
-
if not raw_text:
|
| 1137 |
-
result = {
|
| 1138 |
-
"๋ํ INCI": representative,
|
| 1139 |
-
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 1140 |
-
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 1141 |
-
"๋น๊ณ ": cache_status or "ํด๋น ๊ตญ๊ฐ/์ฑ๋ ๊ท์ ํ์ผ ์์",
|
| 1142 |
-
}
|
| 1143 |
-
log_search_context(
|
| 1144 |
-
target_id,
|
| 1145 |
-
country,
|
| 1146 |
-
component,
|
| 1147 |
-
result["๊ฒฐ๊ณผ"],
|
| 1148 |
-
"COUNTRY_FILE_DIRECT_NO_DB",
|
| 1149 |
-
result["๋น๊ณ "],
|
| 1150 |
-
)
|
| 1151 |
-
return result
|
| 1152 |
-
|
| 1153 |
-
matches = find_matching_regulatory_sections(
|
| 1154 |
-
raw_text=raw_text,
|
| 1155 |
ingredient_names=[inci_name, korean_name, cas_no],
|
| 1156 |
max_sections=30,
|
| 1157 |
)
|
|
@@ -1168,7 +1346,7 @@ def evaluate_component_from_country_files_only(country, material, component, tar
|
|
| 1168 |
country,
|
| 1169 |
component,
|
| 1170 |
result["๊ฒฐ๊ณผ"],
|
| 1171 |
-
"
|
| 1172 |
f"cache_status={cache_status}",
|
| 1173 |
)
|
| 1174 |
return result
|
|
@@ -1602,7 +1780,7 @@ def process_single_ingredient(
|
|
| 1602 |
|
| 1603 |
if file_result is not None:
|
| 1604 |
final_result = file_result
|
| 1605 |
-
source = "
|
| 1606 |
|
| 1607 |
if final_result is None:
|
| 1608 |
local_result = evaluate_local_rules(
|
|
@@ -1667,7 +1845,7 @@ def process_single_ingredient(
|
|
| 1667 |
f"- ์ ํ ๊ตญ๊ฐ ์: {len(countries)}๊ฐ\n"
|
| 1668 |
f"- MFDS ์ํ: {mfds_live_msg}\n"
|
| 1669 |
f"- MFDS ์กฐํ ๋์: {', '.join(terms) if terms else '์์'}\n"
|
| 1670 |
-
"- ํ์ ๋ฐฉ์: GPT ํ์ ์์, Annex/Negative/Positive List ๊ธฐ๋ฐ
|
| 1671 |
"- ๊ธ์ง ์ฑ๋ถ: ํจ๋ ์ ๋ฌด์ ๋ฌด๊ดํ๊ฒ ๋ฐฐํฉ๊ธ์ง ์ฐ์ ํ์\n"
|
| 1672 |
)
|
| 1673 |
return result_df, msg
|
|
@@ -1702,15 +1880,18 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 1702 |
with gr.Tab("๐ ๋จ์ผ ์ฑ๋ถ ๊ฒ์"):
|
| 1703 |
single_country=gr.CheckboxGroup(choices=get_country_folders(),value=[],label="๐ ๊ฒ์ ๊ตญ๊ฐ / ์ฑ๋ ์ ํ",elem_id="single_country_checks")
|
| 1704 |
single_refresh=gr.Button("๐ ๊ตญ๊ฐ/๊ท์ ํ์ผ ์๋ก๊ณ ์นจ")
|
|
|
|
| 1705 |
single_query=gr.Textbox(label="๊ฒ์์ด",placeholder="์: ํธ๋ชจ์ด๋ ์ดํธ / Homosalate / 118-56-9 / ํธ๋ผ๋ฅ์ฌ๋ฏน์ ์จ๋")
|
| 1706 |
with gr.Row():
|
| 1707 |
single_amount=gr.Textbox(label="ํจ๋ %(w/w) ์ ํ ์
๋ ฅ",placeholder="์: 7.2")
|
| 1708 |
single_function=gr.Textbox(label="FUNCTION ์ ํ ์
๋ ฅ",placeholder="์: Sunscreen Agent")
|
|
|
|
| 1709 |
single_btn=gr.Button("๐ ๋จ์ผ ์ฑ๋ถ ๊ฒ์ ์์",variant="primary")
|
| 1710 |
single_df_out=gr.Dataframe(label="๋จ์ผ ์ฑ๋ถ ๊ฒ์ ๊ฒฐ๊ณผ",wrap=True,interactive=False)
|
| 1711 |
single_msg_out=gr.Textbox(label="๊ฒ์ ์ํ / ๋ฉ์์ง",interactive=False,lines=8)
|
|
|
|
| 1712 |
single_refresh.click(refresh_country_choices_and_clear_cache,inputs=single_country,outputs=single_country)
|
| 1713 |
-
single_btn.click(process_single_ingredient,inputs=[single_country,single_query,single_amount,single_function],outputs=[single_df_out,single_msg_out])
|
| 1714 |
|
| 1715 |
USER_DB={"jin2li@rebom.kr":"qwer0515!","jkh@rebom.kr":"rebom123!","member2":"1111"}
|
| 1716 |
def auth_fn(username,password): return str(username).strip() in USER_DB and USER_DB[str(username).strip()]==str(password).strip()
|
|
|
|
| 60 |
OUTPUT_DIR = BASE_DIR / "outputs"
|
| 61 |
OUTPUT_DIR.mkdir(exist_ok=True)
|
| 62 |
FAISS_CACHE_DIR = ".faiss_cache"
|
| 63 |
+
REG_INDEX_CACHE_DIR = ".reg_index_cache"
|
| 64 |
NO_EVIDENCE_TEXT = "ํด๋น ์๋ฃ ๋ด ์ ํ ๊ทผ๊ฑฐ ์์"
|
| 65 |
NEED_CHECK_TEXT = "ํ์ธ ํ์"
|
| 66 |
LIMIT_CHECK_TEXT = "๋ฐฐํฉํ๋ ํ์ธ ํ์"
|
|
|
|
| 69 |
EMBEDDINGS_CACHE = None
|
| 70 |
RAW_SEARCH_LOGS = []
|
| 71 |
REG_TEXT_CACHE = {}
|
| 72 |
+
REG_SECTION_INDEX_CACHE = {}
|
| 73 |
|
| 74 |
COUNTRY_ORDER = ["ASEAN","CALIFORNIA","CHINA","EU (FUTURE)","EU","FDA","JAPAN","KOREA","MEXICO","SEPHORA","TARGET","UK","ULTA"]
|
| 75 |
COUNTRY_DISPLAY = {"EU":"EU","์ ๋ฝ":"EU","FDA":"FDA","๋ฏธ๊ตญ":"FDA","USA":"FDA","US":"FDA","KOREA":"Korea","ํ๊ตญ":"Korea","KR":"Korea","JAPAN":"์ผ๋ณธ","์ผ๋ณธ":"์ผ๋ณธ","JP":"์ผ๋ณธ","CHINA":"์ค๊ตญ","์ค๊ตญ":"์ค๊ตญ","CN":"์ค๊ตญ","ASEAN":"ASEAN","์์ธ์":"ASEAN","UK":"UK","์๊ตญ":"UK","EU (FUTURE)":"EU (FUTURE)","EU_FUTURE":"EU (FUTURE)","CALIFORNIA":"CALIFORNIA","MEXICO":"MEXICO","SEPHORA":"SEPHORA","TARGET":"TARGET","ULTA":"ULTA"}
|
|
|
|
| 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 |
+
|
| 993 |
+
folder = resolve_country_folder(country)
|
| 994 |
+
|
| 995 |
+
if not folder or not os.path.isdir(folder):
|
| 996 |
+
return [], "ํด๋น ๊ตญ๊ฐ/์ฑ๋ ํด๋ ์์"
|
| 997 |
+
|
| 998 |
+
files = get_regulatory_file_list(folder)
|
| 999 |
+
|
| 1000 |
+
if not files:
|
| 1001 |
+
return [], "ํด๋น ๊ตญ๊ฐ/์ฑ๋ ๊ท์ ํ์ผ ์์"
|
| 1002 |
+
|
| 1003 |
+
signature = tuple((f["relative_path"], f["size"], f["mtime_ns"]) for f in files)
|
| 1004 |
+
sig_hash = stable_hash(signature)
|
| 1005 |
+
memory_key = f"{folder}|{sig_hash}"
|
| 1006 |
+
|
| 1007 |
+
if memory_key in REG_SECTION_INDEX_CACHE:
|
| 1008 |
+
return REG_SECTION_INDEX_CACHE[memory_key], "MEMORY_CACHE"
|
| 1009 |
+
|
| 1010 |
+
os.makedirs(REG_INDEX_CACHE_DIR, exist_ok=True)
|
| 1011 |
+
cache_file = os.path.join(
|
| 1012 |
+
REG_INDEX_CACHE_DIR,
|
| 1013 |
+
f"{safe_filename(folder)}_{sig_hash[:16]}_sections.json",
|
| 1014 |
+
)
|
| 1015 |
+
|
| 1016 |
+
if os.path.exists(cache_file):
|
| 1017 |
+
try:
|
| 1018 |
+
with open(cache_file, "r", encoding="utf-8") as f:
|
| 1019 |
+
payload = json.load(f)
|
| 1020 |
+
|
| 1021 |
+
if payload.get("signature_hash") == sig_hash:
|
| 1022 |
+
sections = payload.get("sections", [])
|
| 1023 |
+
REG_SECTION_INDEX_CACHE[memory_key] = sections
|
| 1024 |
+
return sections, "DISK_CACHE"
|
| 1025 |
+
except Exception as e:
|
| 1026 |
+
print(f"์น์
์ธ๋ฑ์ค ์บ์ ๋ก๋ ์คํจ: {cache_file} / {e}")
|
| 1027 |
+
|
| 1028 |
+
sections = []
|
| 1029 |
+
|
| 1030 |
+
for item in files:
|
| 1031 |
+
try:
|
| 1032 |
+
raw = extract_text_from_regulatory_file(item)
|
| 1033 |
+
|
| 1034 |
+
if not raw:
|
| 1035 |
+
continue
|
| 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,
|
| 1049 |
+
"header": source_header,
|
| 1050 |
+
"regulation_type": reg_type,
|
| 1051 |
+
"text": raw,
|
| 1052 |
+
"text_norm": normalize_compact(raw),
|
| 1053 |
+
})
|
| 1054 |
+
|
| 1055 |
+
except Exception as e:
|
| 1056 |
+
print(f"์น์
์ธ๋ฑ์ค ์์ฑ ์คํจ: {item.get('path', '')} / {e}")
|
| 1057 |
+
|
| 1058 |
+
REG_SECTION_INDEX_CACHE[memory_key] = sections
|
| 1059 |
+
|
| 1060 |
+
try:
|
| 1061 |
+
with open(cache_file, "w", encoding="utf-8") as f:
|
| 1062 |
+
json.dump(
|
| 1063 |
+
{
|
| 1064 |
+
"country": str(country),
|
| 1065 |
+
"folder": folder,
|
| 1066 |
+
"signature_hash": sig_hash,
|
| 1067 |
+
"sections": sections,
|
| 1068 |
+
},
|
| 1069 |
+
f,
|
| 1070 |
+
ensure_ascii=False,
|
| 1071 |
+
)
|
| 1072 |
+
except Exception as e:
|
| 1073 |
+
print(f"์น์
์ธ๋ฑ์ค ์บ์ ์ ์ฅ ์คํจ: {cache_file} / {e}")
|
| 1074 |
+
|
| 1075 |
+
return sections, "BUILT_INDEX"
|
| 1076 |
+
|
| 1077 |
+
|
| 1078 |
+
def find_matching_regulatory_sections_fast(country, ingredient_names, max_sections=30):
|
| 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 |
+
|
| 1086 |
+
names_norm = [
|
| 1087 |
+
normalize_compact(x)
|
| 1088 |
+
for x in ingredient_names
|
| 1089 |
+
if safe_str(x) and len(normalize_compact(x)) >= 3
|
| 1090 |
+
]
|
| 1091 |
+
|
| 1092 |
+
if not names_norm:
|
| 1093 |
+
return [], status
|
| 1094 |
+
|
| 1095 |
+
matches = []
|
| 1096 |
+
|
| 1097 |
+
for section in sections:
|
| 1098 |
+
text_norm = section.get("text_norm", "")
|
| 1099 |
+
|
| 1100 |
+
if not any(name in text_norm for name in names_norm):
|
| 1101 |
+
continue
|
| 1102 |
+
|
| 1103 |
+
text = safe_str(section.get("text", ""))
|
| 1104 |
+
header = safe_str(section.get("header", ""))
|
| 1105 |
+
lines = [safe_str(x) for x in text.splitlines() if safe_str(x)]
|
| 1106 |
+
|
| 1107 |
+
hit_indices = []
|
| 1108 |
+
|
| 1109 |
+
for idx, line in enumerate(lines):
|
| 1110 |
+
line_norm = normalize_compact(line)
|
| 1111 |
+
|
| 1112 |
+
if any(name in line_norm for name in names_norm):
|
| 1113 |
+
hit_indices.append(idx)
|
| 1114 |
+
|
| 1115 |
+
if len(hit_indices) >= 10:
|
| 1116 |
+
break
|
| 1117 |
+
|
| 1118 |
+
context_lines = []
|
| 1119 |
+
seen = set()
|
| 1120 |
+
|
| 1121 |
+
for idx in hit_indices:
|
| 1122 |
+
start = max(0, idx - 4)
|
| 1123 |
+
end = min(len(lines), idx + 5)
|
| 1124 |
+
|
| 1125 |
+
for j in range(start, end):
|
| 1126 |
+
if j in seen:
|
| 1127 |
+
continue
|
| 1128 |
+
|
| 1129 |
+
seen.add(j)
|
| 1130 |
+
context_lines.append(lines[j])
|
| 1131 |
+
|
| 1132 |
+
if context_lines:
|
| 1133 |
+
context = header + "\n" + "\n".join(context_lines)
|
| 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:
|
| 1148 |
+
break
|
| 1149 |
+
|
| 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๊ฐ ์ง์ ํฌํจ๋ ์น์
์ ์ฐพ๋๋ค.
|
|
|
|
| 1328 |
)
|
| 1329 |
return result
|
| 1330 |
|
| 1331 |
+
matches, cache_status = find_matching_regulatory_sections_fast(
|
| 1332 |
+
country=country,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1333 |
ingredient_names=[inci_name, korean_name, cas_no],
|
| 1334 |
max_sections=30,
|
| 1335 |
)
|
|
|
|
| 1346 |
country,
|
| 1347 |
component,
|
| 1348 |
result["๊ฒฐ๊ณผ"],
|
| 1349 |
+
"COUNTRY_FILE_FAST_NO_HIT",
|
| 1350 |
f"cache_status={cache_status}",
|
| 1351 |
)
|
| 1352 |
return result
|
|
|
|
| 1780 |
|
| 1781 |
if file_result is not None:
|
| 1782 |
final_result = file_result
|
| 1783 |
+
source = "COUNTRY_FILE_FAST"
|
| 1784 |
|
| 1785 |
if final_result is None:
|
| 1786 |
local_result = evaluate_local_rules(
|
|
|
|
| 1845 |
f"- ์ ํ ๊ตญ๊ฐ ์: {len(countries)}๊ฐ\n"
|
| 1846 |
f"- MFDS ์ํ: {mfds_live_msg}\n"
|
| 1847 |
f"- MFDS ์กฐํ ๋์: {', '.join(terms) if terms else '์์'}\n"
|
| 1848 |
+
"- ํ์ ๋ฐฉ์: GPT ํ์ ์์, Annex/Negative/Positive List ๊ธฐ๋ฐ ๊ณ ์ ์ธ๋ฑ์ค ๊ฒ์ + ์์ฝ์ฒ ์ฒดํฌ ON ์ ์ค์๊ฐ ๊ฒฐ๊ณผ ์ฌ์ฉ\n"
|
| 1849 |
"- ๊ธ์ง ์ฑ๋ถ: ํจ๋ ์ ๋ฌด์ ๋ฌด๊ดํ๊ฒ ๋ฐฐํฉ๊ธ์ง ์ฐ์ ํ์\n"
|
| 1850 |
)
|
| 1851 |
return result_df, msg
|
|
|
|
| 1880 |
with gr.Tab("๐ ๋จ์ผ ์ฑ๋ถ ๊ฒ์"):
|
| 1881 |
single_country=gr.CheckboxGroup(choices=get_country_folders(),value=[],label="๐ ๊ฒ์ ๊ตญ๊ฐ / ์ฑ๋ ์ ํ",elem_id="single_country_checks")
|
| 1882 |
single_refresh=gr.Button("๐ ๊ตญ๊ฐ/๊ท์ ํ์ผ ์๋ก๊ณ ์นจ")
|
| 1883 |
+
single_warmup_btn=gr.Button("โก ๋จ์ผ๊ฒ์ ์บ์ ๋ฏธ๋ฆฌ ๋ง๋ค๊ธฐ")
|
| 1884 |
single_query=gr.Textbox(label="๊ฒ์์ด",placeholder="์: ํธ๋ชจ์ด๋ ์ดํธ / Homosalate / 118-56-9 / ํธ๋ผ๋ฅ์ฌ๋ฏน์ ์จ๋")
|
| 1885 |
with gr.Row():
|
| 1886 |
single_amount=gr.Textbox(label="ํจ๋ %(w/w) ์ ํ ์
๋ ฅ",placeholder="์: 7.2")
|
| 1887 |
single_function=gr.Textbox(label="FUNCTION ์ ํ ์
๋ ฅ",placeholder="์: Sunscreen Agent")
|
| 1888 |
+
single_use_mfds_live=gr.Checkbox(label="์์ฝ์ฒ ์ฌ์ดํธ ์ค์๊ฐ ์กฐํ ์ฌ์ฉ",value=False)
|
| 1889 |
single_btn=gr.Button("๐ ๋จ์ผ ์ฑ๋ถ ๊ฒ์ ์์",variant="primary")
|
| 1890 |
single_df_out=gr.Dataframe(label="๋จ์ผ ์ฑ๋ถ ๊ฒ์ ๊ฒฐ๊ณผ",wrap=True,interactive=False)
|
| 1891 |
single_msg_out=gr.Textbox(label="๊ฒ์ ์ํ / ๋ฉ์์ง",interactive=False,lines=8)
|
| 1892 |
+
single_warmup_btn.click(warmup_country_indexes,inputs=single_country,outputs=single_msg_out)
|
| 1893 |
single_refresh.click(refresh_country_choices_and_clear_cache,inputs=single_country,outputs=single_country)
|
| 1894 |
+
single_btn.click(process_single_ingredient,inputs=[single_country,single_query,single_amount,single_function,single_use_mfds_live],outputs=[single_df_out,single_msg_out])
|
| 1895 |
|
| 1896 |
USER_DB={"jin2li@rebom.kr":"qwer0515!","jkh@rebom.kr":"rebom123!","member2":"1111"}
|
| 1897 |
def auth_fn(username,password): return str(username).strip() in USER_DB and USER_DB[str(username).strip()]==str(password).strip()
|