|
import sys
|
|
import pkg_resources
|
|
import torch
|
|
import os
|
|
from pathlib import Path
|
|
import psutil
|
|
|
|
def check_system_resources():
|
|
"""Check available system resources"""
|
|
try:
|
|
memory = psutil.virtual_memory()
|
|
available_gb = memory.available / (1024 * 1024 * 1024)
|
|
|
|
print("\n💾 System Resources:")
|
|
print(f"- Available Memory: {available_gb:.1f}GB")
|
|
|
|
if available_gb < 2:
|
|
print("⚠️ Warning: Low available memory. This might affect performance.")
|
|
print(" Consider closing other applications or increasing virtual memory.")
|
|
|
|
|
|
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
|
print(f"- Using Device: {device.upper()}")
|
|
|
|
if device == 'cpu':
|
|
print("ℹ️ Note: Using CPU for computations. GPU would provide better performance.")
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f"Error checking system resources: {str(e)}")
|
|
return False
|
|
|
|
def check_setup():
|
|
"""Check if all dependencies are properly installed"""
|
|
required = {
|
|
'google-generativeai': '0.3.0',
|
|
'faiss-cpu': '1.7.4',
|
|
'langchain': '0.1.0',
|
|
'python-dotenv': '1.0.0',
|
|
'sentence-transformers': '2.2.2',
|
|
'torch': '2.0.0',
|
|
'streamlit': '1.30.0',
|
|
'langchain-community': '0.0.13',
|
|
'tqdm': '4.66.1',
|
|
'numpy': '1.24.0',
|
|
'psutil': '5.8.0'
|
|
}
|
|
|
|
missing = []
|
|
for package, version in required.items():
|
|
try:
|
|
pkg_resources.require(f"{package}>={version}")
|
|
except (pkg_resources.VersionConflict, pkg_resources.DistributionNotFound):
|
|
missing.append(package)
|
|
|
|
if missing:
|
|
print("\n❌ Missing or incompatible packages:")
|
|
for package in missing:
|
|
print(f" - {package}")
|
|
print("\nTo fix: pip install -r requirements.txt")
|
|
return False
|
|
|
|
|
|
if not Path('.env').exists():
|
|
print("\n❌ Configuration Missing:")
|
|
print("Please create a .env file with your GOOGLE_API_KEY")
|
|
return False
|
|
|
|
if not Path('./documents').exists():
|
|
print("\n❌ Study Materials Missing:")
|
|
print("Please create a 'documents' folder and add your PDF study materials")
|
|
return False
|
|
|
|
|
|
if Path('./documents').exists():
|
|
total_size = 0
|
|
for pdf in Path('./documents').glob('**/*.pdf'):
|
|
total_size += pdf.stat().st_size
|
|
|
|
total_size_mb = total_size / (1024 * 1024)
|
|
if total_size_mb > 500:
|
|
print(f"\n⚠️ Large Document Set ({total_size_mb:.1f}MB):")
|
|
print("Consider splitting documents into smaller chunks or increasing available memory")
|
|
|
|
print("\n✅ Basic setup verification complete")
|
|
return True
|
|
|
|
def verify_model():
|
|
"""Verify the GTE embedding model is working"""
|
|
try:
|
|
from sentence_transformers import SentenceTransformer
|
|
print("\n🔄 Loading GTE embedding model...")
|
|
|
|
|
|
test_model = SentenceTransformer('thenlper/gte-large')
|
|
test_text = "Test sentence for memory usage verification."
|
|
_ = test_model.encode(test_text, show_progress_bar=False)
|
|
|
|
print("✓ GTE embedding model verified")
|
|
|
|
|
|
del test_model
|
|
import gc
|
|
gc.collect()
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f"\n❌ Error loading GTE embedding model: {str(e)}")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
print("\n🔍 Starting system verification...")
|
|
check_system_resources()
|
|
if check_setup():
|
|
verify_model() |