jin2li commited on
Commit
78b05ab
ยท
verified ยท
1 Parent(s): 8de844f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +130 -103
app.py CHANGED
@@ -67,6 +67,7 @@ VECTOR_DB_CACHE = {}
67
  EVAL_CACHE = {}
68
  EMBEDDINGS_CACHE = None
69
  RAW_SEARCH_LOGS = []
 
70
 
71
  COUNTRY_ORDER = ["ASEAN","CALIFORNIA","CHINA","EU (FUTURE)","EU","FDA","JAPAN","KOREA","MEXICO","SEPHORA","TARGET","UK","ULTA"]
72
  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"}
@@ -766,17 +767,123 @@ def build_single_component_from_query(query, amount="", function="", single_amou
766
  return mat, comp, at
767
 
768
 
769
- def evaluate_component_from_country_files_only(country, material, component, target_id=""):
 
 
 
 
 
770
  """
771
- GPT ํŒ์ • ์—†์ด ์‚ฌ์šฉ์ž๊ฐ€ ์—…๋ฐ์ดํŠธํ•œ ๊ตญ๊ฐ€๋ณ„ ๊ทœ์ œ ํŒŒ์ผ๋งŒ ๊ฒ€์ƒ‰ํ•ด์„œ ํŒ์ •ํ•œ๋‹ค.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
772
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
773
  ์›์น™:
774
  1. ๊ธˆ์ง€ ์„ฑ๋ถ„์€ ํ•จ๋Ÿ‰ ์œ ๋ฌด์™€ ๋ฌด๊ด€ํ•˜๊ฒŒ ๋ฐฐํ•ฉ๊ธˆ์ง€
775
  2. ๋ฐฐํ•ฉํ•œ๋„๋Š” ์„ฑ๋ถ„๋ช…/INCI/CAS์™€ % ์ˆ˜์น˜๊ฐ€ ๊ฐ™์€ ๊ทผ์ฒ˜์—์„œ ๊ฒ€์ฆ๋  ๋•Œ๋งŒ ํ‘œ์‹œ
776
- 3. ํ˜„์žฌ ์„ฑ๋ถ„๋ช…/INCI/CAS๊ฐ€ ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ ๊ฒ€์ƒ‰ ์›๋ฌธ์— ์ง์ ‘ ์žˆ๋Š” ๊ฒฝ์šฐ๋งŒ ์ œํ•œ ๊ทผ๊ฑฐ๋กœ ์‚ฌ์šฉ
777
  4. ๊ทผ๊ฑฐ๊ฐ€ ์—†์œผ๋ฉด Pass / ํ•ด๋‹น ์ž๋ฃŒ ๋‚ด ์ œํ•œ ๊ทผ๊ฑฐ ์—†์Œ
778
  """
779
- db = build_database(country)
780
  country_col = display_country(country)
781
 
782
  inci_name = safe_str(component.get("INCI Name", ""))
@@ -819,55 +926,33 @@ def evaluate_component_from_country_files_only(country, material, component, tar
819
  )
820
  return result
821
 
822
- if not db:
 
 
823
  result = {
824
  "๋Œ€ํ‘œ INCI": representative,
825
  "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
826
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
827
- "๋น„๊ณ ": "ํ•ด๋‹น ๊ตญ๊ฐ€/์ฑ„๋„ ๊ทœ์ œ DB ์—†์Œ",
828
  }
829
  log_search_context(
830
  target_id,
831
  country,
832
  component,
833
  result["๊ฒฐ๊ณผ"],
834
- "COUNTRY_FILE_ONLY_NO_DB",
835
  result["๋น„๊ณ "],
836
  )
837
  return result
838
 
839
- search_text = f"""
840
- ๊ตญ๊ฐ€/์ฑ„๋„: {country}
841
- ๊ฒ€ํ†  ์„ฑ๋ถ„ ๊ตญ๋ฌธ: {korean_name}
842
- ๊ฒ€ํ†  ์„ฑ๋ถ„ INCI: {inci_name}
843
- CAS.No: {cas_no}
844
- """
845
-
846
- try:
847
- docs = db.similarity_search(search_text, k=8)
848
- context = "\n".join([d.page_content for d in docs])
849
- except Exception as e:
850
- result = {
851
- "๋Œ€ํ‘œ INCI": representative,
852
- "๊ฒฐ๊ณผ": "ํ™•์ธ ํ•„์š”",
853
- "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
854
- "๋น„๊ณ ": f"๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ ๊ฒ€์ƒ‰ ์‹คํŒจ: {e}",
855
- }
856
- log_search_context(
857
- target_id,
858
- country,
859
- component,
860
- result["๊ฒฐ๊ณผ"],
861
- "COUNTRY_FILE_ONLY_ERROR",
862
- str(e),
863
- )
864
- return result
865
-
866
- names = [inci_name, korean_name, cas_no]
867
- names_norm = [normalize_compact(x) for x in names if safe_str(x)]
868
- context_norm = normalize_compact(context)
869
 
870
- if not any(name and len(name) >= 3 and name in context_norm for name in names_norm):
871
  result = {
872
  "๋Œ€ํ‘œ INCI": representative,
873
  "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
@@ -879,8 +964,8 @@ CAS.No: {cas_no}
879
  country,
880
  component,
881
  result["๊ฒฐ๊ณผ"],
882
- "COUNTRY_FILE_ONLY_NO_HIT",
883
- context,
884
  )
885
  return result
886
 
@@ -934,7 +1019,7 @@ CAS.No: {cas_no}
934
  country,
935
  component,
936
  result["๊ฒฐ๊ณผ"],
937
- "COUNTRY_FILE_ONLY_PROHIBITED",
938
  context,
939
  )
940
  return result
@@ -956,7 +1041,7 @@ CAS.No: {cas_no}
956
  country,
957
  component,
958
  result["๊ฒฐ๊ณผ"],
959
- "COUNTRY_FILE_ONLY_LIMIT",
960
  context,
961
  )
962
  return result
@@ -1003,7 +1088,7 @@ CAS.No: {cas_no}
1003
  country,
1004
  component,
1005
  result["๊ฒฐ๊ณผ"],
1006
- "COUNTRY_FILE_ONLY_RESTRICTION",
1007
  context,
1008
  )
1009
  return result
@@ -1019,70 +1104,12 @@ CAS.No: {cas_no}
1019
  country,
1020
  component,
1021
  result["๊ฒฐ๊ณผ"],
1022
- "COUNTRY_FILE_ONLY_NO_RESTRICTION",
1023
  context,
1024
  )
1025
  return result
1026
 
1027
 
1028
-
1029
- def make_single_display_result(final_result, country_col="", component=None):
1030
- """
1031
- ๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ ํ‘œ์˜ '๋ฐฐํ•ฉํ•œ๋„/๊ธˆ์ง€' ์นธ์— ๋“ค์–ด๊ฐˆ ์งง์€ ํ‘œ์‹œ๋ฌธ๊ตฌ๋ฅผ ๋งŒ๋“ ๋‹ค.
1032
- """
1033
- component = component or {}
1034
-
1035
- result_text = safe_str(final_result.get("๊ฒฐ๊ณผ", ""))
1036
- display_text = safe_str(final_result.get("ํ‘œ์‹œ๋ฌธ๊ตฌ", ""))
1037
- inci_name = safe_str(component.get("INCI Name", ""))
1038
-
1039
- if display_text:
1040
- cleaned_display = normalize_formula_country_text(
1041
- display_text,
1042
- country_col=country_col,
1043
- inci_name=inci_name,
1044
- amount_text=safe_str(component.get("In formula(w/w %)", "")),
1045
- )
1046
-
1047
- if cleaned_display:
1048
- return cleaned_display
1049
-
1050
- cleaned_result = normalize_formula_country_text(
1051
- result_text,
1052
- country_col=country_col,
1053
- inci_name=inci_name,
1054
- amount_text=safe_str(component.get("In formula(w/w %)", "")),
1055
- )
1056
-
1057
- if cleaned_result:
1058
- return cleaned_result
1059
-
1060
- return NEED_CHECK_TEXT
1061
-
1062
-
1063
-
1064
- def simplify_single_note(note):
1065
- """
1066
- ๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ์˜ ๋น„๊ณ ๋ฅผ ๋„ˆ๋ฌด ๊ธธ์ง€ ์•Š๊ฒŒ ์ •๋ฆฌํ•œ๋‹ค.
1067
- """
1068
- note = safe_str(note)
1069
-
1070
- if not note or note == "-":
1071
- return ""
1072
-
1073
- replace_map = {
1074
- "๋กœ์ปฌ ์ œํ•œ์„ฑ๋ถ„ ๋ชฉ๋ก์—๋Š” ์žˆ์œผ๋‚˜ ํ•ด๋‹น ๊ตญ๊ฐ€ ํ•œ๋„๊ฐ’ ๋ฏธ๋“ฑ๋ก. Pass ์ฒ˜๋ฆฌ ๊ธˆ์ง€.": "ํ•ด๋‹น ๊ตญ๊ฐ€ ํ•œ๋„๊ฐ’ ๋ฏธ๋“ฑ๋ก",
1075
- "๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด ์„ฑ๋ถ„์ด๋ฏ€๋กœ ๊ทผ๊ฑฐ ๋ฏธ๊ฒ€์ถœ๋งŒ์œผ๋กœ Pass ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์Œ": "๊ทผ๊ฑฐ ๋ฏธ๊ฒ€์ถœ, ํ™•์ธ ํ•„์š”",
1076
- "๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด์ด๋‚˜ ๊ตญ๊ฐ€๋ณ„ ๊ทœ์ œํŒŒ์ผ์—์„œ ์ง์ ‘ ๊ทผ๊ฑฐ ๋ฏธ๊ฒ€์ถœ. Pass ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์Œ.": "๊ตญ๊ฐ€๋ณ„ ๊ทœ์ œํŒŒ์ผ ๋‚ด ์ง์ ‘ ๊ทผ๊ฑฐ ๋ฏธ๊ฒ€์ถœ",
1077
- "ํ•ด๋‹น ๊ตญ๊ฐ€/์ฑ„๋„ ๊ทœ์ œ DB ์—†์Œ. ๊ณ ์œ„ํ—˜๊ตฐ ํ›„๋ณด์ด๋ฏ€๋กœ Pass ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์Œ.": "ํ•ด๋‹น ๊ตญ๊ฐ€ ๊ทœ์ œ DB ์—†์Œ",
1078
- "ํ–ฅ๋ฃŒ๋Š” ์„ธ๋ถ€ ๊ตฌ์„ฑ์„ฑ๋ถ„ ๋ฐ ์•Œ๋ ˆ๋ฅด๊ฒ ํ‘œ์‹œ๋Œ€์ƒ ์—ฌ๋ถ€ ํ™•์ธ ํ•„์š”. ์ž๋™ Pass ์ฒ˜๋ฆฌ ๊ธˆ์ง€.": "ํ–ฅ๋ฃŒ ์„ธ๋ถ€ ์กฐ์„ฑ ๋ฐ ์•Œ๋ ˆ๋ฅด๊ฒ ํ™•์ธ ํ•„์š”",
1079
- "์ •์ œ์ˆ˜/Water/Aqua ๊ธฐ๋ณธ Pass ์ฒ˜๋ฆฌ": "์ •์ œ์ˆ˜/Water/Aqua ๊ธฐ๋ณธ Pass ์ฒ˜๋ฆฌ",
1080
- "์ผ๋ณธ ์ˆ˜์ถœ์šฉ ์ œํ’ˆ ์‚ฌ์šฉ ๋ถˆ๊ฐ€ ์—ฌ๋ถ€ ํ™•์ธ ํ•„์š”": "์ผ๋ณธ ์ˆ˜์ถœ์šฉ ์ œํ’ˆ ์‚ฌ์šฉ ๋ถˆ๊ฐ€ ์—ฌ๋ถ€ ํ™•์ธ ํ•„์š”",
1081
- }
1082
-
1083
- return replace_map.get(note, note)
1084
-
1085
-
1086
  def process_single_ingredient(
1087
  countries,
1088
  single_query,
@@ -1291,7 +1318,7 @@ def process_single_ingredient(
1291
  f"- ์„ ํƒ ๊ตญ๊ฐ€ ์ˆ˜: {len(countries)}๊ฐœ\n"
1292
  f"- MFDS ์ƒํƒœ: {mfds_live_msg}\n"
1293
  f"- MFDS ์กฐํšŒ ๋Œ€์ƒ: {', '.join(terms) if terms else '์—†์Œ'}\n"
1294
- "- ํŒ์ • ๋ฐฉ์‹: GPT ํŒ์ • ์—†์Œ, ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ๊ณผ ์‹์•ฝ์ฒ˜ ๊ฒฐ๊ณผ๋งŒ ์‚ฌ์šฉ\n"
1295
  "- ๊ธˆ์ง€ ์„ฑ๋ถ„: ํ•จ๋Ÿ‰ ์œ ๋ฌด์™€ ๋ฌด๊ด€ํ•˜๊ฒŒ ๋ฐฐํ•ฉ๊ธˆ์ง€ ์šฐ์„  ํ‘œ์‹œ\n"
1296
  )
1297
  return result_df, msg
 
67
  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"}
 
767
  return mat, comp, at
768
 
769
 
770
+
771
+ def get_country_regulatory_text_cached(country):
772
+ """
773
+ ๋‹จ์ผ ์„ฑ๋ถ„/ํŒŒ์ผ ๊ธฐ๋ฐ˜ ๊ฒ€์ƒ‰ ์†๋„ ๊ฐœ์„ ์šฉ.
774
+ FAISS/์ž„๋ฒ ๋”ฉ์„ ๋งŒ๋“ค์ง€ ์•Š๊ณ  ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ ์›๋ฌธ์„ ์ง์ ‘ ์ฝ์–ด์„œ ์บ์‹œํ•œ๋‹ค.
775
+ ์ฒซ ๊ฒ€์ƒ‰์€ ํŒŒ์ผ์„ ์ฝ๋А๋ผ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆด ์ˆ˜ ์žˆ์ง€๋งŒ, ๊ฐ™์€ ์•ฑ ์„ธ์…˜์˜ ๋‹ค์Œ ๊ฒ€์ƒ‰๋ถ€ํ„ฐ๋Š” ์บ์‹œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
776
  """
777
+ global REG_TEXT_CACHE
778
+
779
+ folder = resolve_country_folder(country)
780
+
781
+ if not folder or not os.path.isdir(folder):
782
+ return "", "ํ•ด๋‹น ๊ตญ๊ฐ€/์ฑ„๋„ ํด๋” ์—†์Œ"
783
+
784
+ files = get_regulatory_file_list(folder)
785
+
786
+ if not files:
787
+ return "", "ํ•ด๋‹น ๊ตญ๊ฐ€/์ฑ„๋„ ๊ทœ์ œ ํŒŒ์ผ ์—†์Œ"
788
+
789
+ signature = tuple((f["relative_path"], f["size"], f["mtime_ns"]) for f in files)
790
+ sig_hash = stable_hash(signature)
791
+ cache_key = f"{folder}|{sig_hash}"
792
+
793
+ cached = REG_TEXT_CACHE.get(cache_key)
794
+
795
+ if cached is not None:
796
+ return cached, "CACHE"
797
+
798
+ text_blocks = []
799
 
800
+ for item in files:
801
+ try:
802
+ raw = extract_text_from_regulatory_file(item)
803
+
804
+ if raw:
805
+ text_blocks.append(
806
+ f"[๊ตญ๊ฐ€/์ฑ„๋„: {folder}] [์ถœ์ฒ˜ํŒŒ์ผ: {item['relative_path']}]\n{raw}"
807
+ )
808
+ except Exception as e:
809
+ text_blocks.append(
810
+ f"[๊ตญ๊ฐ€/์ฑ„๋„: {folder}] [์ถœ์ฒ˜ํŒŒ์ผ: {item.get('relative_path', '')}] ํŒŒ์ผ ์ฝ๊ธฐ ์‹คํŒจ: {e}"
811
+ )
812
+
813
+ combined = "\n\n".join(text_blocks)
814
+ REG_TEXT_CACHE[cache_key] = combined
815
+
816
+ return combined, "READ_FILES"
817
+
818
+
819
+ def extract_relevant_context_direct(raw_text, ingredient_names, window=2, max_blocks=12):
820
+ """
821
+ ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ ์›๋ฌธ์—์„œ ํ˜„์žฌ ์„ฑ๋ถ„๋ช…/INCI/CAS๊ฐ€ ์ง์ ‘ ๋“ค์–ด๊ฐ„ ๋ฌธ๋‹จ๋งŒ ๋น ๋ฅด๊ฒŒ ์ถ”์ถœํ•œ๋‹ค.
822
+ """
823
+ raw_text = safe_str(raw_text)
824
+
825
+ if not raw_text:
826
+ return "", False
827
+
828
+ names_norm = [
829
+ normalize_compact(x)
830
+ for x in ingredient_names
831
+ if safe_str(x) and len(normalize_compact(x)) >= 3
832
+ ]
833
+
834
+ if not names_norm:
835
+ return "", False
836
+
837
+ # ํŒŒ์ผ/์‹œํŠธ/ํŽ˜์ด์ง€ ๊ตฌ๋ถ„๊ณผ ์ค„ ๋‹จ์œ„ ๊ฒ€์ƒ‰์„ ๊ฐ™์ด ์“ฐ๊ธฐ ์œ„ํ•ด ๋„ˆ๋ฌด ์งง์€ ์ค„์€ ์ฃผ๋ณ€ ๋ฌธ๋งฅ๊ณผ ํ•ฉ์นœ๋‹ค.
838
+ rough_blocks = re.split(r"[\n\r]+", raw_text)
839
+ rough_blocks = [safe_str(x) for x in rough_blocks if safe_str(x)]
840
+
841
+ hit_indices = []
842
+
843
+ for idx, block in enumerate(rough_blocks):
844
+ block_norm = normalize_compact(block)
845
+
846
+ if any(name in block_norm for name in names_norm):
847
+ hit_indices.append(idx)
848
+
849
+ if len(hit_indices) >= max_blocks:
850
+ break
851
+
852
+ if not hit_indices:
853
+ return "", False
854
+
855
+ selected = []
856
+ seen = set()
857
+
858
+ for idx in hit_indices:
859
+ start = max(0, idx - window)
860
+ end = min(len(rough_blocks), idx + window + 1)
861
+
862
+ for j in range(start, end):
863
+ if j in seen:
864
+ continue
865
+
866
+ seen.add(j)
867
+ selected.append(rough_blocks[j])
868
+
869
+ context = "\n".join(selected)
870
+
871
+ return context[:8000], True
872
+
873
+
874
+
875
+ def evaluate_component_from_country_files_only(country, material, component, target_id=""):
876
+ """
877
+ GPT ํŒ์ • ์—†์ด ์‚ฌ์šฉ์ž๊ฐ€ ์—…๋ฐ์ดํŠธํ•œ ๊ตญ๊ฐ€๋ณ„ ๊ทœ์ œ ํŒŒ์ผ๋งŒ ์ง์ ‘ ๊ฒ€์ƒ‰ํ•ด์„œ ํŒ์ •ํ•œ๋‹ค.
878
+ ์†๋„ ๊ฐœ์„ :
879
+ - ๋‹จ์ผ ์„ฑ๋ถ„์—์„œ FAISS/์ž„๋ฒ ๋”ฉ ์ƒ์„ฑ ์—†์ด ์›๋ฌธ ์ง์ ‘ ๊ฒ€์ƒ‰
880
+ - ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ ์›๋ฌธ์€ ์•ฑ ์„ธ์…˜ ๋™์•ˆ ์บ์‹œ
881
  ์›์น™:
882
  1. ๊ธˆ์ง€ ์„ฑ๋ถ„์€ ํ•จ๋Ÿ‰ ์œ ๋ฌด์™€ ๋ฌด๊ด€ํ•˜๊ฒŒ ๋ฐฐํ•ฉ๊ธˆ์ง€
883
  2. ๋ฐฐํ•ฉํ•œ๋„๋Š” ์„ฑ๋ถ„๋ช…/INCI/CAS์™€ % ์ˆ˜์น˜๊ฐ€ ๊ฐ™์€ ๊ทผ์ฒ˜์—์„œ ๊ฒ€์ฆ๋  ๋•Œ๋งŒ ํ‘œ์‹œ
884
+ 3. ํ˜„์žฌ ์„ฑ๋ถ„๋ช…/INCI/CAS๊ฐ€ ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ ์›๋ฌธ์— ์ง์ ‘ ์žˆ๋Š” ๊ฒฝ์šฐ๋งŒ ์ œํ•œ ๊ทผ๊ฑฐ๋กœ ์‚ฌ์šฉ
885
  4. ๊ทผ๊ฑฐ๊ฐ€ ์—†์œผ๋ฉด Pass / ํ•ด๋‹น ์ž๋ฃŒ ๋‚ด ์ œํ•œ ๊ทผ๊ฑฐ ์—†์Œ
886
  """
 
887
  country_col = display_country(country)
888
 
889
  inci_name = safe_str(component.get("INCI Name", ""))
 
926
  )
927
  return result
928
 
929
+ raw_text, cache_status = get_country_regulatory_text_cached(country)
930
+
931
+ if not raw_text:
932
  result = {
933
  "๋Œ€ํ‘œ INCI": representative,
934
  "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
935
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
936
+ "๋น„๊ณ ": cache_status or "ํ•ด๋‹น ๊ตญ๊ฐ€/์ฑ„๋„ ๊ทœ์ œ DB ์—†์Œ",
937
  }
938
  log_search_context(
939
  target_id,
940
  country,
941
  component,
942
  result["๊ฒฐ๊ณผ"],
943
+ "COUNTRY_FILE_DIRECT_NO_DB",
944
  result["๋น„๊ณ "],
945
  )
946
  return result
947
 
948
+ context, has_hit = extract_relevant_context_direct(
949
+ raw_text=raw_text,
950
+ ingredient_names=[inci_name, korean_name, cas_no],
951
+ window=2,
952
+ max_blocks=16,
953
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
954
 
955
+ if not has_hit:
956
  result = {
957
  "๋Œ€ํ‘œ INCI": representative,
958
  "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
 
964
  country,
965
  component,
966
  result["๊ฒฐ๊ณผ"],
967
+ "COUNTRY_FILE_DIRECT_NO_HIT",
968
+ f"cache_status={cache_status}",
969
  )
970
  return result
971
 
 
1019
  country,
1020
  component,
1021
  result["๊ฒฐ๊ณผ"],
1022
+ "COUNTRY_FILE_DIRECT_PROHIBITED",
1023
  context,
1024
  )
1025
  return result
 
1041
  country,
1042
  component,
1043
  result["๊ฒฐ๊ณผ"],
1044
+ "COUNTRY_FILE_DIRECT_LIMIT",
1045
  context,
1046
  )
1047
  return result
 
1088
  country,
1089
  component,
1090
  result["๊ฒฐ๊ณผ"],
1091
+ "COUNTRY_FILE_DIRECT_RESTRICTION",
1092
  context,
1093
  )
1094
  return result
 
1104
  country,
1105
  component,
1106
  result["๊ฒฐ๊ณผ"],
1107
+ "COUNTRY_FILE_DIRECT_NO_RESTRICTION",
1108
  context,
1109
  )
1110
  return result
1111
 
1112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1113
  def process_single_ingredient(
1114
  countries,
1115
  single_query,
 
1318
  f"- ์„ ํƒ ๊ตญ๊ฐ€ ์ˆ˜: {len(countries)}๊ฐœ\n"
1319
  f"- MFDS ์ƒํƒœ: {mfds_live_msg}\n"
1320
  f"- MFDS ์กฐํšŒ ๋Œ€์ƒ: {', '.join(terms) if terms else '์—†์Œ'}\n"
1321
+ "- ํŒ์ • ๋ฐฉ์‹: GPT ํŒ์ • ์—†์Œ, ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ ์ง์ ‘๊ฒ€์ƒ‰ + ์‹์•ฝ์ฒ˜ ์ฒดํฌ ON ์‹œ ์‹ค์‹œ๊ฐ„ ๊ฒฐ๊ณผ ์‚ฌ์šฉ\n"
1322
  "- ๊ธˆ์ง€ ์„ฑ๋ถ„: ํ•จ๋Ÿ‰ ์œ ๋ฌด์™€ ๋ฌด๊ด€ํ•˜๊ฒŒ ๋ฐฐํ•ฉ๊ธˆ์ง€ ์šฐ์„  ํ‘œ์‹œ\n"
1323
  )
1324
  return result_df, msg