-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_model_loading.py
More file actions
87 lines (75 loc) · 2.97 KB
/
Copy pathdebug_model_loading.py
File metadata and controls
87 lines (75 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python3
"""
Debug Model Loading Issues
Get detailed information about why the model is not loading properly.
"""
import requests
import json
import time
import argparse
from test_config import create_api_client, create_test_config
def debug_model_loading():
"""Debug the model loading issues"""
config = create_test_config()
client = create_api_client()
print("🔍 Debugging Model Loading Issues")
print("=" * 50)
print(f"Testing URL: {config.base_url}")
print(f"API Key: {config.api_key[:20]}...")
# Test model status with API key
print("\n1. Testing model status with API key...")
try:
data = client.get("/model_status")
print(f" ✅ Model Status: {json.dumps(data, indent=2)}")
except requests.exceptions.RequestException as e:
if "401" in str(e):
print(" 🔐 Unauthorized - API key mismatch")
else:
print(f" ❌ Model status error: {e}")
# Test security status
print("\n2. Testing security status...")
try:
data = client.get("/security_status")
print(f" ✅ Security Status: {json.dumps(data, indent=2)}")
except requests.exceptions.RequestException as e:
print(f" ❌ Security status error: {e}")
# Test prediction with detailed error analysis
print("\n3. Testing prediction with error analysis...")
try:
payload = {"text": "I am happy"}
data = client.post("/predict", payload)
print(f" ✅ Prediction successful: {json.dumps(data, indent=2)}")
except requests.exceptions.RequestException as e:
print(f" ❌ Prediction error: {e}")
except ValueError as e:
print(f" ❌ Invalid response format: {e}")
# Test batch prediction
print("\n4. Testing batch prediction...")
try:
payload = {"texts": ["I am happy", "I am sad", "I am excited"]}
data = client.post("/predict_batch", payload)
print(f" ✅ Batch prediction successful: {json.dumps(data, indent=2)}")
except requests.exceptions.RequestException as e:
print(f" ❌ Batch prediction error: {e}")
except ValueError as e:
print(f" ❌ Invalid response format: {e}")
# Test with different input formats
print("\n5. Testing different input formats...")
test_cases = [
{"text": "I am happy"},
{"text": "This is a test"},
{"text": "I feel great"},
{"text": ""}, # Empty text
{"invalid": "field"}, # Invalid payload
]
for i, test_case in enumerate(test_cases):
print(f" Test case {i+1}: {test_case}")
try:
data = client.post("/predict", test_case)
print(f" ✅ Success: {data.get('emotion', 'Unknown')}")
except requests.exceptions.RequestException as e:
print(f" ❌ Request failed: {e}")
except ValueError as e:
print(f" ❌ Invalid response: {e}")
if __name__ == "__main__":
debug_model_loading()