Spaces:
Runtime error
Runtime error
111306047 commited on
Commit ·
6ff5685
1
Parent(s): 6c9facf
fix int
Browse files
app.py
CHANGED
|
@@ -127,19 +127,15 @@ async def predict_malware(files: List[UploadFile] = File(...)):
|
|
| 127 |
probs = torch.nn.functional.softmax(logits, dim=-1)
|
| 128 |
confidence, predicted_class = torch.max(probs, dim=-1)
|
| 129 |
|
| 130 |
-
# 取得 label
|
| 131 |
predicted_id = predicted_class.item()
|
| 132 |
-
if hasattr(model.config, 'id2label'):
|
| 133 |
-
|
| 134 |
-
if predicted_id in model.config.id2label:
|
| 135 |
-
label_name = model.config.id2label[predicted_id]
|
| 136 |
-
elif str(predicted_id) in model.config.id2label:
|
| 137 |
-
label_name = model.config.id2label[str(predicted_id)]
|
| 138 |
-
else:
|
| 139 |
-
label_name = f"class_{predicted_id}"
|
| 140 |
else:
|
| 141 |
label_name = f"class_{predicted_id}"
|
| 142 |
|
|
|
|
|
|
|
| 143 |
# ✅ 取得 embedding (使用 hidden_states)
|
| 144 |
if hasattr(outputs, 'hidden_states') and outputs.hidden_states is not None:
|
| 145 |
# 取最後一層的 [CLS] token embedding
|
|
|
|
| 127 |
probs = torch.nn.functional.softmax(logits, dim=-1)
|
| 128 |
confidence, predicted_class = torch.max(probs, dim=-1)
|
| 129 |
|
| 130 |
+
# ✅ 取得 label (使用整數 key)
|
| 131 |
predicted_id = predicted_class.item()
|
| 132 |
+
if hasattr(model.config, 'id2label') and predicted_id in model.config.id2label:
|
| 133 |
+
label_name = model.config.id2label[predicted_id]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
else:
|
| 135 |
label_name = f"class_{predicted_id}"
|
| 136 |
|
| 137 |
+
print(f" 🔍 Predicted ID: {predicted_id}, Label: {label_name}")
|
| 138 |
+
|
| 139 |
# ✅ 取得 embedding (使用 hidden_states)
|
| 140 |
if hasattr(outputs, 'hidden_states') and outputs.hidden_states is not None:
|
| 141 |
# 取最後一層的 [CLS] token embedding
|