Spaces:
Sleeping
Sleeping
Commit
Β·
8f83228
1
Parent(s):
3356a7c
fix issues with model loading
Browse files- app.py +9 -2
- requirements.txt +3 -1
- test_model.py +77 -0
app.py
CHANGED
@@ -10,13 +10,20 @@ def load_model():
|
|
10 |
global _classifier
|
11 |
if _classifier is None:
|
12 |
try:
|
|
|
13 |
_classifier = pipeline(
|
14 |
"text-classification",
|
15 |
model="YosefA/adfluence-intent-model",
|
16 |
-
return_all_scores=True
|
|
|
17 |
)
|
|
|
18 |
except Exception as e:
|
19 |
-
print(f"Error loading model: {e}")
|
|
|
|
|
|
|
|
|
20 |
return None
|
21 |
return _classifier
|
22 |
|
|
|
10 |
global _classifier
|
11 |
if _classifier is None:
|
12 |
try:
|
13 |
+
# Try loading with trust_remote_code for better compatibility
|
14 |
_classifier = pipeline(
|
15 |
"text-classification",
|
16 |
model="YosefA/adfluence-intent-model",
|
17 |
+
return_all_scores=True,
|
18 |
+
trust_remote_code=True
|
19 |
)
|
20 |
+
print("Model loaded successfully!")
|
21 |
except Exception as e:
|
22 |
+
print(f"Error loading model YosefA/adfluence-intent-model: {e}")
|
23 |
+
print("Please verify that:")
|
24 |
+
print("1. The model name is correct")
|
25 |
+
print("2. The model exists and is public")
|
26 |
+
print("3. You have internet connection")
|
27 |
return None
|
28 |
return _classifier
|
29 |
|
requirements.txt
CHANGED
@@ -2,4 +2,6 @@ gradio==4.44.0
|
|
2 |
transformers==4.36.0
|
3 |
torch==2.1.0
|
4 |
tokenizers==0.15.0
|
5 |
-
huggingface_hub==0.19.4
|
|
|
|
|
|
2 |
transformers==4.36.0
|
3 |
torch==2.1.0
|
4 |
tokenizers==0.15.0
|
5 |
+
huggingface_hub==0.19.4
|
6 |
+
numpy<2.0.0
|
7 |
+
requests==2.31.0
|
test_model.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
"""
|
3 |
+
Test script to verify if the Hugging Face model exists and can be loaded.
|
4 |
+
Run this to debug model loading issues.
|
5 |
+
"""
|
6 |
+
|
7 |
+
from transformers import pipeline
|
8 |
+
import requests
|
9 |
+
|
10 |
+
def test_model_exists(model_name):
|
11 |
+
"""Test if model exists on Hugging Face"""
|
12 |
+
url = f"https://huggingface.co/api/models/{model_name}"
|
13 |
+
try:
|
14 |
+
response = requests.get(url)
|
15 |
+
if response.status_code == 200:
|
16 |
+
print(f"β
Model {model_name} exists on Hugging Face")
|
17 |
+
model_info = response.json()
|
18 |
+
print(f" Pipeline tag: {model_info.get('pipeline_tag', 'Unknown')}")
|
19 |
+
print(f" Downloads: {model_info.get('downloads', 'Unknown')}")
|
20 |
+
return True
|
21 |
+
elif response.status_code == 404:
|
22 |
+
print(f"β Model {model_name} not found on Hugging Face")
|
23 |
+
return False
|
24 |
+
else:
|
25 |
+
print(f"β οΈ Unexpected response: {response.status_code}")
|
26 |
+
return False
|
27 |
+
except Exception as e:
|
28 |
+
print(f"β Error checking model: {e}")
|
29 |
+
return False
|
30 |
+
|
31 |
+
def test_model_loading(model_name):
|
32 |
+
"""Test loading the model with transformers"""
|
33 |
+
try:
|
34 |
+
print(f"\nπ Attempting to load model: {model_name}")
|
35 |
+
classifier = pipeline(
|
36 |
+
"text-classification",
|
37 |
+
model=model_name,
|
38 |
+
return_all_scores=True,
|
39 |
+
trust_remote_code=True
|
40 |
+
)
|
41 |
+
print("β
Model loaded successfully!")
|
42 |
+
|
43 |
+
# Test classification
|
44 |
+
test_text = "This product looks amazing!"
|
45 |
+
result = classifier(test_text)
|
46 |
+
print(f"β
Test classification successful:")
|
47 |
+
print(f" Input: '{test_text}'")
|
48 |
+
print(f" Output: {result}")
|
49 |
+
|
50 |
+
return True
|
51 |
+
|
52 |
+
except Exception as e:
|
53 |
+
print(f"β Error loading model: {e}")
|
54 |
+
return False
|
55 |
+
|
56 |
+
def main():
|
57 |
+
model_name = "YosefA/adfluence-intent-model"
|
58 |
+
|
59 |
+
print(f"π§ͺ Testing model: {model_name}")
|
60 |
+
print("=" * 50)
|
61 |
+
|
62 |
+
# Test 1: Check if model exists
|
63 |
+
exists = test_model_exists(model_name)
|
64 |
+
|
65 |
+
if exists:
|
66 |
+
# Test 2: Try loading the model
|
67 |
+
test_model_loading(model_name)
|
68 |
+
else:
|
69 |
+
print("\nπ‘ Suggestions:")
|
70 |
+
print("1. Check if the model name is spelled correctly")
|
71 |
+
print("2. Verify the model is public (not private)")
|
72 |
+
print("3. Check if you need to be logged in to access it")
|
73 |
+
print("4. Try searching for similar models:")
|
74 |
+
print(" https://huggingface.co/models?search=intent+classification")
|
75 |
+
|
76 |
+
if __name__ == "__main__":
|
77 |
+
main()
|