Spaces:
Build error
Build error
File size: 4,142 Bytes
298d6c1 |
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
#!/usr/bin/env python3
"""
Test script to verify the build configuration
"""
import sys
import subprocess
from pathlib import Path
def test_imports():
"""Test if all required packages can be imported"""
print("π Testing package imports...")
required_packages = [
"torch",
"transformers",
"accelerate",
"peft",
"datasets",
"gradio",
"flask",
"requests",
"numpy",
"sklearn"
]
failed_imports = []
for package in required_packages:
try:
__import__(package)
print(f"β
{package}")
except ImportError as e:
print(f"β {package}: {e}")
failed_imports.append(package)
return len(failed_imports) == 0
def test_scripts():
"""Test if scripts can be found and are executable"""
print("\nπ Testing scripts...")
scripts_dir = Path("scripts")
if not scripts_dir.exists():
print("β Scripts directory not found")
return False
required_scripts = [
"check_training_ready.py",
"create_sample_dataset.py",
"setup_textilindo_training.py",
"train_textilindo_ai.py",
"test_textilindo_ai.py"
]
missing_scripts = []
for script in required_scripts:
script_path = scripts_dir / script
if script_path.exists():
print(f"β
{script}")
else:
print(f"β {script} not found")
missing_scripts.append(script)
return len(missing_scripts) == 0
def test_config_files():
"""Test if configuration files exist"""
print("\nπ Testing configuration files...")
config_files = [
"requirements.txt",
"app.py",
"app_hf_spaces.py",
"health_check.py"
]
missing_files = []
for config_file in config_files:
if Path(config_file).exists():
print(f"β
{config_file}")
else:
print(f"β {config_file} not found")
missing_files.append(config_file)
return len(missing_files) == 0
def test_script_execution():
"""Test if a simple script can be executed"""
print("\nπ Testing script execution...")
try:
# Test the check_training_ready script
result = subprocess.run([
sys.executable, "scripts/check_training_ready.py"
], capture_output=True, text=True, timeout=30)
if result.returncode == 0:
print("β
Script execution successful")
return True
else:
print(f"β Script execution failed: {result.stderr}")
return False
except subprocess.TimeoutExpired:
print("β Script execution timed out")
return False
except Exception as e:
print(f"β Script execution error: {e}")
return False
def main():
"""Main test function"""
print("π§ͺ Textilindo AI Assistant - Build Test")
print("=" * 50)
tests = [
("Package Imports", test_imports),
("Scripts Availability", test_scripts),
("Configuration Files", test_config_files),
("Script Execution", test_script_execution)
]
results = []
for test_name, test_func in tests:
print(f"\nπ {test_name}")
print("-" * 30)
result = test_func()
results.append((test_name, result))
print("\n" + "=" * 50)
print("π Test Results:")
all_passed = True
for test_name, result in results:
status = "β
PASS" if result else "β FAIL"
print(f"{status} {test_name}")
if not result:
all_passed = False
if all_passed:
print("\nπ All tests passed! Build configuration is ready.")
print("\nπ Next steps:")
print("1. Push to Hugging Face Space")
print("2. Set environment variables")
print("3. Deploy and test")
else:
print("\nβ Some tests failed. Please fix the issues above.")
sys.exit(1)
if __name__ == "__main__":
main()
|