File size: 6,310 Bytes
599c2c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/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()