Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
| 1 |
# ============================================================
|
| 2 |
-
# reBom Regulatory Screening AI
|
| 3 |
# - ๊ตญ๊ฐ/์ฑ๋ ํด๋ ์๋ ์ธ์
|
| 4 |
# - ๊ท์ ํ์ผ ์๋ ๋ณ๊ฒฝ ๊ฐ์ง
|
| 5 |
# - ๊ตญ๊ฐ๋ณ FAISS ๋ฒกํฐ DB ๋์คํฌ ์บ์
|
| 6 |
# - ๊ตญ๊ฐ๋ณ ๋ฌธ์ ๊ฒฉ๋ฆฌ ๊ฒ์์ผ๋ก ํ๊ตญ ๊ท์ ํ์ฐ ๋ฐฉ์ง
|
| 7 |
# - ๋ก์ปฌ ๊ท์น ์ฐ์ ํ์
|
| 8 |
# - MFDS ์์ฝํ์์ ๋๋ผ ์์ธ DB ์์
์ฐ๋
|
|
|
|
| 9 |
# - ๊ตญ๊ฐ๋ณ batch GPT ํ์
|
| 10 |
# - Formula Ingredients Statement ๊ฐ์ํ ์ถ๋ ฅ
|
| 11 |
# - ๋ฌธ์ ์ฑ๋ถ๋ง Regulatory Screening Summary ์ถ๋ ฅ
|
|
@@ -198,9 +199,13 @@ ALLOWED_PATHS = [
|
|
| 198 |
str(BASE_DIR),
|
| 199 |
]
|
| 200 |
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
|
| 205 |
custom_css = """
|
| 206 |
#country_checks .wrap,
|
|
@@ -585,6 +590,7 @@ def is_country_result_issue(text):
|
|
| 585 |
"ํด๋น์์",
|
| 586 |
"ํด๋น ์์",
|
| 587 |
"ํน์ด ๊ท์ ํ์ธ ์์",
|
|
|
|
| 588 |
]
|
| 589 |
|
| 590 |
if text in pass_values:
|
|
@@ -1680,7 +1686,7 @@ def evaluate_limit_rule(country, material, component, rule_group, rule_type_name
|
|
| 1680 |
|
| 1681 |
return {
|
| 1682 |
"๋ํ INCI": label,
|
| 1683 |
-
"๊ฒฐ๊ณผ":
|
| 1684 |
"๋น๊ณ ": "-",
|
| 1685 |
}
|
| 1686 |
|
|
@@ -1805,7 +1811,7 @@ def evaluate_local_rules(country, material, component, ingredient_totals, ingred
|
|
| 1805 |
def parse_country_response(text):
|
| 1806 |
result = {
|
| 1807 |
"๋ํ INCI": "-",
|
| 1808 |
-
"๊ฒฐ๊ณผ":
|
| 1809 |
"๋น๊ณ ": "-",
|
| 1810 |
}
|
| 1811 |
|
|
@@ -1816,7 +1822,7 @@ def parse_country_response(text):
|
|
| 1816 |
result["๋ํ INCI"] = line.split(":", 1)[1].strip() or "-"
|
| 1817 |
|
| 1818 |
elif line.startswith("๊ฒฐ๊ณผ:"):
|
| 1819 |
-
result["๊ฒฐ๊ณผ"] = line.split(":", 1)[1].strip() or
|
| 1820 |
|
| 1821 |
elif line.startswith("๋น๊ณ :"):
|
| 1822 |
result["๋น๊ณ "] = line.split(":", 1)[1].strip() or "-"
|
|
@@ -1847,7 +1853,7 @@ def sanitize_country_result(parsed, fallback_inci="-"):
|
|
| 1847 |
parsed = {}
|
| 1848 |
|
| 1849 |
representative = safe_str(parsed.get("๋ํ INCI", "")) or fallback_inci or "-"
|
| 1850 |
-
result_text = safe_str(parsed.get("๊ฒฐ๊ณผ", "")) or
|
| 1851 |
note = safe_str(parsed.get("๋น๊ณ ", "")) or "-"
|
| 1852 |
|
| 1853 |
bad_tokens = [
|
|
@@ -1889,6 +1895,26 @@ def make_eval_cache_key(country, component):
|
|
| 1889 |
)
|
| 1890 |
|
| 1891 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1892 |
def evaluate_component_with_llm(country, material, component, llm, target_id=""):
|
| 1893 |
db = build_database(country)
|
| 1894 |
|
|
@@ -1907,7 +1933,7 @@ def evaluate_component_with_llm(country, material, component, llm, target_id="")
|
|
| 1907 |
if not db:
|
| 1908 |
result = {
|
| 1909 |
"๋ํ INCI": inci_name or "-",
|
| 1910 |
-
"๊ฒฐ๊ณผ":
|
| 1911 |
"๋น๊ณ ": "-",
|
| 1912 |
}
|
| 1913 |
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "NO_DB", "ํด๋น ๊ตญ๊ฐ/์ฑ๋ ๊ท์ DB ์์")
|
|
@@ -1930,6 +1956,23 @@ def evaluate_component_with_llm(country, material, component, llm, target_id="")
|
|
| 1930 |
์ ํ์ ํ: Leave-on ๋ฐ Wash-off ๊ธฐ์ค ๋ชจ๋ ํ์ธ
|
| 1931 |
"""
|
| 1932 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1933 |
docs = db.similarity_search(search_text, k=RAG_TOP_K_SINGLE)
|
| 1934 |
context = "\n".join([d.page_content for d in docs])
|
| 1935 |
|
|
@@ -1940,11 +1983,11 @@ def evaluate_component_with_llm(country, material, component, llm, target_id="")
|
|
| 1940 |
[์ ๋ ๊ท์น]
|
| 1941 |
- ํ์ฌ ๊ฒํ ๊ตญ๊ฐ๋ "{country}"์ด๋ค.
|
| 1942 |
- ์๋ ๊ฒ์ ์๋ฌธ์ "{country}" ํด๋ ๋๋ ์ฑ๋์์๋ง ๊ฒ์๋ ๊ทผ๊ฑฐ๋ค.
|
| 1943 |
-
-
|
|
|
|
| 1944 |
- ํนํ EU ๊ท์ ์ ํ๊ตญ/์ผ๋ณธ/๋ฏธ๊ตญ/FDA/์ค๊ตญ์ ๋ณต์ฌ ์ ์ฉํ์ง ๋ง.
|
| 1945 |
-
- ASEAN์ฒ๋ผ EU ์ฒด๊ณ๋ฅผ ์ฐธ์กฐํ๋ ๋ฌธ์๊ฐ ์๋๋ผ๋, ASEAN ๊ตญ๊ฐ๋ก ์ ํ๋ ๊ฒฝ์ฐ์๋ง ASEAN ๊ฒฐ๊ณผ๋ก ์์ฑํด.
|
| 1946 |
- ๊ฒ์๋ "{country}" ์๋ฌธ์ ๋ช
์๋์ง ์์ ์ ํ, ๋ฐฐํฉ๊ธ์ง, ๋ฐฐํฉํ๋๋ ๋ง๋ค์ง ๋ง.
|
| 1947 |
-
- ์๋ฌธ ๊ทผ๊ฑฐ๊ฐ ์์ผ๋ฉด ๊ฒฐ๊ณผ๋ ์ ํํ "
|
| 1948 |
|
| 1949 |
[์๋ฃ๋ช
๊ตญ๋ฌธ]
|
| 1950 |
{trade_ko}
|
|
@@ -1968,8 +2011,6 @@ INCI/CAS: {inci_name}
|
|
| 1968 |
์์ฑ ์์น:
|
| 1969 |
- ๊ฒ์๋ ๊ท์ ์๋ฌธ์ ๊ทผ๊ฑฐ๊ฐ ์๋ ๋ด์ฉ๋ง ์์ฑํด.
|
| 1970 |
- ์๋ฌธ์ ๊ทผ๊ฑฐ๊ฐ ์๋๋ฐ ํน์ ํ๋๋ ๊ธ์ง ์ฌ๋ถ๋ฅผ ๋ง๋ค์ง ๋ง.
|
| 1971 |
-
- ๊ด๋ จ ๊ท์ ๊ฐ ์์ผ๋ฉด ๊ฒฐ๊ณผ๋ ์ ํํ "์ ํ ์์ (ํต๊ณผ)" ๋ก ์์ฑํด.
|
| 1972 |
-
- "๋ฐฐํฉํ๋ ์์" ์์ฒด๋ ๋ฌธ์ ๊ฐ ์๋๋ค.
|
| 1973 |
- ํ์ฌ ํจ๋์ด ํ๋ ์ด๋ด๋ผ๋ฉด ๋ฐ๋์ "์ด๋ด(ํต๊ณผ)"๋ผ๊ณ ์์ฑํด.
|
| 1974 |
- ํ์ฌ ํจ๋์ด ํ๋๋ฅผ ์ด๊ณผํ ๋๋ง "์ด๊ณผ" ๋๋ "์ฌ๊ฒํ ํ์"๋ผ๊ณ ์์ฑํด.
|
| 1975 |
- ๋ฐฐํฉ๊ธ์ง, ํ์ ํ์, ์๋ฃ ํ์ธ ํ์๋ ์ฌ๊ฒํ ๋์์ด๋ค.
|
|
@@ -2009,7 +2050,7 @@ def evaluate_components_with_llm_batch(country, targets, llm):
|
|
| 2009 |
|
| 2010 |
results[item["target_id"]] = {
|
| 2011 |
"๋ํ INCI": inci_name or "-",
|
| 2012 |
-
"๊ฒฐ๊ณผ":
|
| 2013 |
"๋น๊ณ ": "-",
|
| 2014 |
}
|
| 2015 |
|
|
@@ -2017,7 +2058,7 @@ def evaluate_components_with_llm_batch(country, targets, llm):
|
|
| 2017 |
item["target_id"],
|
| 2018 |
country,
|
| 2019 |
comp,
|
| 2020 |
-
|
| 2021 |
"NO_DB",
|
| 2022 |
"ํด๋น ๊ตญ๊ฐ/์ฑ๋ ๊ท์ DB ์์",
|
| 2023 |
)
|
|
@@ -2035,6 +2076,57 @@ def evaluate_components_with_llm_batch(country, targets, llm):
|
|
| 2035 |
else:
|
| 2036 |
uncached_targets.append(item)
|
| 2037 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2038 |
if not uncached_targets:
|
| 2039 |
return results
|
| 2040 |
|
|
@@ -2080,11 +2172,11 @@ def evaluate_components_with_llm_batch(country, targets, llm):
|
|
| 2080 |
[์ ๋ ๊ท์น]
|
| 2081 |
- ํ์ฌ ๊ฒํ ๊ตญ๊ฐ๋ "{country}"์ด๋ค.
|
| 2082 |
- ์๋ ๊ฒ์ ์๋ฌธ์ "{country}" ํด๋ ๋๋ ์ฑ๋์์๋ง ๊ฒ์๋ ๊ทผ๊ฑฐ๋ค.
|
| 2083 |
-
-
|
|
|
|
| 2084 |
- ํนํ EU ๊ท์ ์ ํ๊ตญ/์ผ๋ณธ/๋ฏธ๊ตญ/FDA/์ค๊ตญ์ ๋ณต์ฌ ์ ์ฉํ์ง ๋ง.
|
| 2085 |
-
- ASEAN์ฒ๋ผ EU ์ฒด๊ณ๋ฅผ ์ฐธ์กฐํ๋ ๋ฌธ์๊ฐ ์๋๋ผ๋, ASEAN ๊ตญ๊ฐ๋ก ์ ํ๋ ๊ฒฝ์ฐ์๋ง ASEAN ๊ฒฐ๊ณผ๋ก ์์ฑํด.
|
| 2086 |
- ๊ฒ์๋ "{country}" ์๋ฌธ์ ๋ช
์๋์ง ์์ ์ ํ, ๋ฐฐํฉ๊ธ์ง, ๋ฐฐํฉํ๋๋ ๋ง๋ค์ง ๋ง.
|
| 2087 |
-
- ์๋ฌธ ๊ทผ๊ฑฐ๊ฐ ์์ผ๋ฉด ๊ฒฐ๊ณผ๋ ์ ํํ "
|
| 2088 |
|
| 2089 |
[๊ฒํ ๋์ JSON]
|
| 2090 |
{json.dumps(target_payload, ensure_ascii=False, indent=2)}
|
|
@@ -2100,7 +2192,7 @@ def evaluate_components_with_llm_batch(country, targets, llm):
|
|
| 2100 |
{{
|
| 2101 |
"target_id": "์
๋ ฅ target_id ๊ทธ๋๋ก",
|
| 2102 |
"๋ํ INCI": "๏ฟฝ๏ฟฝ๏ฟฝํ INCI ๋๋ -",
|
| 2103 |
-
"๊ฒฐ๊ณผ": "
|
| 2104 |
"๋น๊ณ ": "-"
|
| 2105 |
}}
|
| 2106 |
]
|
|
@@ -2108,8 +2200,6 @@ def evaluate_components_with_llm_batch(country, targets, llm):
|
|
| 2108 |
์์ฑ ์์น:
|
| 2109 |
- ๊ฒ์๋ ๊ท์ ์๋ฌธ์ ๊ทผ๊ฑฐ๊ฐ ์๋ ๋ด์ฉ๋ง ์์ฑํด.
|
| 2110 |
- ์๋ฌธ์ ๊ทผ๊ฑฐ๊ฐ ์๋๋ฐ ํน์ ํ๋๋ ๊ธ์ง ์ฌ๋ถ๋ฅผ ๋ง๋ค์ง ๋ง.
|
| 2111 |
-
- ๊ด๋ จ ๊ท์ ๊ฐ ์์ผ๋ฉด ๊ฒฐ๊ณผ๋ ์ ํํ "์ ํ ์์ (ํต๊ณผ)" ๋ก ์์ฑํด.
|
| 2112 |
-
- "๋ฐฐํฉํ๋ ์์" ์์ฒด๋ ๋ฌธ์ ๊ฐ ์๋๋ค.
|
| 2113 |
- ํ์ฌ ํจ๋์ด ํ๋ ์ด๋ด๋ผ๋ฉด ๋ฐ๋์ "์ด๋ด(ํต๊ณผ)"๋ผ๊ณ ์์ฑํด.
|
| 2114 |
- ํ์ฌ ํจ๋์ด ํ๋๋ฅผ ์ด๊ณผํ ๋๋ง "์ด๊ณผ" ๋๋ "์ฌ๊ฒํ ํ์"๋ผ๊ณ ์์ฑํด.
|
| 2115 |
- ๋ฐฐํฉ๊ธ์ง, ํ์ ํ์, ์๋ฃ ํ์ธ ํ์๋ ์ฌ๊ฒํ ๋์์ด๋ค.
|
|
@@ -2550,7 +2640,7 @@ def process(countries, file, product_name="", use_mfds_db=True):
|
|
| 2550 |
" 2) Regulatory Screening Summary: ๋ฌธ์ ์๋ ์ฑ๋ถ๋ง ๊ตญ๊ฐ๋ณ ์์ฝ\n"
|
| 2551 |
" 3) Raw Search Log: ๋ก์ปฌ ๊ท์น/MFDS/GPT ๊ฒ์ ๊ทผ๊ฑฐ ๋ก๊ทธ\n"
|
| 2552 |
"- ํ์ ์ฐ์ ์์: ๋ก์ปฌ ๊ณ ์ ๊ท์น โ MFDS ์์ธ DB โ ๊ตญ๊ฐ๋ณ FAISS/GPT\n"
|
| 2553 |
-
"-
|
| 2554 |
"- ๊ตญ๊ฐ๋ณ FAISS DB๋ฅผ ๋ถ๋ฆฌํด์ EU ๊ฒฐ๊ณผ๊ฐ ํ๊ตญ/์ผ๋ณธ/๋ฏธ๊ตญ์ผ๋ก ์๋ ํ์ฐ๋์ง ์๋๋ก ์์ ํ์ต๋๋ค.\n"
|
| 2555 |
"- public share link๊ฐ ์์ฑ๋๋๋ก share=True๋ก ์คํํฉ๋๋ค."
|
| 2556 |
)
|
|
|
|
| 1 |
# ============================================================
|
| 2 |
+
# reBom Regulatory Screening AI - Fast Grounded Version
|
| 3 |
# - ๊ตญ๊ฐ/์ฑ๋ ํด๋ ์๋ ์ธ์
|
| 4 |
# - ๊ท์ ํ์ผ ์๋ ๋ณ๊ฒฝ ๊ฐ์ง
|
| 5 |
# - ๊ตญ๊ฐ๋ณ FAISS ๋ฒกํฐ DB ๋์คํฌ ์บ์
|
| 6 |
# - ๊ตญ๊ฐ๋ณ ๋ฌธ์ ๊ฒฉ๋ฆฌ ๊ฒ์์ผ๋ก ํ๊ตญ ๊ท์ ํ์ฐ ๋ฐฉ์ง
|
| 7 |
# - ๋ก์ปฌ ๊ท์น ์ฐ์ ํ์
|
| 8 |
# - MFDS ์์ฝํ์์ ๋๋ผ ์์ธ DB ์์
์ฐ๋
|
| 9 |
+
# - GPT ํธ์ถ ์ ์๋ฏธ ์๋ ๊ฒ์๊ฒฐ๊ณผ ํํฐ๋ง
|
| 10 |
# - ๊ตญ๊ฐ๋ณ batch GPT ํ์
|
| 11 |
# - Formula Ingredients Statement ๊ฐ์ํ ์ถ๋ ฅ
|
| 12 |
# - ๋ฌธ์ ์ฑ๋ถ๋ง Regulatory Screening Summary ์ถ๋ ฅ
|
|
|
|
| 199 |
str(BASE_DIR),
|
| 200 |
]
|
| 201 |
|
| 202 |
+
# ์๋ ๊ฐ์ ๊ฐ
|
| 203 |
+
BATCH_SIZE = 40
|
| 204 |
+
RAG_TOP_K_BATCH = 4
|
| 205 |
+
RAG_TOP_K_SINGLE = 2
|
| 206 |
+
MEANINGFUL_HIT_K = 2
|
| 207 |
+
|
| 208 |
+
NO_EVIDENCE_TEXT = "ํด๋น ์๋ฃ ๋ด ์ ํ ๊ทผ๊ฑฐ ์์"
|
| 209 |
|
| 210 |
custom_css = """
|
| 211 |
#country_checks .wrap,
|
|
|
|
| 590 |
"ํด๋น์์",
|
| 591 |
"ํด๋น ์์",
|
| 592 |
"ํน์ด ๊ท์ ํ์ธ ์์",
|
| 593 |
+
NO_EVIDENCE_TEXT,
|
| 594 |
]
|
| 595 |
|
| 596 |
if text in pass_values:
|
|
|
|
| 1686 |
|
| 1687 |
return {
|
| 1688 |
"๋ํ INCI": label,
|
| 1689 |
+
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 1690 |
"๋น๊ณ ": "-",
|
| 1691 |
}
|
| 1692 |
|
|
|
|
| 1811 |
def parse_country_response(text):
|
| 1812 |
result = {
|
| 1813 |
"๋ํ INCI": "-",
|
| 1814 |
+
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 1815 |
"๋น๊ณ ": "-",
|
| 1816 |
}
|
| 1817 |
|
|
|
|
| 1822 |
result["๋ํ INCI"] = line.split(":", 1)[1].strip() or "-"
|
| 1823 |
|
| 1824 |
elif line.startswith("๊ฒฐ๊ณผ:"):
|
| 1825 |
+
result["๊ฒฐ๊ณผ"] = line.split(":", 1)[1].strip() or NO_EVIDENCE_TEXT
|
| 1826 |
|
| 1827 |
elif line.startswith("๋น๊ณ :"):
|
| 1828 |
result["๋น๊ณ "] = line.split(":", 1)[1].strip() or "-"
|
|
|
|
| 1853 |
parsed = {}
|
| 1854 |
|
| 1855 |
representative = safe_str(parsed.get("๋ํ INCI", "")) or fallback_inci or "-"
|
| 1856 |
+
result_text = safe_str(parsed.get("๊ฒฐ๊ณผ", "")) or NO_EVIDENCE_TEXT
|
| 1857 |
note = safe_str(parsed.get("๋น๊ณ ", "")) or "-"
|
| 1858 |
|
| 1859 |
bad_tokens = [
|
|
|
|
| 1895 |
)
|
| 1896 |
|
| 1897 |
|
| 1898 |
+
def has_meaningful_search_hit(db, search_text, ingredient_names, k=MEANINGFUL_HIT_K):
|
| 1899 |
+
if not db:
|
| 1900 |
+
return False, ""
|
| 1901 |
+
|
| 1902 |
+
try:
|
| 1903 |
+
docs = db.similarity_search(search_text, k=k)
|
| 1904 |
+
context = "\n".join([d.page_content for d in docs])
|
| 1905 |
+
except Exception:
|
| 1906 |
+
return False, ""
|
| 1907 |
+
|
| 1908 |
+
context_norm = normalize_compact(context)
|
| 1909 |
+
|
| 1910 |
+
for name in ingredient_names:
|
| 1911 |
+
name_norm = normalize_compact(name)
|
| 1912 |
+
if name_norm and len(name_norm) >= 3 and name_norm in context_norm:
|
| 1913 |
+
return True, context
|
| 1914 |
+
|
| 1915 |
+
return False, context
|
| 1916 |
+
|
| 1917 |
+
|
| 1918 |
def evaluate_component_with_llm(country, material, component, llm, target_id=""):
|
| 1919 |
db = build_database(country)
|
| 1920 |
|
|
|
|
| 1933 |
if not db:
|
| 1934 |
result = {
|
| 1935 |
"๋ํ INCI": inci_name or "-",
|
| 1936 |
+
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 1937 |
"๋น๊ณ ": "-",
|
| 1938 |
}
|
| 1939 |
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "NO_DB", "ํด๋น ๊ตญ๊ฐ/์ฑ๋ ๊ท์ DB ์์")
|
|
|
|
| 1956 |
์ ํ์ ํ: Leave-on ๋ฐ Wash-off ๊ธฐ์ค ๋ชจ๋ ํ์ธ
|
| 1957 |
"""
|
| 1958 |
|
| 1959 |
+
has_hit, pre_context = has_meaningful_search_hit(
|
| 1960 |
+
db=db,
|
| 1961 |
+
search_text=search_text,
|
| 1962 |
+
ingredient_names=[inci_name, korean_name],
|
| 1963 |
+
k=MEANINGFUL_HIT_K,
|
| 1964 |
+
)
|
| 1965 |
+
|
| 1966 |
+
if not has_hit:
|
| 1967 |
+
result = {
|
| 1968 |
+
"๋ํ INCI": inci_name or "-",
|
| 1969 |
+
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 1970 |
+
"๋น๊ณ ": "-",
|
| 1971 |
+
}
|
| 1972 |
+
EVAL_CACHE[cache_key] = result
|
| 1973 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "NO_MEANINGFUL_HIT", pre_context)
|
| 1974 |
+
return result
|
| 1975 |
+
|
| 1976 |
docs = db.similarity_search(search_text, k=RAG_TOP_K_SINGLE)
|
| 1977 |
context = "\n".join([d.page_content for d in docs])
|
| 1978 |
|
|
|
|
| 1983 |
[์ ๋ ๊ท์น]
|
| 1984 |
- ํ์ฌ ๊ฒํ ๊ตญ๊ฐ๋ "{country}"์ด๋ค.
|
| 1985 |
- ์๋ ๊ฒ์ ์๋ฌธ์ "{country}" ํด๋ ๋๋ ์ฑ๋์์๋ง ๊ฒ์๋ ๊ทผ๊ฑฐ๋ค.
|
| 1986 |
+
- ์ธ๋ถ ์ง์, ํ์ต ์ง์, ์ผ๋ฐ ๊ท์ ์ง๏ฟฝ๏ฟฝ๏ฟฝ์ ์ฌ์ฉํ์ง ๋ง.
|
| 1987 |
+
- ๋ค๋ฅธ ๊ตญ๊ฐ ๊ท์ , EU Annex, ASEAN ์ฑํ ๊ท์ ์ ํ์ฌ ๊ตญ๊ฐ์ ์์ ์ ์ฉํ์ง ๋ง.
|
| 1988 |
- ํนํ EU ๊ท์ ์ ํ๊ตญ/์ผ๋ณธ/๋ฏธ๊ตญ/FDA/์ค๊ตญ์ ๋ณต์ฌ ์ ์ฉํ์ง ๋ง.
|
|
|
|
| 1989 |
- ๊ฒ์๋ "{country}" ์๋ฌธ์ ๋ช
์๋์ง ์์ ์ ํ, ๋ฐฐํฉ๊ธ์ง, ๋ฐฐํฉํ๋๋ ๋ง๋ค์ง ๋ง.
|
| 1990 |
+
- ๊ฒ์ ์๋ฌธ์ ๋ช
์๋ ์ ํ/๊ธ์ง/ํ๋ ๊ทผ๊ฑฐ๊ฐ ์์ผ๋ฉด ๊ฒฐ๊ณผ๋ ์ ํํ "{NO_EVIDENCE_TEXT}"์ผ๋ก ์์ฑํด.
|
| 1991 |
|
| 1992 |
[์๋ฃ๋ช
๊ตญ๋ฌธ]
|
| 1993 |
{trade_ko}
|
|
|
|
| 2011 |
์์ฑ ์์น:
|
| 2012 |
- ๊ฒ์๋ ๊ท์ ์๋ฌธ์ ๊ทผ๊ฑฐ๊ฐ ์๋ ๋ด์ฉ๋ง ์์ฑํด.
|
| 2013 |
- ์๋ฌธ์ ๊ทผ๊ฑฐ๊ฐ ์๋๋ฐ ํน์ ํ๋๋ ๊ธ์ง ์ฌ๋ถ๋ฅผ ๋ง๋ค์ง ๋ง.
|
|
|
|
|
|
|
| 2014 |
- ํ์ฌ ํจ๋์ด ํ๋ ์ด๋ด๋ผ๋ฉด ๋ฐ๋์ "์ด๋ด(ํต๊ณผ)"๋ผ๊ณ ์์ฑํด.
|
| 2015 |
- ํ์ฌ ํจ๋์ด ํ๋๋ฅผ ์ด๊ณผํ ๋๋ง "์ด๊ณผ" ๋๋ "์ฌ๊ฒํ ํ์"๋ผ๊ณ ์์ฑํด.
|
| 2016 |
- ๋ฐฐํฉ๊ธ์ง, ํ์ ํ์, ์๋ฃ ํ์ธ ํ์๋ ์ฌ๊ฒํ ๋์์ด๋ค.
|
|
|
|
| 2050 |
|
| 2051 |
results[item["target_id"]] = {
|
| 2052 |
"๋ํ INCI": inci_name or "-",
|
| 2053 |
+
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 2054 |
"๋น๊ณ ": "-",
|
| 2055 |
}
|
| 2056 |
|
|
|
|
| 2058 |
item["target_id"],
|
| 2059 |
country,
|
| 2060 |
comp,
|
| 2061 |
+
NO_EVIDENCE_TEXT,
|
| 2062 |
"NO_DB",
|
| 2063 |
"ํด๋น ๊ตญ๊ฐ/์ฑ๋ ๊ท์ DB ์์",
|
| 2064 |
)
|
|
|
|
| 2076 |
else:
|
| 2077 |
uncached_targets.append(item)
|
| 2078 |
|
| 2079 |
+
if not uncached_targets:
|
| 2080 |
+
return results
|
| 2081 |
+
|
| 2082 |
+
filtered_targets = []
|
| 2083 |
+
|
| 2084 |
+
for item in uncached_targets:
|
| 2085 |
+
material = item["material"]
|
| 2086 |
+
comp = item["component"]
|
| 2087 |
+
|
| 2088 |
+
inci_name = safe_str(comp.get("INCI Name", ""))
|
| 2089 |
+
korean_name = safe_str(comp.get("ํ๊ธ ์ฑ๋ถ๋ช
", ""))
|
| 2090 |
+
amount = comp.get("amount_float")
|
| 2091 |
+
amount_text = format_percent(amount) if amount is not None else "ํจ๋ ํ์ธ ํ์"
|
| 2092 |
+
|
| 2093 |
+
search_text = f"""
|
| 2094 |
+
๊ตญ๊ฐ/์ฑ๋: {country}
|
| 2095 |
+
์๋ฃ๋ช
๊ตญ๋ฌธ: {material.get("Trade name(๊ตญ๋ฌธ)", "")}
|
| 2096 |
+
์๋ฃ๋ช
์๋ฌธ: {material.get("Trade name(์๋ฌธ)", "")}
|
| 2097 |
+
๊ฒํ ์ฑ๋ถ ๊ตญ๋ฌธ: {korean_name}
|
| 2098 |
+
๊ฒํ ์ฑ๋ถ INCI/CAS: {inci_name}
|
| 2099 |
+
์ต์ข
์ ํ ๋ด ํจ๋: {amount_text}%
|
| 2100 |
+
"""
|
| 2101 |
+
|
| 2102 |
+
has_hit, context = has_meaningful_search_hit(
|
| 2103 |
+
db=db,
|
| 2104 |
+
search_text=search_text,
|
| 2105 |
+
ingredient_names=[inci_name, korean_name],
|
| 2106 |
+
k=MEANINGFUL_HIT_K,
|
| 2107 |
+
)
|
| 2108 |
+
|
| 2109 |
+
if has_hit:
|
| 2110 |
+
filtered_targets.append(item)
|
| 2111 |
+
else:
|
| 2112 |
+
result = {
|
| 2113 |
+
"๋ํ INCI": inci_name or "-",
|
| 2114 |
+
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 2115 |
+
"๋น๊ณ ": "-",
|
| 2116 |
+
}
|
| 2117 |
+
results[item["target_id"]] = result
|
| 2118 |
+
EVAL_CACHE[make_eval_cache_key(country, comp)] = result
|
| 2119 |
+
log_search_context(
|
| 2120 |
+
item["target_id"],
|
| 2121 |
+
country,
|
| 2122 |
+
comp,
|
| 2123 |
+
result["๊ฒฐ๊ณผ"],
|
| 2124 |
+
"NO_MEANINGFUL_HIT",
|
| 2125 |
+
context,
|
| 2126 |
+
)
|
| 2127 |
+
|
| 2128 |
+
uncached_targets = filtered_targets
|
| 2129 |
+
|
| 2130 |
if not uncached_targets:
|
| 2131 |
return results
|
| 2132 |
|
|
|
|
| 2172 |
[์ ๋ ๊ท์น]
|
| 2173 |
- ํ์ฌ ๊ฒํ ๊ตญ๊ฐ๋ "{country}"์ด๋ค.
|
| 2174 |
- ์๋ ๊ฒ์ ์๋ฌธ์ "{country}" ํด๋ ๋๋ ์ฑ๋์์๋ง ๊ฒ์๋ ๊ทผ๊ฑฐ๋ค.
|
| 2175 |
+
- ์ธ๋ถ ์ง์, ํ์ต ์ง์, ์ผ๋ฐ ๊ท์ ์ง์์ ์ฌ์ฉํ์ง ๋ง.
|
| 2176 |
+
- ๋ค๋ฅธ ๊ตญ๊ฐ ๊ท์ , EU Annex, ASEAN ์ฑํ ๊ท์ ์ ํ์ฌ ๊ตญ๊ฐ์ ์์ ์ ์ฉํ์ง ๋ง.
|
| 2177 |
- ํนํ EU ๊ท์ ์ ํ๊ตญ/์ผ๋ณธ/๋ฏธ๊ตญ/FDA/์ค๊ตญ์ ๋ณต์ฌ ์ ์ฉํ์ง ๋ง.
|
|
|
|
| 2178 |
- ๊ฒ์๋ "{country}" ์๋ฌธ์ ๋ช
์๋์ง ์์ ์ ํ, ๋ฐฐํฉ๊ธ์ง, ๋ฐฐํฉํ๋๋ ๋ง๋ค์ง ๋ง.
|
| 2179 |
+
- ๊ฒ์ ์๋ฌธ์ ๋ช
์๋ ์ ํ/๊ธ์ง/ํ๋ ๊ทผ๊ฑฐ๊ฐ ์์ผ๋ฉด ๊ฒฐ๊ณผ๋ ์ ํํ "{NO_EVIDENCE_TEXT}"์ผ๋ก ์์ฑํด.
|
| 2180 |
|
| 2181 |
[๊ฒํ ๋์ JSON]
|
| 2182 |
{json.dumps(target_payload, ensure_ascii=False, indent=2)}
|
|
|
|
| 2192 |
{{
|
| 2193 |
"target_id": "์
๋ ฅ target_id ๊ทธ๋๋ก",
|
| 2194 |
"๋ํ INCI": "๏ฟฝ๏ฟฝ๏ฟฝํ INCI ๋๋ -",
|
| 2195 |
+
"๊ฒฐ๊ณผ": "{NO_EVIDENCE_TEXT} ๋๋ ๊ท์ ๋ด์ฉ",
|
| 2196 |
"๋น๊ณ ": "-"
|
| 2197 |
}}
|
| 2198 |
]
|
|
|
|
| 2200 |
์์ฑ ์์น:
|
| 2201 |
- ๊ฒ์๋ ๊ท์ ์๋ฌธ์ ๊ทผ๊ฑฐ๊ฐ ์๋ ๋ด์ฉ๋ง ์์ฑํด.
|
| 2202 |
- ์๋ฌธ์ ๊ทผ๊ฑฐ๊ฐ ์๋๋ฐ ํน์ ํ๋๋ ๊ธ์ง ์ฌ๋ถ๋ฅผ ๋ง๋ค์ง ๋ง.
|
|
|
|
|
|
|
| 2203 |
- ํ์ฌ ํจ๋์ด ํ๋ ์ด๋ด๋ผ๋ฉด ๋ฐ๋์ "์ด๋ด(ํต๊ณผ)"๋ผ๊ณ ์์ฑํด.
|
| 2204 |
- ํ์ฌ ํจ๋์ด ํ๋๋ฅผ ์ด๊ณผํ ๋๋ง "์ด๊ณผ" ๋๋ "์ฌ๊ฒํ ํ์"๋ผ๊ณ ์์ฑํด.
|
| 2205 |
- ๋ฐฐํฉ๊ธ์ง, ํ์ ํ์, ์๋ฃ ํ์ธ ํ์๋ ์ฌ๊ฒํ ๋์์ด๋ค.
|
|
|
|
| 2640 |
" 2) Regulatory Screening Summary: ๋ฌธ์ ์๋ ์ฑ๋ถ๋ง ๊ตญ๊ฐ๋ณ ์์ฝ\n"
|
| 2641 |
" 3) Raw Search Log: ๋ก์ปฌ ๊ท์น/MFDS/GPT ๊ฒ์ ๊ทผ๊ฑฐ ๋ก๊ทธ\n"
|
| 2642 |
"- ํ์ ์ฐ์ ์์: ๋ก์ปฌ ๊ณ ์ ๊ท์น โ MFDS ์์ธ DB โ ๊ตญ๊ฐ๋ณ FAISS/GPT\n"
|
| 2643 |
+
"- GPT ํธ์ถ ์ ๊ฒ์ ์๋ฌธ์ ์ค์ ์ฑ๋ถ๋ช
์ด ์์ผ๋ฉด GPT๋ฅผ ํธ์ถํ์ง ์๊ณ 'ํด๋น ์๋ฃ ๋ด ์ ํ ๊ทผ๊ฑฐ ์์'์ผ๋ก ์ฒ๋ฆฌํฉ๋๋ค.\n"
|
| 2644 |
"- ๊ตญ๊ฐ๋ณ FAISS DB๋ฅผ ๋ถ๋ฆฌํด์ EU ๊ฒฐ๊ณผ๊ฐ ํ๊ตญ/์ผ๋ณธ/๋ฏธ๊ตญ์ผ๋ก ์๋ ํ์ฐ๋์ง ์๋๋ก ์์ ํ์ต๋๋ค.\n"
|
| 2645 |
"- public share link๊ฐ ์์ฑ๋๋๋ก share=True๋ก ์คํํฉ๋๋ค."
|
| 2646 |
)
|