Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,17 +3,10 @@ import torch
|
|
| 3 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 4 |
import re
|
| 5 |
from tokenizers.normalizers import Replace, Regex, Sequence, Strip
|
| 6 |
-
import os
|
| 7 |
|
| 8 |
-
# --- Model & Tokenizer Configuration ---
|
| 9 |
-
# Check if the local model file exists
|
| 10 |
-
model1_filename = "modernbert.bin"
|
| 11 |
-
if not os.path.exists(model1_filename):
|
| 12 |
-
print(f"Warning: Model file '{model1_filename}' not found. Please ensure it is in the correct directory.")
|
| 13 |
-
# You might want to handle this more gracefully, e.g., by disabling the app or using a fallback.
|
| 14 |
-
# For now, the script will likely fail at model_1.load_state_dict if the file is missing.
|
| 15 |
|
| 16 |
-
model1_path =
|
| 17 |
model2_path = "https://huggingface.co/mihalykiss/modernbert_2/resolve/main/Model_groups_3class_seed12"
|
| 18 |
model3_path = "https://huggingface.co/mihalykiss/modernbert_2/resolve/main/Model_groups_3class_seed22"
|
| 19 |
|
|
@@ -24,14 +17,7 @@ try:
|
|
| 24 |
tokenizer = AutoTokenizer.from_pretrained("answerdotai/ModernBERT-base")
|
| 25 |
|
| 26 |
model_1 = AutoModelForSequenceClassification.from_pretrained("answerdotai/ModernBERT-base", num_labels=41)
|
| 27 |
-
|
| 28 |
-
model_1.load_state_dict(torch.load(model1_path, map_location=device))
|
| 29 |
-
else:
|
| 30 |
-
# Fallback or error if local model is not found.
|
| 31 |
-
# This part depends on how you want to handle the missing file.
|
| 32 |
-
# For this example, we'll assume it might raise an error later if not handled.
|
| 33 |
-
print(f"ERROR: Local model file '{model1_path}' not found. Model 1 cannot be loaded.")
|
| 34 |
-
# exit() # Or raise an exception
|
| 35 |
model_1.to(device).eval()
|
| 36 |
|
| 37 |
model_2 = AutoModelForSequenceClassification.from_pretrained("answerdotai/ModernBERT-base", num_labels=41)
|
|
|
|
| 3 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 4 |
import re
|
| 5 |
from tokenizers.normalizers import Replace, Regex, Sequence, Strip
|
| 6 |
+
import os
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
model1_path = "https://huggingface.co/spaces/SzegedAI/AI_Detector/resolve/main/modernbert.bin"
|
| 10 |
model2_path = "https://huggingface.co/mihalykiss/modernbert_2/resolve/main/Model_groups_3class_seed12"
|
| 11 |
model3_path = "https://huggingface.co/mihalykiss/modernbert_2/resolve/main/Model_groups_3class_seed22"
|
| 12 |
|
|
|
|
| 17 |
tokenizer = AutoTokenizer.from_pretrained("answerdotai/ModernBERT-base")
|
| 18 |
|
| 19 |
model_1 = AutoModelForSequenceClassification.from_pretrained("answerdotai/ModernBERT-base", num_labels=41)
|
| 20 |
+
model_1.load_state_dict(torch.hub.load_state_dict_from_url(model1_path, map_location=device, progress=True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
model_1.to(device).eval()
|
| 22 |
|
| 23 |
model_2 = AutoModelForSequenceClassification.from_pretrained("answerdotai/ModernBERT-base", num_labels=41)
|