Spaces:
Sleeping
Sleeping
Commit
Β·
59c54cf
1
Parent(s):
d67fe33
Remove test script for HuggingFace conversion
Browse files- test_hf_conversion.py +0 -130
test_hf_conversion.py
DELETED
@@ -1,130 +0,0 @@
|
|
1 |
-
#!/usr/bin/env python3
|
2 |
-
"""
|
3 |
-
Test script to verify HuggingFace conversion works
|
4 |
-
"""
|
5 |
-
|
6 |
-
import sys
|
7 |
-
import os
|
8 |
-
|
9 |
-
def test_imports():
|
10 |
-
"""Test if all required imports work"""
|
11 |
-
try:
|
12 |
-
print("Testing imports...")
|
13 |
-
|
14 |
-
# Test basic imports
|
15 |
-
from PIL import Image
|
16 |
-
import io
|
17 |
-
print("β
PIL and io imports successful")
|
18 |
-
|
19 |
-
# Test transformers import
|
20 |
-
try:
|
21 |
-
from transformers import pipeline
|
22 |
-
print("β
transformers import successful")
|
23 |
-
except ImportError as e:
|
24 |
-
print(f"β transformers import failed: {e}")
|
25 |
-
return False
|
26 |
-
|
27 |
-
# Test torch import
|
28 |
-
try:
|
29 |
-
import torch
|
30 |
-
print(f"β
torch import successful (version: {torch.__version__})")
|
31 |
-
print(f" CUDA available: {torch.cuda.is_available()}")
|
32 |
-
except ImportError as e:
|
33 |
-
print(f"β torch import failed: {e}")
|
34 |
-
return False
|
35 |
-
|
36 |
-
return True
|
37 |
-
|
38 |
-
except Exception as e:
|
39 |
-
print(f"β Import test failed: {e}")
|
40 |
-
return False
|
41 |
-
|
42 |
-
def test_pipeline_creation():
|
43 |
-
"""Test if we can create the HuggingFace pipeline"""
|
44 |
-
try:
|
45 |
-
print("\nTesting pipeline creation...")
|
46 |
-
|
47 |
-
from transformers import pipeline
|
48 |
-
|
49 |
-
# Try to create image captioning pipeline
|
50 |
-
print("Creating image-to-text pipeline...")
|
51 |
-
image_to_text = pipeline(
|
52 |
-
"image-to-text",
|
53 |
-
model="Salesforce/blip-image-captioning-base",
|
54 |
-
device=-1 # Force CPU to avoid GPU issues
|
55 |
-
)
|
56 |
-
print("β
Image-to-text pipeline created successfully")
|
57 |
-
|
58 |
-
return True
|
59 |
-
|
60 |
-
except Exception as e:
|
61 |
-
print(f"β Pipeline creation failed: {e}")
|
62 |
-
return False
|
63 |
-
|
64 |
-
def test_basic_functionality():
|
65 |
-
"""Test basic functionality with a simple image"""
|
66 |
-
try:
|
67 |
-
print("\nTesting basic functionality...")
|
68 |
-
|
69 |
-
from transformers import pipeline
|
70 |
-
from PIL import Image
|
71 |
-
import io
|
72 |
-
|
73 |
-
# Create a simple test image
|
74 |
-
test_image = Image.new('RGB', (100, 100), color='red')
|
75 |
-
|
76 |
-
# Create pipeline
|
77 |
-
image_to_text = pipeline(
|
78 |
-
"image-to-text",
|
79 |
-
model="Salesforce/blip-image-captioning-base",
|
80 |
-
device=-1
|
81 |
-
)
|
82 |
-
|
83 |
-
# Test image captioning
|
84 |
-
result = image_to_text(test_image)
|
85 |
-
print(f"β
Image captioning successful: {result}")
|
86 |
-
|
87 |
-
return True
|
88 |
-
|
89 |
-
except Exception as e:
|
90 |
-
print(f"β Basic functionality test failed: {e}")
|
91 |
-
return False
|
92 |
-
|
93 |
-
def main():
|
94 |
-
"""Run all tests"""
|
95 |
-
print("π§ͺ Testing HuggingFace Fashion Analyzer Conversion")
|
96 |
-
print("=" * 50)
|
97 |
-
|
98 |
-
tests = [
|
99 |
-
("Import Test", test_imports),
|
100 |
-
("Pipeline Creation Test", test_pipeline_creation),
|
101 |
-
("Basic Functionality Test", test_basic_functionality)
|
102 |
-
]
|
103 |
-
|
104 |
-
passed = 0
|
105 |
-
total = len(tests)
|
106 |
-
|
107 |
-
for test_name, test_func in tests:
|
108 |
-
print(f"\nπ Running {test_name}...")
|
109 |
-
try:
|
110 |
-
if test_func():
|
111 |
-
print(f"β
{test_name} PASSED")
|
112 |
-
passed += 1
|
113 |
-
else:
|
114 |
-
print(f"β {test_name} FAILED")
|
115 |
-
except Exception as e:
|
116 |
-
print(f"β {test_name} FAILED with exception: {e}")
|
117 |
-
|
118 |
-
print("\n" + "=" * 50)
|
119 |
-
print(f"π Test Results: {passed}/{total} tests passed")
|
120 |
-
|
121 |
-
if passed == total:
|
122 |
-
print("π All tests passed! HuggingFace conversion is ready.")
|
123 |
-
return True
|
124 |
-
else:
|
125 |
-
print("β οΈ Some tests failed. Check the errors above.")
|
126 |
-
return False
|
127 |
-
|
128 |
-
if __name__ == "__main__":
|
129 |
-
success = main()
|
130 |
-
sys.exit(0 if success else 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|