gvlktejaswi commited on
Commit
970a5b6
·
verified ·
1 Parent(s): 93282af

Update page_files/Categorized_Search.py

Browse files
Files changed (1) hide show
  1. page_files/Categorized_Search.py +27 -5
page_files/Categorized_Search.py CHANGED
@@ -32,16 +32,38 @@ def _load_plot_bytes(selected_abbr, property_choice, result_df):
32
  if "material_name" in result_df.columns:
33
  material_name = str(result_df.iloc[0]["material_name"])
34
  tables = [table] if table else list(_CLASS_TABLE.values()) # fallback: try all
 
35
  try:
 
 
36
  try:
37
- from categorized.Backend import mapper5
 
38
  except ModuleNotFoundError:
39
- import sys, os
40
- sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
 
41
  try:
42
- from categorized.Backend import mapper5
 
43
  except ModuleNotFoundError:
44
- import mapper5 # flat-layout fallback
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  from sqlalchemy import text
46
  engine = mapper5.get_db_engine()
47
  except Exception as e:
 
32
  if "material_name" in result_df.columns:
33
  material_name = str(result_df.iloc[0]["material_name"])
34
  tables = [table] if table else list(_CLASS_TABLE.values()) # fallback: try all
35
+ mapper5 = None
36
  try:
37
+ import sys, os
38
+ # 1) flat layout (local dev: mapper5.py on sys.path / same dir)
39
  try:
40
+ import mapper5 as _m5
41
+ mapper5 = _m5
42
  except ModuleNotFoundError:
43
+ pass
44
+ # 2) HF Space package layout: page_files/categorized/Backend/mapper5.py
45
+ if mapper5 is None:
46
  try:
47
+ from categorized.Backend import mapper5 as _m5
48
+ mapper5 = _m5
49
  except ModuleNotFoundError:
50
+ pass
51
+ # 3) add candidate dirs to sys.path and retry flat import
52
+ if mapper5 is None:
53
+ here = os.path.dirname(__file__)
54
+ candidates = [
55
+ here,
56
+ os.path.join(here, ".."),
57
+ os.path.join(here, "..", ".."),
58
+ os.path.join(here, "categorized", "Backend"),
59
+ os.environ.get("MAPPER5_DIR", ""),
60
+ r"C:\Users\999te\InDesDatabaseTool\langchain-env\Lib",
61
+ ]
62
+ for cand in candidates:
63
+ if cand and os.path.isdir(cand):
64
+ sys.path.insert(0, os.path.abspath(cand))
65
+ import mapper5 as _m5
66
+ mapper5 = _m5
67
  from sqlalchemy import text
68
  engine = mapper5.get_db_engine()
69
  except Exception as e: