縮排
Browse files
app.py
CHANGED
|
@@ -225,6 +225,7 @@ async def get_embeddings_from_hf_dataset(filename: str) -> Optional[List[np.ndar
|
|
| 225 |
count += 1
|
| 226 |
if count >= 1000: break # 保留限制
|
| 227 |
|
|
|
|
| 228 |
if embeddings:
|
| 229 |
print(f"✅ Found {len(embeddings)} embeddings for base name {base_name}")
|
| 230 |
return embeddings
|
|
@@ -254,7 +255,9 @@ def analyze_som_region_probability(
|
|
| 254 |
if len(region_samples) == 0:
|
| 255 |
return {"dropper": 0.0, "APT30": 0.0}
|
| 256 |
|
|
|
|
| 257 |
feature_counts = {"dropper": [], "spreader": [], "APT30": [], "Codoso_Gh0st_1": []}
|
|
|
|
| 258 |
if hasattr(som_analyzer, 'background_embeddings') and hasattr(som_analyzer, 'background_labels'):
|
| 259 |
for i, bg_emb in enumerate(som_analyzer.background_embeddings):
|
| 260 |
bg_row, bg_col = som_analyzer.som.winner(bg_emb) #
|
|
@@ -264,6 +267,8 @@ def analyze_som_region_probability(
|
|
| 264 |
feature_counts[feature_name].append(
|
| 265 |
som_analyzer.background_labels[feature_name][i]
|
| 266 |
)
|
|
|
|
|
|
|
| 267 |
probabilities = {}
|
| 268 |
for feature_name, values in feature_counts.items():
|
| 269 |
if len(values) > 0:
|
|
|
|
| 225 |
count += 1
|
| 226 |
if count >= 1000: break # 保留限制
|
| 227 |
|
| 228 |
+
# ✅ 修正縮排:這個 if/else 區塊必須在 'try' 內部
|
| 229 |
if embeddings:
|
| 230 |
print(f"✅ Found {len(embeddings)} embeddings for base name {base_name}")
|
| 231 |
return embeddings
|
|
|
|
| 255 |
if len(region_samples) == 0:
|
| 256 |
return {"dropper": 0.0, "APT30": 0.0}
|
| 257 |
|
| 258 |
+
# ✅ 修正縮排:'feature_counts' 和 'if hasattr' 應該在同一層級
|
| 259 |
feature_counts = {"dropper": [], "spreader": [], "APT30": [], "Codoso_Gh0st_1": []}
|
| 260 |
+
|
| 261 |
if hasattr(som_analyzer, 'background_embeddings') and hasattr(som_analyzer, 'background_labels'):
|
| 262 |
for i, bg_emb in enumerate(som_analyzer.background_embeddings):
|
| 263 |
bg_row, bg_col = som_analyzer.som.winner(bg_emb) #
|
|
|
|
| 267 |
feature_counts[feature_name].append(
|
| 268 |
som_analyzer.background_labels[feature_name][i]
|
| 269 |
)
|
| 270 |
+
|
| 271 |
+
# ✅ 修正縮排:'probabilities' 和 'for' 迴圈應該在 'if hasattr' 之外
|
| 272 |
probabilities = {}
|
| 273 |
for feature_name, values in feature_counts.items():
|
| 274 |
if len(values) > 0:
|