Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Setup script for Inclusive World Curriculum Assistant | |
| """ | |
| import os | |
| import sys | |
| import subprocess | |
| import platform | |
| from pathlib import Path | |
| def check_python_version(): | |
| """Check if Python version is compatible""" | |
| if sys.version_info < (3, 8): | |
| print("β Error: Python 3.8 or higher is required") | |
| print(f"Current version: {sys.version}") | |
| return False | |
| print(f"β Python version: {sys.version}") | |
| return True | |
| def check_system_requirements(): | |
| """Check system requirements""" | |
| print("\nπ Checking system requirements...") | |
| # Check available memory (rough estimate) | |
| try: | |
| import psutil | |
| memory_gb = psutil.virtual_memory().total / (1024**3) | |
| print(f"π Available RAM: {memory_gb:.1f} GB") | |
| if memory_gb < 8: | |
| print("β οΈ Warning: Less than 8GB RAM detected. Model loading may be slow.") | |
| else: | |
| print("β Sufficient RAM detected") | |
| except ImportError: | |
| print("β οΈ psutil not available - cannot check RAM") | |
| # Check disk space | |
| try: | |
| disk_usage = psutil.disk_usage('.') | |
| free_gb = disk_usage.free / (1024**3) | |
| print(f"πΎ Available disk space: {free_gb:.1f} GB") | |
| if free_gb < 5: | |
| print("β οΈ Warning: Less than 5GB free space. Consider freeing up space.") | |
| else: | |
| print("β Sufficient disk space") | |
| except: | |
| print("β οΈ Could not check disk space") | |
| def install_dependencies(): | |
| """Install required dependencies""" | |
| print("\nπ¦ Installing dependencies...") | |
| try: | |
| # Upgrade pip first | |
| subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "pip"]) | |
| # Install requirements | |
| subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"]) | |
| print("β Dependencies installed successfully") | |
| return True | |
| except subprocess.CalledProcessError as e: | |
| print(f"β Error installing dependencies: {e}") | |
| return False | |
| def create_directories(): | |
| """Create necessary directories""" | |
| print("\nπ Creating directories...") | |
| directories = ["Slides", "chroma_db"] | |
| for directory in directories: | |
| Path(directory).mkdir(exist_ok=True) | |
| print(f"β Created directory: {directory}") | |
| def check_curriculum_files(): | |
| """Check if curriculum files exist""" | |
| print("\nπ Checking curriculum files...") | |
| slides_dir = Path("Slides") | |
| if not slides_dir.exists(): | |
| print("β οΈ Slides directory not found. Creating...") | |
| slides_dir.mkdir(exist_ok=True) | |
| pdf_files = list(slides_dir.glob("*.pdf")) | |
| if pdf_files: | |
| print(f"β Found {len(pdf_files)} curriculum PDF files:") | |
| for pdf in pdf_files: | |
| print(f" π {pdf.name}") | |
| else: | |
| print("β οΈ No PDF files found in Slides directory") | |
| print(" Please add your curriculum PDF files to the Slides/ directory") | |
| def create_sample_config(): | |
| """Create a sample configuration if needed""" | |
| print("\nβοΈ Checking configuration...") | |
| if not Path("config.py").exists(): | |
| print("β config.py not found. Please ensure it exists.") | |
| return False | |
| print("β Configuration file found") | |
| return True | |
| def test_imports(): | |
| """Test if key modules can be imported""" | |
| print("\nπ§ͺ Testing imports...") | |
| required_modules = [ | |
| "streamlit", | |
| "langchain", | |
| "chromadb", | |
| "transformers", | |
| "torch", | |
| "fitz" | |
| ] | |
| failed_imports = [] | |
| for module in required_modules: | |
| try: | |
| __import__(module) | |
| print(f"β {module}") | |
| except ImportError: | |
| print(f"β {module}") | |
| failed_imports.append(module) | |
| if failed_imports: | |
| print(f"\nβ Failed to import: {', '.join(failed_imports)}") | |
| return False | |
| print("β All required modules imported successfully") | |
| return True | |
| def main(): | |
| """Main setup function""" | |
| print("π Inclusive World Curriculum Assistant Setup") | |
| print("=" * 50) | |
| # Check Python version | |
| if not check_python_version(): | |
| sys.exit(1) | |
| # Check system requirements | |
| check_system_requirements() | |
| # Create directories | |
| create_directories() | |
| # Check curriculum files | |
| check_curriculum_files() | |
| # Check configuration | |
| if not create_sample_config(): | |
| sys.exit(1) | |
| # Install dependencies | |
| if not install_dependencies(): | |
| print("\nβ Setup failed. Please check the error messages above.") | |
| sys.exit(1) | |
| # Test imports | |
| if not test_imports(): | |
| print("\nβ Some modules failed to import. Please reinstall dependencies.") | |
| sys.exit(1) | |
| print("\nπ Setup completed successfully!") | |
| print("\nπ To start the application:") | |
| print(" streamlit run app.py") | |
| print("\nπ For more information, see README.md") | |
| if __name__ == "__main__": | |
| main() |