Spaces:
Build error
Build error
| #!/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() | |