raxhel commited on
Commit
b070005
·
verified ·
1 Parent(s): 7100558
Files changed (1) hide show
  1. app.py +14 -23
app.py CHANGED
@@ -80,33 +80,24 @@ print("✅ Model loaded successfully")
80
 
81
  # ===== 新增:載入 SOM 模型 (from app.py) =====
82
  print("🧠 Initializing SOM Analyzer...")
83
- SOM_REPO = "malvec/codebert_Malvec" # (app.py 的 SOM repo)
84
  SOM_AVAILABLE = False
85
 
86
  if SOM_FILE_AVAILABLE: # 檢查 'som_analyzer.py' 是否 import 成功
87
  try:
88
- som_weights_path = hf_hub_download(
89
- repo_id=SOM_REPO,
90
- filename="som_weights.npy",
91
- token=HF_TOKEN
92
- )
93
- background_data_path = hf_hub_download(
94
- repo_id=SOM_REPO,
95
- filename="som_background_data.pkl",
96
- token=HF_TOKEN
97
- )
98
-
99
- som_analyzer = SOMAnalyzer(
100
- som_weights_path=som_weights_path,
101
- background_data_path=background_data_path
102
- )
103
- print("✅ SOM Analyzer initialized successfully!")
104
- SOM_AVAILABLE = True
105
- except Exception as e:
106
- print(f"⚠️ SOM Analyzer initialization failed: {e}")
107
- print(" SOM analysis will be disabled")
108
- else:
109
- print(" SOM analysis disabled because 'som_analyzer.py' is missing.")
110
 
111
  # ----------------------------------------------------------
112
  # ROUTES
 
80
 
81
  # ===== 新增:載入 SOM 模型 (from app.py) =====
82
  print("🧠 Initializing SOM Analyzer...")
83
+ #SOM_REPO = "malvec/codebert_Malvec" # (app.py 的 SOM repo)
84
  SOM_AVAILABLE = False
85
 
86
  if SOM_FILE_AVAILABLE: # 檢查 'som_analyzer.py' 是否 import 成功
87
  try:
88
+ # ✅ 直接使用 repo 內的本地檔案
89
+ # (假設 app.py 和 .npy/.pkl 檔案在同一層級)
90
+ print(" Loading SOM files from local repository...")
91
+ som_weights_path = "som_weights.npy"
92
+ background_data_path = "som_background_data.pkl"
93
+
94
+ # 檢查檔案是否存在
95
+ if not os.path.exists(som_weights_path):
96
+ raise FileNotFoundError(f"{som_weights_path} not found in this repo.")
97
+ if not os.path.exists(background_data_path):
98
+ raise FileNotFoundError(f"{background_data_path} not found in this repo.")
99
+
100
+ print(" Local files found.")
 
 
 
 
 
 
 
 
 
101
 
102
  # ----------------------------------------------------------
103
  # ROUTES