Spaces:
Sleeping
Sleeping
Commit
Β·
a10ba15
1
Parent(s):
8f83228
Fix tokenizer compatibility issues
Browse files- app.py +39 -16
- requirements.txt +3 -3
app.py
CHANGED
|
@@ -9,22 +9,45 @@ def load_model():
|
|
| 9 |
"""Load the intent classification model"""
|
| 10 |
global _classifier
|
| 11 |
if _classifier is None:
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
trust_remote_code
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
return _classifier
|
| 29 |
|
| 30 |
def classify_intent(comment):
|
|
|
|
| 9 |
"""Load the intent classification model"""
|
| 10 |
global _classifier
|
| 11 |
if _classifier is None:
|
| 12 |
+
model_name = "YosefA/adfluence-intent-model"
|
| 13 |
+
|
| 14 |
+
# Try multiple approaches to load the model
|
| 15 |
+
loading_strategies = [
|
| 16 |
+
{
|
| 17 |
+
"name": "Standard loading with trust_remote_code",
|
| 18 |
+
"kwargs": {"trust_remote_code": True, "return_all_scores": True}
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"name": "Loading with revision='main'",
|
| 22 |
+
"kwargs": {"revision": "main", "return_all_scores": True}
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"name": "Loading with use_fast=False",
|
| 26 |
+
"kwargs": {"use_fast": False, "return_all_scores": True}
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"name": "Loading with legacy tokenizer",
|
| 30 |
+
"kwargs": {"use_fast": False, "trust_remote_code": True, "return_all_scores": True}
|
| 31 |
+
}
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
+
for strategy in loading_strategies:
|
| 35 |
+
try:
|
| 36 |
+
print(f"Trying: {strategy['name']}")
|
| 37 |
+
_classifier = pipeline(
|
| 38 |
+
"text-classification",
|
| 39 |
+
model=model_name,
|
| 40 |
+
**strategy['kwargs']
|
| 41 |
+
)
|
| 42 |
+
print(f"β
Model loaded successfully using: {strategy['name']}")
|
| 43 |
+
return _classifier
|
| 44 |
+
|
| 45 |
+
except Exception as e:
|
| 46 |
+
print(f"β Failed with {strategy['name']}: {e}")
|
| 47 |
+
continue
|
| 48 |
+
|
| 49 |
+
print("β All loading strategies failed")
|
| 50 |
+
return None
|
| 51 |
return _classifier
|
| 52 |
|
| 53 |
def classify_intent(comment):
|
requirements.txt
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
gradio==4.44.0
|
| 2 |
-
transformers==4.
|
| 3 |
torch==2.1.0
|
| 4 |
-
tokenizers==0.
|
| 5 |
-
huggingface_hub==0.
|
| 6 |
numpy<2.0.0
|
| 7 |
requests==2.31.0
|
|
|
|
| 1 |
gradio==4.44.0
|
| 2 |
+
transformers==4.45.0
|
| 3 |
torch==2.1.0
|
| 4 |
+
tokenizers==0.20.0
|
| 5 |
+
huggingface_hub==0.25.0
|
| 6 |
numpy<2.0.0
|
| 7 |
requests==2.31.0
|