jin2li commited on
Commit
e4fdf3a
ยท
verified ยท
1 Parent(s): 8f17412

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +121 -89
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  # APP_PATCH_NOTE_LIMIT_POSITIVE_MFDS = "Positive List ํ•œ๋„ํ™•์ธ + MFDS ์ œํ•œ ํŒŒ์‹ฑ ๋ณด๊ฐ• ์ ์šฉ๋ณธ"
2
  # ============================================================
3
  # reBom Regulatory Screening AI - Fast Grounded Fixed Version
@@ -37,6 +38,7 @@
37
  import os, re, json, base64, hashlib, traceback, sqlite3, secrets, datetime, time, sys, subprocess, time
38
  from pathlib import Path
39
  from collections import defaultdict
 
40
  import pandas as pd
41
  import pdfplumber
42
  import gradio as gr
@@ -74,9 +76,16 @@ NO_EVIDENCE_TEXT = "ํ•ด๋‹น ์ž๋ฃŒ ๋‚ด ์ œํ•œ ๊ทผ๊ฑฐ ์—†์Œ"
74
  NEED_CHECK_TEXT = "ํ™•์ธ ํ•„์š”"
75
  LIMIT_CHECK_TEXT = "๋ฐฐํ•ฉํ•œ๋„ ํ™•์ธ ํ•„์š”"
76
  MFDS_LIVE_URL = "https://nedrug.mfds.go.kr/pbp/CCBDF01"
77
- MFDS_RETRY_COUNT = int(os.getenv("MFDS_RETRY_COUNT", "2"))
78
- MFDS_RETRY_WAIT_SEC = float(os.getenv("MFDS_RETRY_WAIT_SEC", "2.0"))
79
- MFDS_BETWEEN_TERMS_WAIT_SEC = float(os.getenv("MFDS_BETWEEN_TERMS_WAIT_SEC", "1.5"))
 
 
 
 
 
 
 
80
  VECTOR_DB_CACHE = {}
81
  EVAL_CACHE = {}
82
  EMBEDDINGS_CACHE = None
@@ -188,6 +197,7 @@ def get_identity_raw(material, component):
188
  def get_identity_text(material,component):
189
  return normalize_text(get_identity_raw(material, component))
190
 
 
191
  def normalized_tokens(text):
192
  """
193
  ์„ฑ๋ถ„๋ช… ๋น„๊ต์šฉ ํ† ํฐํ™”.
@@ -196,6 +206,7 @@ def normalized_tokens(text):
196
  text = safe_str(text).lower().replace("ฮฑ", "alpha").replace("ฮฒ", "beta")
197
  return [t for t in re.split(r"[^a-z0-9๊ฐ€-ํžฃใ-ใ‚“ใ‚ก-ใƒณไธ€-้พฅ]+", text) if t]
198
 
 
199
  def exact_ingredient_match(term, target_text):
200
  """
201
  ์„ฑ๋ถ„๋ช…/alias๊ฐ€ target_text ์•ˆ์—์„œ ๋…๋ฆฝ ํ† ํฐ์œผ๋กœ ์กด์žฌํ•  ๋•Œ๋งŒ True.
@@ -738,15 +749,15 @@ def registry_terms_for_component(material=None, component=None, extra_terms=None
738
  material.get("Trade name(์˜๋ฌธ)", ""),
739
  ] + list(extra_terms or [])
740
 
741
- identity_raw = " ".join(safe_str(x) for x in identity_values if safe_str(x))
742
 
743
  hits = []
744
 
745
  for entry in REGULATORY_SYNONYM_REGISTRY:
746
  terms = entry.get("terms", [])
 
747
 
748
- # ๋ถ€๋ถ„ ๋ฌธ์ž์—ด ๋งค์นญ ๊ธˆ์ง€: biotin์ด meabiotin/biotinate์— ๊ฑธ๋ฆฌ๋Š” ๋ฌธ์ œ ๋ฐฉ์ง€
749
- if any(exact_ingredient_match(t, identity_raw) for t in terms if safe_str(t)):
750
  for t in terms:
751
  if safe_str(t) and t not in hits:
752
  hits.append(safe_str(t))
@@ -768,17 +779,17 @@ def registry_direct_regulation_fallback(country, material, component, target_id=
768
  country_col = display_country(country)
769
  representative = safe_str(component.get("INCI Name", "")) or safe_str(component.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", "")) or registry_terms[0]
770
 
771
- registry_terms = [
772
- safe_str(t)
773
  for t in registry_terms
774
  if safe_str(t) and len(normalize_compact(t)) >= 3
775
  ]
776
 
777
  for section in sections:
778
  text = safe_str(section.get("text", ""))
 
779
 
780
- # ๋ถ€๋ถ„ ๋ฌธ์ž์—ด ๋งค์นญ ๊ธˆ์ง€
781
- if not any(exact_ingredient_match(t, text) for t in registry_terms):
782
  continue
783
 
784
  header = safe_str(section.get("header", ""))
@@ -791,7 +802,8 @@ def registry_direct_regulation_fallback(country, material, component, target_id=
791
  seen = set()
792
 
793
  for idx, line in enumerate(lines):
794
- if any(exact_ingredient_match(t, line) for t in registry_terms):
 
795
  for j in range(max(0, idx - 5), min(len(lines), idx + 6)):
796
  if j not in seen:
797
  seen.add(j)
@@ -954,12 +966,13 @@ def find_chemical_variant_match_in_country_text(country, material, component, ta
954
 
955
  for section in sections:
956
  text = safe_str(section.get("text", ""))
 
957
  header = safe_str(section.get("header", ""))
958
  reg_type = infer_regulation_type_from_source_text(header + "\n" + text[:1500], country=country)
959
  reg_kind = reg_type.get("type", "unknown")
960
  reg_label = reg_type.get("label", "๊ทœ์ œ ์œ ํ˜• ๋ฏธ๋ถ„๋ฅ˜")
961
 
962
- hit_terms = [v for v in expanded if exact_ingredient_match(v, text)]
963
  if not hit_terms:
964
  continue
965
 
@@ -968,7 +981,8 @@ def find_chemical_variant_match_in_country_text(country, material, component, ta
968
  seen = set()
969
 
970
  for idx, line in enumerate(lines):
971
- if any(exact_ingredient_match(v, line) for v in hit_terms):
 
972
  for j in range(max(0, idx - 4), min(len(lines), idx + 5)):
973
  if j not in seen:
974
  seen.add(j)
@@ -1338,16 +1352,27 @@ def make_grouped_materials(df):
1338
  return mats,{"cols":cols,"cleaned_df":clean,"ingredient_totals":defaultdict(float),"ingredient_amount_parts":defaultdict(list)}
1339
 
1340
  # MFDS simplified: disabled-safe placeholder; keep UI compatibility
1341
- def extract_terms_for_live_lookup(row_items):
 
 
 
 
 
1342
  terms=[]
1343
  for item in row_items:
1344
  m=item["material"]; c=item["component"]
1345
- if is_plain_fragrance_component(m,c) or is_always_pass_component(m,c): continue
 
1346
  for v in [c.get("INCI Name",""),c.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…",""),c.get("CAS.No","")]:
1347
- if safe_str(v): terms.append(safe_str(v)); break
 
 
1348
  seen=[]
1349
  for t in terms:
1350
- if t not in seen: seen.append(t)
 
 
 
1351
  return seen
1352
 
1353
  def mfds_visible_text(page):
@@ -1468,8 +1493,9 @@ def mfds_click_probable_result(page, term):
1468
  except Exception:
1469
  continue
1470
 
1471
- # ๋ถ€๋ถ„ ๋ฌธ์ž์—ด ํด๋ฆญ ๊ธˆ์ง€: biotin ๊ฒ€์ƒ‰ ์‹œ MEA-Biotinate ๊ฒฐ๊ณผ ํด๋ฆญ ๋ฐฉ์ง€
1472
- if exact_ingredient_match(term, row_text):
 
1473
  row.click(timeout=3000)
1474
  page.wait_for_timeout(1000)
1475
  return True
@@ -1733,8 +1759,7 @@ def mfds_lookup_one_term_with_retry(page, term):
1733
  return [], ""
1734
 
1735
  # ๊ฒ€์ƒ‰์–ด๊ฐ€ ํ™”๋ฉด์— ์žˆ์ง€๋งŒ ๊ทœ์ œ ํ•„๋“œ๊ฐ€ ์—†์œผ๋ฉด ์ผ๋ฐ˜ ์›๋ฃŒ ์ƒ์„ธ/๋ฌด๊ทœ์ œ ๊ฒฐ๊ณผ๋กœ ํŒ๋‹จ
1736
- # ๋‹จ, ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์€ ๊ธˆ์ง€: biotin์ด meabiotin/biotinate์— ๊ฑธ๋ฆฌ๋ฉด ์•ˆ ๋จ
1737
- if exact_ingredient_match(term, body_text):
1738
  return [], ""
1739
 
1740
  if not clicked:
@@ -1812,12 +1837,12 @@ def mfds_try_install_chromium_once():
1812
  return False, str(e)
1813
 
1814
 
1815
- def mfds_live_lookup_terms(terms, max_terms=30, headless=True):
1816
  if not PLAYWRIGHT_AVAILABLE or sync_playwright is None:
1817
  return pd.DataFrame(), "MFDS ์‹ค์‹œ๊ฐ„ ์กฐํšŒ ์‹คํŒจ: playwright ํŒจํ‚ค์ง€ ๋ฏธ์„ค์น˜"
1818
 
1819
  terms = [safe_str(t) for t in terms if safe_str(t)]
1820
- terms = terms[:int(max_terms)] if max_terms else terms[:30]
1821
 
1822
  all_rows = []
1823
  errors = []
@@ -2100,7 +2125,7 @@ def build_integrated_result(rd,country_cols):
2100
  issues=[cc for cc in country_cols if is_country_result_issue(rd.get(cc,""))]
2101
  return "PASS" if not issues else "์žฌ๊ฒ€ํ†  ํ•„์š”: "+", ".join(issues)
2102
 
2103
- def process(countries,file,product_name="",use_mfds_live=False,live_max_terms=30,live_headless=True):
2104
  """
2105
  ์ „์„ฑ๋ถ„ ์ „์ฒด ์Šคํฌ๋ฆฌ๋‹ ๊ณ ์† ๋ฒ„์ „.
2106
 
@@ -2108,7 +2133,7 @@ def process(countries,file,product_name="",use_mfds_live=False,live_max_terms=30
2108
  - ์ „์ฒด ์Šคํฌ๋ฆฌ๋‹์—์„œ GPT/LLM ํ˜ธ์ถœ ์ œ๊ฑฐ
2109
  - ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ ์ง์ ‘ ๊ฒ€์ƒ‰(COUNTRY_FILE_FAST) ์šฐ์„ 
2110
  - ์„ ํƒ ๊ตญ๊ฐ€๋ณ„ ์„น์…˜ ์ธ๋ฑ์Šค 1ํšŒ ์›Œ๋ฐ์—…
2111
- - ์‹์•ฝ์ฒ˜ ์‹ค์‹œ๊ฐ„ ์กฐํšŒ๋Š” ์ฒดํฌ ON์ผ ๋•Œ๋งŒ ์‚ฌ์šฉ
2112
  """
2113
  global RAW_SEARCH_LOGS
2114
  RAW_SEARCH_LOGS = []
@@ -2154,12 +2179,20 @@ def process(countries,file,product_name="",use_mfds_live=False,live_max_terms=30
2154
  except Exception as e:
2155
  index_messages.append(f"{display_country(country)}=index error: {e}")
2156
 
2157
- terms = extract_terms_for_live_lookup(row_items)
 
 
 
 
2158
  mfds_df = pd.DataFrame()
2159
  mfds_msg = "์‚ฌ์šฉ ์•ˆ ํ•จ"
2160
 
 
 
 
2161
  if use_mfds_live:
2162
- mfds_df, mfds_msg = mfds_live_lookup_terms(terms, live_max_terms, True)
 
2163
 
2164
  for country in countries:
2165
  col = display_country(country)
@@ -2694,38 +2727,37 @@ def get_country_section_index_cached(country):
2694
  def find_matching_regulatory_sections_fast(country, ingredient_names, max_sections=30):
2695
  """
2696
  ๊ณ ์† ๋‹จ์ผ ๊ฒ€์ƒ‰.
2697
- ์„ฑ๋ถ„๋ช…/INCI/CAS๋ฅผ ๊ตญ๊ฐ€๋ณ„ ์„น์…˜ ์ธ๋ฑ์Šค์—์„œ ์ง์ ‘ ๊ฒ€์ƒ‰ํ•œ๋‹ค.
2698
-
2699
- ์ค‘์š”:
2700
- - normalize_compact ๊ธฐ๋ฐ˜ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด ๊ฒ€์ƒ‰์„ ์“ฐ์ง€ ์•Š๋Š”๋‹ค.
2701
- - Biotin ๊ฒ€์ƒ‰ ์‹œ MEA-Biotinate, Biotinate, Biotinyl- ๊ณ„์—ด์„ Biotin์œผ๋กœ ์˜ค์ธํ•˜์ง€ ์•Š๋Š”๋‹ค.
2702
  """
2703
  sections, status = get_country_section_index_cached(country)
2704
 
2705
- names = [
2706
- safe_str(x)
2707
  for x in ingredient_names
2708
- if safe_str(x) and len(normalize_compact(x)) >= 3 and not is_broad_lookup_term(x)
2709
  ]
2710
 
2711
- if not names:
2712
  return [], status
2713
 
2714
  matches = []
2715
 
2716
  for section in sections:
2717
- text = safe_str(section.get("text", ""))
2718
 
2719
- if not any(exact_ingredient_match(name, text) for name in names):
2720
  continue
2721
 
 
2722
  header = safe_str(section.get("header", ""))
2723
  lines = [safe_str(x) for x in text.splitlines() if safe_str(x)]
2724
 
2725
  hit_indices = []
2726
 
2727
  for idx, line in enumerate(lines):
2728
- if any(exact_ingredient_match(name, line) for name in names):
 
 
2729
  hit_indices.append(idx)
2730
 
2731
  if len(hit_indices) >= 10:
@@ -2750,6 +2782,7 @@ def find_matching_regulatory_sections_fast(country, ingredient_names, max_sectio
2750
  else:
2751
  context = header + "\n" + text[:2000]
2752
 
 
2753
  reg_type = infer_regulation_type_from_source_text(
2754
  header + "\n" + text[:1500],
2755
  country=country,
@@ -2766,62 +2799,65 @@ def find_matching_regulatory_sections_fast(country, ingredient_names, max_sectio
2766
 
2767
  return matches, status
2768
 
 
2769
  def find_matching_regulatory_sections(raw_text, ingredient_names, max_sections=20):
2770
  """
2771
- ๊ตฌ๋ฒ„์ „ ํ˜ธํ™˜์šฉ. ๋ถ€๋ถ„ ๋ฌธ์ž์—ด ๊ฒ€์ƒ‰ ๊ธˆ์ง€.
2772
  """
2773
- names = [
2774
- safe_str(x)
2775
  for x in ingredient_names
2776
- if safe_str(x) and len(normalize_compact(x)) >= 3 and not is_broad_lookup_term(x)
2777
  ]
2778
 
2779
- if not names:
2780
  return []
2781
 
2782
  matches = []
2783
 
2784
  for section in split_regulatory_text_into_sections(raw_text):
2785
  text = section["text"]
 
2786
 
2787
- if not any(exact_ingredient_match(name, text) for name in names):
2788
- continue
 
2789
 
2790
- lines = [safe_str(x) for x in text.splitlines() if safe_str(x)]
2791
- hit_indices = []
2792
 
2793
- for idx, line in enumerate(lines):
2794
- if any(exact_ingredient_match(name, line) for name in names):
2795
- hit_indices.append(idx)
2796
 
2797
- context_lines = []
2798
- seen = set()
2799
 
2800
- for idx in hit_indices[:8]:
2801
- start = max(0, idx - 4)
2802
- end = min(len(lines), idx + 5)
2803
 
2804
- for j in range(start, end):
2805
- if j in seen:
2806
- continue
2807
 
2808
- seen.add(j)
2809
- context_lines.append(lines[j])
2810
 
2811
- context = section["header"] + "\n" + "\n".join(context_lines)
2812
- reg_type = infer_regulation_type_from_source_text(section["header"] + "\n" + text[:1200], country="")
2813
 
2814
- matches.append({
2815
- "header": section["header"],
2816
- "context": context[:8000],
2817
- "regulation_type": reg_type,
2818
- })
2819
 
2820
- if len(matches) >= max_sections:
2821
- break
2822
 
2823
  return matches
2824
 
 
2825
  def pick_best_regulatory_match(matches):
2826
  """
2827
  ์—ฌ๋Ÿฌ ํŒŒ์ผ์—์„œ ๋™์‹œ์— ๋งค์นญ๋  ๋•Œ ์šฐ์„ ์ˆœ์œ„๋ฅผ ์ •ํ•œ๋‹ค.
@@ -3136,11 +3172,8 @@ def evaluate_component_from_uploaded_source_records(country, material, component
3136
  ๊ตญ๊ฐ€ ํด๋” ํŒŒ์ผ๋งŒ ๋ณด๊ณ  ํŒ์ •.
3137
  ํŒŒ์ผ record ์•ˆ์— ํ˜„์žฌ ์„ฑ๋ถ„๋ช…/๊ตญ๋ฌธ/CAS๊ฐ€ ์ง์ ‘ ์žˆ์„ ๋•Œ๋งŒ ํŒ์ •ํ•œ๋‹ค.
3138
  """
3139
- terms = [
3140
- safe_str(t)
3141
- for t in source_match_terms_for_component(material, component)
3142
- if safe_str(t) and len(normalize_compact(t)) >= 3 and not is_broad_lookup_term(t)
3143
- ]
3144
 
3145
  representative = (
3146
  safe_str(component.get("INCI Name", ""))
@@ -3149,17 +3182,16 @@ def evaluate_component_from_uploaded_source_records(country, material, component
3149
  or "-"
3150
  )
3151
 
3152
- if not terms:
3153
  return None
3154
 
3155
  records, status = build_country_source_record_index(country)
3156
  hits = []
3157
 
3158
  for rec in records:
3159
- rec_text = rec.get("text", "")
3160
 
3161
- # ๋ถ€๋ถ„ ๋ฌธ์ž์—ด ๋งค์นญ ๊ธˆ์ง€: biotin์ด MEA-Biotinate์— ๊ฑธ๋ฆฌ๋Š” ๋ฌธ์ œ ๋ฐฉ์ง€
3162
- if any(exact_ingredient_match(t, rec_text) for t in terms):
3163
  hits.append(rec)
3164
 
3165
  if not hits:
@@ -3589,7 +3621,7 @@ DEFAULT_ADMIN_EMAIL = os.getenv("ADMIN_EMAIL", "jin2li@rebom.kr").strip().lower(
3589
  DEFAULT_ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD", "qwer0515!")
3590
 
3591
 
3592
- def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=30, live_headless=True):
3593
  if not is_approved_user(user):
3594
  return None, None, require_login_message()
3595
 
@@ -3623,7 +3655,7 @@ def auth_fn(username, password):
3623
  # Gradio ๊ธฐ๋ณธ auth ์‚ฌ์šฉ ์‹œ ๋‚ด๋ถ€ ๋กœ๊ทธ์ธ ์ฒดํฌ ์šฐํšŒ
3624
  # ============================================================
3625
 
3626
- def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=30, live_headless=True):
3627
  return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
3628
 
3629
 
@@ -3659,7 +3691,7 @@ def auth_fn(username, password):
3659
  return USER_DB.get(username) == password
3660
 
3661
 
3662
- def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=30, live_headless=True):
3663
  return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
3664
 
3665
 
@@ -3700,7 +3732,7 @@ def auth_fn(username, password):
3700
 
3701
 
3702
  # Gradio ๊ธฐ๋ณธ auth๋ฅผ ํ†ต๊ณผํ•œ ์‚ฌ์šฉ์ž๋Š” ์ด๋ฏธ ์ธ์ฆ๋œ ์ƒํƒœ์ด๋ฏ€๋กœ ๋‚ด๋ถ€ ๋กœ๊ทธ์ธ ์ฒดํฌ๋ฅผ ํ•˜์ง€ ์•Š๋Š”๋‹ค.
3703
- def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=30, live_headless=True):
3704
  return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
3705
 
3706
 
@@ -3736,7 +3768,7 @@ def auth_fn(username, password):
3736
  return USER_DB.get(username) == password
3737
 
3738
 
3739
- def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=30, live_headless=True):
3740
  return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
3741
 
3742
 
@@ -3772,7 +3804,7 @@ def auth_fn(username, password):
3772
  return USER_DB.get(username) == password
3773
 
3774
 
3775
- def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=30, live_headless=True):
3776
  return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
3777
 
3778
 
@@ -3820,7 +3852,7 @@ def auth_fn(username, password):
3820
  return USER_DB.get(username) == password
3821
 
3822
 
3823
- def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=30, live_headless=True):
3824
  return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
3825
 
3826
 
@@ -3932,8 +3964,8 @@ with gr.Blocks(css=custom_css) as demo:
3932
  refresh=gr.Button("๐Ÿ”„ ํด๋”/๊ทœ์ œํŒŒ์ผ ์ƒˆ๋กœ๊ณ ์นจ")
3933
  product_name=gr.Textbox(label="์ œํ’ˆ๋ช… / PRODUCT NAME",placeholder="์˜ˆ: ๋งˆ๋ฐ์นดํฌ๋ฆผ")
3934
  file=gr.File(label="์ „์„ฑ๋ถ„ ํŒŒ์ผ ์—…๋กœ๋“œ",file_types=[".xlsx",".xls",".pdf",".png",".jpg",".jpeg",".webp"])
3935
- use_mfds_live=gr.Checkbox(label="์‹์•ฝ์ฒ˜ ์‚ฌ์ดํŠธ ์‹ค์‹œ๊ฐ„ ์กฐํšŒ ์‚ฌ์šฉ",value=False)
3936
- live_max_terms=gr.Number(label="์‹์•ฝ์ฒ˜ ์‹ค์‹œ๊ฐ„ ์กฐํšŒ ์ตœ๋Œ€ ๊ฒ€์ƒ‰์–ด ์ˆ˜",value=5,precision=0)
3937
  live_headless=gr.Checkbox(label="์‹์•ฝ์ฒ˜ ์กฐํšŒ ๋ธŒ๋ผ์šฐ์ € ์ˆจ๊น€ ๋ชจ๋“œ",value=True)
3938
  btn=gr.Button("๐Ÿš€ ๋ถ„์„ ์‹œ์ž‘",variant="primary")
3939
  df_out=gr.Dataframe(label="๋ฏธ๋ฆฌ๋ณด๊ธฐ - Formula Ingredients Statement",wrap=True,interactive=False)
@@ -3958,7 +3990,7 @@ with gr.Blocks(css=custom_css) as demo:
3958
  with gr.Row():
3959
  single_amount=gr.Textbox(label="ํ•จ๋Ÿ‰ %(w/w) ์„ ํƒ ์ž…๋ ฅ",placeholder="์˜ˆ: 7.2")
3960
  single_function=gr.Textbox(label="FUNCTION ์„ ํƒ ์ž…๋ ฅ",placeholder="์˜ˆ: Sunscreen Agent")
3961
- single_use_mfds_live=gr.Checkbox(label="์‹์•ฝ์ฒ˜ ์‚ฌ์ดํŠธ ์‹ค์‹œ๊ฐ„ ์กฐํšŒ ์‚ฌ์šฉ",value=False)
3962
  single_btn=gr.Button("๐Ÿ”Ž ๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰ ์‹œ์ž‘",variant="primary")
3963
  single_df_out=gr.Dataframe(label="๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ",wrap=True,interactive=False)
3964
  single_msg_out=gr.Textbox(label="๊ฒ€์ƒ‰ ์ƒํƒœ / ๋ฉ”์‹œ์ง€",interactive=False,lines=8)
 
1
+ # APP_PATCH_NOTE_SPEED_MFDS_BATCH_OFF = "์ „์ฒด ์Šคํฌ๋ฆฌ๋‹ ์†๋„ ์‘๊ธ‰ํŒจ์น˜: MFDS ์‹ค์‹œ๊ฐ„ ์กฐํšŒ ๋ฐฐ์น˜ ๋น„ํ™œ์„ฑํ™” + ๋งค์นญ ์บ์‹œ"
2
  # APP_PATCH_NOTE_LIMIT_POSITIVE_MFDS = "Positive List ํ•œ๋„ํ™•์ธ + MFDS ์ œํ•œ ํŒŒ์‹ฑ ๋ณด๊ฐ• ์ ์šฉ๋ณธ"
3
  # ============================================================
4
  # reBom Regulatory Screening AI - Fast Grounded Fixed Version
 
38
  import os, re, json, base64, hashlib, traceback, sqlite3, secrets, datetime, time, sys, subprocess, time
39
  from pathlib import Path
40
  from collections import defaultdict
41
+ from functools import lru_cache
42
  import pandas as pd
43
  import pdfplumber
44
  import gradio as gr
 
76
  NEED_CHECK_TEXT = "ํ™•์ธ ํ•„์š”"
77
  LIMIT_CHECK_TEXT = "๋ฐฐํ•ฉํ•œ๋„ ํ™•์ธ ํ•„์š”"
78
  MFDS_LIVE_URL = "https://nedrug.mfds.go.kr/pbp/CCBDF01"
79
+ # ์†๋„ ์‘๊ธ‰ํŒจ์น˜
80
+ # - ์ „์ฒด ์ „์„ฑ๋ถ„ ์Šคํฌ๋ฆฌ๋‹์—์„œ๋Š” MFDS ์‚ฌ์ดํŠธ ์‹ค์‹œ๊ฐ„ ์กฐํšŒ๋ฅผ ๊ธฐ๋ณธ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.
81
+ # - ๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰์—์„œ๋Š” ํ•„์š” ์‹œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.
82
+ ENABLE_MFDS_LIVE_FOR_BATCH = False
83
+ ENABLE_MFDS_LIVE_FOR_SINGLE = True
84
+ BATCH_MFDS_DISABLE_REASON = "์ „์ฒด ์ „์„ฑ๋ถ„ ์Šคํฌ๋ฆฌ๋‹์—์„œ๋Š” ์†๋„ ๋ณดํ˜ธ๋ฅผ ์œ„ํ•ด MFDS ์‹ค์‹œ๊ฐ„ ์กฐํšŒ๋ฅผ ์ž๋™ ๋น„ํ™œ์„ฑํ™”ํ•จ"
85
+
86
+ MFDS_RETRY_COUNT = int(os.getenv("MFDS_RETRY_COUNT", "1"))
87
+ MFDS_RETRY_WAIT_SEC = float(os.getenv("MFDS_RETRY_WAIT_SEC", "0.5"))
88
+ MFDS_BETWEEN_TERMS_WAIT_SEC = float(os.getenv("MFDS_BETWEEN_TERMS_WAIT_SEC", "0.2"))
89
  VECTOR_DB_CACHE = {}
90
  EVAL_CACHE = {}
91
  EMBEDDINGS_CACHE = None
 
197
  def get_identity_text(material,component):
198
  return normalize_text(get_identity_raw(material, component))
199
 
200
+ @lru_cache(maxsize=20000)
201
  def normalized_tokens(text):
202
  """
203
  ์„ฑ๋ถ„๋ช… ๋น„๊ต์šฉ ํ† ํฐํ™”.
 
206
  text = safe_str(text).lower().replace("ฮฑ", "alpha").replace("ฮฒ", "beta")
207
  return [t for t in re.split(r"[^a-z0-9๊ฐ€-ํžฃใ-ใ‚“ใ‚ก-ใƒณไธ€-้พฅ]+", text) if t]
208
 
209
+ @lru_cache(maxsize=50000)
210
  def exact_ingredient_match(term, target_text):
211
  """
212
  ์„ฑ๋ถ„๋ช…/alias๊ฐ€ target_text ์•ˆ์—์„œ ๋…๋ฆฝ ํ† ํฐ์œผ๋กœ ์กด์žฌํ•  ๋•Œ๋งŒ True.
 
749
  material.get("Trade name(์˜๋ฌธ)", ""),
750
  ] + list(extra_terms or [])
751
 
752
+ identity_norm = normalize_compact(" ".join(safe_str(x) for x in identity_values if safe_str(x)))
753
 
754
  hits = []
755
 
756
  for entry in REGULATORY_SYNONYM_REGISTRY:
757
  terms = entry.get("terms", [])
758
+ term_norms = [normalize_compact(t) for t in terms if safe_str(t)]
759
 
760
+ if any(tn and tn in identity_norm for tn in term_norms):
 
761
  for t in terms:
762
  if safe_str(t) and t not in hits:
763
  hits.append(safe_str(t))
 
779
  country_col = display_country(country)
780
  representative = safe_str(component.get("INCI Name", "")) or safe_str(component.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", "")) or registry_terms[0]
781
 
782
+ registry_norms = [
783
+ normalize_compact(t)
784
  for t in registry_terms
785
  if safe_str(t) and len(normalize_compact(t)) >= 3
786
  ]
787
 
788
  for section in sections:
789
  text = safe_str(section.get("text", ""))
790
+ text_norm = normalize_compact(text)
791
 
792
+ if not any(tn in text_norm for tn in registry_norms):
 
793
  continue
794
 
795
  header = safe_str(section.get("header", ""))
 
802
  seen = set()
803
 
804
  for idx, line in enumerate(lines):
805
+ ln = normalize_compact(line)
806
+ if any(tn in ln for tn in registry_norms):
807
  for j in range(max(0, idx - 5), min(len(lines), idx + 6)):
808
  if j not in seen:
809
  seen.add(j)
 
966
 
967
  for section in sections:
968
  text = safe_str(section.get("text", ""))
969
+ text_norm = normalize_compact(text)
970
  header = safe_str(section.get("header", ""))
971
  reg_type = infer_regulation_type_from_source_text(header + "\n" + text[:1500], country=country)
972
  reg_kind = reg_type.get("type", "unknown")
973
  reg_label = reg_type.get("label", "๊ทœ์ œ ์œ ํ˜• ๋ฏธ๋ถ„๋ฅ˜")
974
 
975
+ hit_terms = [v for v in expanded if normalize_compact(v) in text_norm]
976
  if not hit_terms:
977
  continue
978
 
 
981
  seen = set()
982
 
983
  for idx, line in enumerate(lines):
984
+ line_norm = normalize_compact(line)
985
+ if any(normalize_compact(v) in line_norm for v in hit_terms):
986
  for j in range(max(0, idx - 4), min(len(lines), idx + 5)):
987
  if j not in seen:
988
  seen.add(j)
 
1352
  return mats,{"cols":cols,"cleaned_df":clean,"ingredient_totals":defaultdict(float),"ingredient_amount_parts":defaultdict(list)}
1353
 
1354
  # MFDS simplified: disabled-safe placeholder; keep UI compatibility
1355
+ def extract_terms_for_live_lookup(row_items, max_terms=5):
1356
+ """
1357
+ MFDS ์‹ค์‹œ๊ฐ„ ์กฐํšŒ์šฉ ๊ฒ€์ƒ‰์–ด ์ƒ์„ฑ.
1358
+ ์ „์ฒด ์Šคํฌ๋ฆฌ๋‹์—์„œ๋Š” MFDS ์‹ค์‹œ๊ฐ„ ์กฐํšŒ๋ฅผ ๋„๋Š” ๊ฒƒ์ด ์›์น™์ด๋ฉฐ,
1359
+ ํ˜น์‹œ ์ผœ์ ธ๋„ ๊ฒ€์ƒ‰์–ด๊ฐ€ ํญ์ฆํ•˜์ง€ ์•Š๋„๋ก ์ตœ๋Œ€ ๊ฐœ์ˆ˜๋ฅผ ์ œํ•œํ•œ๋‹ค.
1360
+ """
1361
  terms=[]
1362
  for item in row_items:
1363
  m=item["material"]; c=item["component"]
1364
+ if is_plain_fragrance_component(m,c) or is_always_pass_component(m,c):
1365
+ continue
1366
  for v in [c.get("INCI Name",""),c.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…",""),c.get("CAS.No","")]:
1367
+ if safe_str(v):
1368
+ terms.append(safe_str(v))
1369
+ break
1370
  seen=[]
1371
  for t in terms:
1372
+ if t not in seen:
1373
+ seen.append(t)
1374
+ if max_terms and len(seen) >= int(max_terms):
1375
+ break
1376
  return seen
1377
 
1378
  def mfds_visible_text(page):
 
1493
  except Exception:
1494
  continue
1495
 
1496
+ row_norm = normalize_compact(row_text)
1497
+
1498
+ if term_norm and term_norm in row_norm:
1499
  row.click(timeout=3000)
1500
  page.wait_for_timeout(1000)
1501
  return True
 
1759
  return [], ""
1760
 
1761
  # ๊ฒ€์ƒ‰์–ด๊ฐ€ ํ™”๋ฉด์— ์žˆ์ง€๋งŒ ๊ทœ์ œ ํ•„๋“œ๊ฐ€ ์—†์œผ๋ฉด ์ผ๋ฐ˜ ์›๋ฃŒ ์ƒ์„ธ/๋ฌด๊ทœ์ œ ๊ฒฐ๊ณผ๋กœ ํŒ๋‹จ
1762
+ if term_norm and term_norm in body_norm:
 
1763
  return [], ""
1764
 
1765
  if not clicked:
 
1837
  return False, str(e)
1838
 
1839
 
1840
+ def mfds_live_lookup_terms(terms, max_terms=5, headless=True):
1841
  if not PLAYWRIGHT_AVAILABLE or sync_playwright is None:
1842
  return pd.DataFrame(), "MFDS ์‹ค์‹œ๊ฐ„ ์กฐํšŒ ์‹คํŒจ: playwright ํŒจํ‚ค์ง€ ๋ฏธ์„ค์น˜"
1843
 
1844
  terms = [safe_str(t) for t in terms if safe_str(t)]
1845
+ terms = terms[:min(int(max_terms), 5)] if max_terms else terms[:5]
1846
 
1847
  all_rows = []
1848
  errors = []
 
2125
  issues=[cc for cc in country_cols if is_country_result_issue(rd.get(cc,""))]
2126
  return "PASS" if not issues else "์žฌ๊ฒ€ํ†  ํ•„์š”: "+", ".join(issues)
2127
 
2128
+ def process(countries,file,product_name="",use_mfds_live=False,live_max_terms=5,live_headless=True):
2129
  """
2130
  ์ „์„ฑ๋ถ„ ์ „์ฒด ์Šคํฌ๋ฆฌ๋‹ ๊ณ ์† ๋ฒ„์ „.
2131
 
 
2133
  - ์ „์ฒด ์Šคํฌ๋ฆฌ๋‹์—์„œ GPT/LLM ํ˜ธ์ถœ ์ œ๊ฑฐ
2134
  - ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ ์ง์ ‘ ๊ฒ€์ƒ‰(COUNTRY_FILE_FAST) ์šฐ์„ 
2135
  - ์„ ํƒ ๊ตญ๊ฐ€๋ณ„ ์„น์…˜ ์ธ๋ฑ์Šค 1ํšŒ ์›Œ๋ฐ์—…
2136
+ - ์ „์ฒด ์Šคํฌ๋ฆฌ๋‹์—์„œ๋Š” ์†๋„ ๋ณดํ˜ธ๋ฅผ ์œ„ํ•ด ์‹์•ฝ์ฒ˜ ์‹ค์‹œ๊ฐ„ ์กฐํšŒ ์ž๋™ ๋น„ํ™œ์„ฑํ™”
2137
  """
2138
  global RAW_SEARCH_LOGS
2139
  RAW_SEARCH_LOGS = []
 
2179
  except Exception as e:
2180
  index_messages.append(f"{display_country(country)}=index error: {e}")
2181
 
2182
+ # ์ „์ฒด ์ „์„ฑ๋ถ„ ์Šคํฌ๋ฆฌ๋‹์—์„œ๋Š” MFDS ์‚ฌ์ดํŠธ ์‹ค์‹œ๊ฐ„ ์กฐํšŒ๋ฅผ ๋Œ๋ฆฌ์ง€ ์•Š๋Š”๋‹ค.
2183
+ # ์„ฑ๋ถ„ ์ˆ˜๊ฐ€ ๋งŽ์„ ๋•Œ Playwright ์ ‘์†/๋Œ€๊ธฐ ์‹œ๊ฐ„์ด ์„ฑ๋ถ„ ์ˆ˜๋งŒํผ ๋ˆ„์ ๋˜์–ด 1์‹œ๊ฐ„ ์ด์ƒ ๊ฑธ๋ฆด ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ.
2184
+ batch_live_requested = bool(use_mfds_live)
2185
+ use_mfds_live = False if not ENABLE_MFDS_LIVE_FOR_BATCH else bool(use_mfds_live)
2186
+ terms = []
2187
  mfds_df = pd.DataFrame()
2188
  mfds_msg = "์‚ฌ์šฉ ์•ˆ ํ•จ"
2189
 
2190
+ if batch_live_requested and not ENABLE_MFDS_LIVE_FOR_BATCH:
2191
+ mfds_msg = BATCH_MFDS_DISABLE_REASON
2192
+
2193
  if use_mfds_live:
2194
+ terms = extract_terms_for_live_lookup(row_items, max_terms=min(int(live_max_terms or 5), 5))
2195
+ mfds_df, mfds_msg = mfds_live_lookup_terms(terms, min(int(live_max_terms or 5), 5), True)
2196
 
2197
  for country in countries:
2198
  col = display_country(country)
 
2727
  def find_matching_regulatory_sections_fast(country, ingredient_names, max_sections=30):
2728
  """
2729
  ๊ณ ์† ๋‹จ์ผ ๊ฒ€์ƒ‰.
2730
+ get_country_section_index_cached()๊ฐ€ ๋งŒ๋“  ์„น์…˜ ์ธ๋ฑ์Šค์—์„œ ์„ฑ๋ถ„๋ช…/INCI/CAS๋ฅผ ์ง์ ‘ ๊ฒ€์ƒ‰ํ•œ๋‹ค.
 
 
 
 
2731
  """
2732
  sections, status = get_country_section_index_cached(country)
2733
 
2734
+ names_norm = [
2735
+ normalize_compact(x)
2736
  for x in ingredient_names
2737
+ if safe_str(x) and len(normalize_compact(x)) >= 3
2738
  ]
2739
 
2740
+ if not names_norm:
2741
  return [], status
2742
 
2743
  matches = []
2744
 
2745
  for section in sections:
2746
+ text_norm = section.get("text_norm", "")
2747
 
2748
+ if not any(name in text_norm for name in names_norm):
2749
  continue
2750
 
2751
+ text = safe_str(section.get("text", ""))
2752
  header = safe_str(section.get("header", ""))
2753
  lines = [safe_str(x) for x in text.splitlines() if safe_str(x)]
2754
 
2755
  hit_indices = []
2756
 
2757
  for idx, line in enumerate(lines):
2758
+ line_norm = normalize_compact(line)
2759
+
2760
+ if any(name in line_norm for name in names_norm):
2761
  hit_indices.append(idx)
2762
 
2763
  if len(hit_indices) >= 10:
 
2782
  else:
2783
  context = header + "\n" + text[:2000]
2784
 
2785
+ # ๋””์Šคํฌ ์บ์‹œ๊ฐ€ ์˜ค๋ž˜๋œ label์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ header ๊ธฐ์ค€์œผ๋กœ ํ•œ๋ฒˆ ๋” ๋ณด์ •
2786
  reg_type = infer_regulation_type_from_source_text(
2787
  header + "\n" + text[:1500],
2788
  country=country,
 
2799
 
2800
  return matches, status
2801
 
2802
+
2803
  def find_matching_regulatory_sections(raw_text, ingredient_names, max_sections=20):
2804
  """
2805
+ ๊ตฌ๋ฒ„์ „ ํ˜ธํ™˜์šฉ. ์‹ ๊ทœ ๋‹จ์ผ ๊ฒ€์ƒ‰์€ find_matching_regulatory_sections_fast()๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
2806
  """
2807
+ names_norm = [
2808
+ normalize_compact(x)
2809
  for x in ingredient_names
2810
+ if safe_str(x) and len(normalize_compact(x)) >= 3
2811
  ]
2812
 
2813
+ if not names_norm:
2814
  return []
2815
 
2816
  matches = []
2817
 
2818
  for section in split_regulatory_text_into_sections(raw_text):
2819
  text = section["text"]
2820
+ text_norm = normalize_compact(text)
2821
 
2822
+ if any(name in text_norm for name in names_norm):
2823
+ lines = [safe_str(x) for x in text.splitlines() if safe_str(x)]
2824
+ hit_indices = []
2825
 
2826
+ for idx, line in enumerate(lines):
2827
+ line_norm = normalize_compact(line)
2828
 
2829
+ if any(name in line_norm for name in names_norm):
2830
+ hit_indices.append(idx)
 
2831
 
2832
+ context_lines = []
2833
+ seen = set()
2834
 
2835
+ for idx in hit_indices[:8]:
2836
+ start = max(0, idx - 4)
2837
+ end = min(len(lines), idx + 5)
2838
 
2839
+ for j in range(start, end):
2840
+ if j in seen:
2841
+ continue
2842
 
2843
+ seen.add(j)
2844
+ context_lines.append(lines[j])
2845
 
2846
+ context = section["header"] + "\n" + "\n".join(context_lines)
2847
+ reg_type = infer_regulation_type_from_source_text(section["header"] + "\n" + text[:1200], country="")
2848
 
2849
+ matches.append({
2850
+ "header": section["header"],
2851
+ "context": context[:8000],
2852
+ "regulation_type": reg_type,
2853
+ })
2854
 
2855
+ if len(matches) >= max_sections:
2856
+ break
2857
 
2858
  return matches
2859
 
2860
+
2861
  def pick_best_regulatory_match(matches):
2862
  """
2863
  ์—ฌ๋Ÿฌ ํŒŒ์ผ์—์„œ ๋™์‹œ์— ๋งค์นญ๋  ๋•Œ ์šฐ์„ ์ˆœ์œ„๋ฅผ ์ •ํ•œ๋‹ค.
 
3172
  ๊ตญ๊ฐ€ ํด๋” ํŒŒ์ผ๋งŒ ๋ณด๊ณ  ํŒ์ •.
3173
  ํŒŒ์ผ record ์•ˆ์— ํ˜„์žฌ ์„ฑ๋ถ„๋ช…/๊ตญ๋ฌธ/CAS๊ฐ€ ์ง์ ‘ ์žˆ์„ ๋•Œ๋งŒ ํŒ์ •ํ•œ๋‹ค.
3174
  """
3175
+ terms = source_match_terms_for_component(material, component)
3176
+ term_norms = [normalize_compact(t) for t in terms if len(normalize_compact(t)) >= 3]
 
 
 
3177
 
3178
  representative = (
3179
  safe_str(component.get("INCI Name", ""))
 
3182
  or "-"
3183
  )
3184
 
3185
+ if not term_norms:
3186
  return None
3187
 
3188
  records, status = build_country_source_record_index(country)
3189
  hits = []
3190
 
3191
  for rec in records:
3192
+ rec_norm = rec.get("text_norm", "")
3193
 
3194
+ if any(tn in rec_norm for tn in term_norms):
 
3195
  hits.append(rec)
3196
 
3197
  if not hits:
 
3621
  DEFAULT_ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD", "qwer0515!")
3622
 
3623
 
3624
+ def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=5, live_headless=True):
3625
  if not is_approved_user(user):
3626
  return None, None, require_login_message()
3627
 
 
3655
  # Gradio ๊ธฐ๋ณธ auth ์‚ฌ์šฉ ์‹œ ๋‚ด๋ถ€ ๋กœ๊ทธ์ธ ์ฒดํฌ ์šฐํšŒ
3656
  # ============================================================
3657
 
3658
+ def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=5, live_headless=True):
3659
  return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
3660
 
3661
 
 
3691
  return USER_DB.get(username) == password
3692
 
3693
 
3694
+ def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=5, live_headless=True):
3695
  return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
3696
 
3697
 
 
3732
 
3733
 
3734
  # Gradio ๊ธฐ๋ณธ auth๋ฅผ ํ†ต๊ณผํ•œ ์‚ฌ์šฉ์ž๋Š” ์ด๋ฏธ ์ธ์ฆ๋œ ์ƒํƒœ์ด๋ฏ€๋กœ ๋‚ด๋ถ€ ๋กœ๊ทธ์ธ ์ฒดํฌ๋ฅผ ํ•˜์ง€ ์•Š๋Š”๋‹ค.
3735
+ def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=5, live_headless=True):
3736
  return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
3737
 
3738
 
 
3768
  return USER_DB.get(username) == password
3769
 
3770
 
3771
+ def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=5, live_headless=True):
3772
  return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
3773
 
3774
 
 
3804
  return USER_DB.get(username) == password
3805
 
3806
 
3807
+ def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=5, live_headless=True):
3808
  return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
3809
 
3810
 
 
3852
  return USER_DB.get(username) == password
3853
 
3854
 
3855
+ def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=5, live_headless=True):
3856
  return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
3857
 
3858
 
 
3964
  refresh=gr.Button("๐Ÿ”„ ํด๋”/๊ทœ์ œํŒŒ์ผ ์ƒˆ๋กœ๊ณ ์นจ")
3965
  product_name=gr.Textbox(label="์ œํ’ˆ๋ช… / PRODUCT NAME",placeholder="์˜ˆ: ๋งˆ๋ฐ์นดํฌ๋ฆผ")
3966
  file=gr.File(label="์ „์„ฑ๋ถ„ ํŒŒ์ผ ์—…๋กœ๋“œ",file_types=[".xlsx",".xls",".pdf",".png",".jpg",".jpeg",".webp"])
3967
+ use_mfds_live=gr.Checkbox(label="์‹์•ฝ์ฒ˜ ์‚ฌ์ดํŠธ ์‹ค์‹œ๊ฐ„ ์กฐํšŒ ์‚ฌ์šฉ(์ „์ฒด ์Šคํฌ๋ฆฌ๋‹์—์„œ๋Š” ์ž๋™ ๋น„ํ™œ์„ฑํ™”)",value=False)
3968
+ live_max_terms=gr.Number(label="์‹์•ฝ์ฒ˜ ์‹ค์‹œ๊ฐ„ ์กฐํšŒ ์ตœ๋Œ€ ๊ฒ€์ƒ‰์–ด ์ˆ˜(์ตœ๋Œ€ 5)",value=5,precision=0)
3969
  live_headless=gr.Checkbox(label="์‹์•ฝ์ฒ˜ ์กฐํšŒ ๋ธŒ๋ผ์šฐ์ € ์ˆจ๊น€ ๋ชจ๋“œ",value=True)
3970
  btn=gr.Button("๐Ÿš€ ๋ถ„์„ ์‹œ์ž‘",variant="primary")
3971
  df_out=gr.Dataframe(label="๋ฏธ๋ฆฌ๋ณด๊ธฐ - Formula Ingredients Statement",wrap=True,interactive=False)
 
3990
  with gr.Row():
3991
  single_amount=gr.Textbox(label="ํ•จ๋Ÿ‰ %(w/w) ์„ ํƒ ์ž…๋ ฅ",placeholder="์˜ˆ: 7.2")
3992
  single_function=gr.Textbox(label="FUNCTION ์„ ํƒ ์ž…๋ ฅ",placeholder="์˜ˆ: Sunscreen Agent")
3993
+ single_use_mfds_live=gr.Checkbox(label="์‹์•ฝ์ฒ˜ ์‚ฌ์ดํŠธ ์‹ค์‹œ๊ฐ„ ์กฐํšŒ ์‚ฌ์šฉ(์ „์ฒด ์Šคํฌ๋ฆฌ๋‹์—์„œ๋Š” ์ž๋™ ๋น„ํ™œ์„ฑํ™”)",value=False)
3994
  single_btn=gr.Button("๐Ÿ”Ž ๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰ ์‹œ์ž‘",variant="primary")
3995
  single_df_out=gr.Dataframe(label="๋‹จ์ผ ์„ฑ๋ถ„ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ",wrap=True,interactive=False)
3996
  single_msg_out=gr.Textbox(label="๊ฒ€์ƒ‰ ์ƒํƒœ / ๋ฉ”์‹œ์ง€",interactive=False,lines=8)