Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Test script to verify project setup and dependencies | |
| """ | |
| import sys | |
| import os | |
| import importlib | |
| from pathlib import Path | |
| def test_python_version(): | |
| """Test Python version""" | |
| print("π Python Version Check") | |
| version = sys.version_info | |
| print(f" Python {version.major}.{version.minor}.{version.micro}") | |
| if version.major >= 3 and version.minor >= 8: | |
| print(" β Python version OK") | |
| return True | |
| else: | |
| print(" β Python 3.8+ required") | |
| return False | |
| def test_dependencies(): | |
| """Test required dependencies""" | |
| print("\nπ¦ Dependency Check") | |
| required_packages = [ | |
| 'requests', | |
| 'beautifulsoup4', | |
| 'pandas', | |
| 'numpy', | |
| 'tqdm', | |
| 'gradio' | |
| ] | |
| optional_packages = [ | |
| 'torch', | |
| 'transformers', | |
| 'datasets', | |
| 'peft', | |
| 'bitsandbytes', | |
| 'accelerate' | |
| ] | |
| all_good = True | |
| for package in required_packages: | |
| try: | |
| importlib.import_module(package) | |
| print(f" β {package}") | |
| except ImportError: | |
| print(f" β {package} (required)") | |
| all_good = False | |
| print("\n Optional ML packages:") | |
| for package in optional_packages: | |
| try: | |
| importlib.import_module(package) | |
| print(f" β {package}") | |
| except ImportError: | |
| print(f" β οΈ {package} (optional, needed for training)") | |
| return all_good | |
| def test_project_structure(): | |
| """Test project file structure""" | |
| print("\nπ Project Structure Check") | |
| required_files = [ | |
| 'requirements.txt', | |
| 'app.py', | |
| 'run_pipeline.py', | |
| 'README.md', | |
| 'src/scraper.py', | |
| 'src/preprocess.py', | |
| 'src/finetune.py', | |
| 'src/utils.py' | |
| ] | |
| required_dirs = [ | |
| 'src', | |
| 'data', | |
| 'models', | |
| 'models/lora_adapters' | |
| ] | |
| all_good = True | |
| for file_path in required_files: | |
| if os.path.exists(file_path): | |
| print(f" β {file_path}") | |
| else: | |
| print(f" β {file_path}") | |
| all_good = False | |
| for dir_path in required_dirs: | |
| if os.path.exists(dir_path): | |
| print(f" β {dir_path}/") | |
| else: | |
| print(f" β {dir_path}/") | |
| all_good = False | |
| return all_good | |
| def test_gpu_availability(): | |
| """Test GPU availability""" | |
| print("\nπ₯οΈ Hardware Check") | |
| try: | |
| import torch | |
| print(f" PyTorch version: {torch.__version__}") | |
| if torch.cuda.is_available(): | |
| gpu_count = torch.cuda.device_count() | |
| print(f" β CUDA available ({gpu_count} GPU(s))") | |
| for i in range(gpu_count): | |
| props = torch.cuda.get_device_properties(i) | |
| memory_gb = props.total_memory / 1e9 | |
| print(f" GPU {i}: {props.name} ({memory_gb:.1f} GB)") | |
| return True | |
| else: | |
| print(" β οΈ CUDA not available (CPU training only)") | |
| return False | |
| except ImportError: | |
| print(" β PyTorch not installed") | |
| return False | |
| def test_internet_connection(): | |
| """Test internet connectivity""" | |
| print("\nπ Internet Connection Check") | |
| try: | |
| import requests | |
| response = requests.get('https://www.lightreading.com', timeout=10) | |
| if response.status_code == 200: | |
| print(" β Light Reading accessible") | |
| return True | |
| else: | |
| print(f" β οΈ Light Reading returned status {response.status_code}") | |
| return False | |
| except Exception as e: | |
| print(f" β Internet connection failed: {e}") | |
| return False | |
| def run_basic_import_test(): | |
| """Test basic imports from project modules""" | |
| print("\nπ§ Module Import Check") | |
| sys.path.append(str(Path(__file__).parent / "src")) | |
| modules_to_test = [ | |
| ('scraper', 'LightReadingScraper'), | |
| ('preprocess', 'ArticlePreprocessor'), | |
| ('utils', 'setup_logging') | |
| ] | |
| all_good = True | |
| for module_name, class_name in modules_to_test: | |
| try: | |
| module = importlib.import_module(module_name) | |
| getattr(module, class_name) | |
| print(f" β {module_name}.{class_name}") | |
| except Exception as e: | |
| print(f" β {module_name}.{class_name}: {e}") | |
| all_good = False | |
| return all_good | |
| def main(): | |
| """Run all tests""" | |
| print("π§ͺ MORRIS-BOT PROJECT SETUP TEST") | |
| print("=" * 50) | |
| tests = [ | |
| ("Python Version", test_python_version), | |
| ("Dependencies", test_dependencies), | |
| ("Project Structure", test_project_structure), | |
| ("GPU Availability", test_gpu_availability), | |
| ("Internet Connection", test_internet_connection), | |
| ("Module Imports", run_basic_import_test) | |
| ] | |
| results = [] | |
| for test_name, test_func in tests: | |
| try: | |
| result = test_func() | |
| results.append((test_name, result)) | |
| except Exception as e: | |
| print(f" β Test failed with error: {e}") | |
| results.append((test_name, False)) | |
| # Summary | |
| print("\n" + "=" * 50) | |
| print("π TEST SUMMARY") | |
| print("=" * 50) | |
| passed = sum(1 for _, result in results if result) | |
| total = len(results) | |
| for test_name, result in results: | |
| status = "β PASS" if result else "β FAIL" | |
| print(f" {status} {test_name}") | |
| print(f"\nOverall: {passed}/{total} tests passed") | |
| if passed == total: | |
| print("\nπ All tests passed! Your setup is ready.") | |
| print("\nNext steps:") | |
| print(" 1. Run: python run_pipeline.py --status") | |
| print(" 2. Run: python run_pipeline.py --collect") | |
| else: | |
| print("\nβ οΈ Some tests failed. Please check the issues above.") | |
| print("\nCommon fixes:") | |
| print(" - Install missing packages: pip install -r requirements.txt") | |
| print(" - Check internet connection") | |
| print(" - Install PyTorch for GPU support") | |
| if __name__ == "__main__": | |
| main() | |