Spaces:
Running
Running
| #!/usr/bin/env python3 | |
| """ | |
| Quick fix script to check and resolve import issues | |
| """ | |
| import sys | |
| import importlib | |
| from pathlib import Path | |
| def check_imports(): | |
| """Check if all required modules can be imported""" | |
| print("π Checking imports...") | |
| # Core Python modules | |
| core_modules = [ | |
| 'os', 'sys', 'asyncio', 'logging', 'uuid', 'json', 'shutil', | |
| 'pathlib', 'datetime', 'typing' | |
| ] | |
| # FastAPI modules | |
| fastapi_modules = [ | |
| 'fastapi', 'uvicorn', 'pydantic' | |
| ] | |
| # ML modules | |
| ml_modules = [ | |
| 'torch', 'transformers', 'datasets', 'safetensors' | |
| ] | |
| # Utility modules | |
| utility_modules = [ | |
| 'numpy', 'pillow', 'requests', 'psutil', 'cryptography' | |
| ] | |
| # Optional modules | |
| optional_modules = [ | |
| 'cv2', 'pydicom', 'SimpleITK', 'intel_extension_for_pytorch' | |
| ] | |
| all_good = True | |
| # Check core modules | |
| print("\nπ¦ Core Python modules:") | |
| for module in core_modules: | |
| try: | |
| importlib.import_module(module) | |
| print(f" β {module}") | |
| except ImportError as e: | |
| print(f" β {module}: {e}") | |
| all_good = False | |
| # Check FastAPI modules | |
| print("\nπ FastAPI modules:") | |
| for module in fastapi_modules: | |
| try: | |
| importlib.import_module(module) | |
| print(f" β {module}") | |
| except ImportError as e: | |
| print(f" β {module}: {e}") | |
| all_good = False | |
| # Check ML modules | |
| print("\nπ€ Machine Learning modules:") | |
| for module in ml_modules: | |
| try: | |
| importlib.import_module(module) | |
| print(f" β {module}") | |
| except ImportError as e: | |
| print(f" β {module}: {e}") | |
| all_good = False | |
| # Check utility modules | |
| print("\nπ§ Utility modules:") | |
| for module in utility_modules: | |
| try: | |
| if module == 'pillow': | |
| importlib.import_module('PIL') | |
| elif module == 'opencv-python': | |
| importlib.import_module('cv2') | |
| else: | |
| importlib.import_module(module) | |
| print(f" β {module}") | |
| except ImportError as e: | |
| print(f" β {module}: {e}") | |
| all_good = False | |
| # Check optional modules | |
| print("\nπ Optional modules:") | |
| for module in optional_modules: | |
| try: | |
| importlib.import_module(module) | |
| print(f" β {module}") | |
| except ImportError as e: | |
| print(f" β οΈ {module}: {e} (optional)") | |
| return all_good | |
| def check_custom_modules(): | |
| """Check if custom modules can be imported""" | |
| print("\nποΈ Custom modules:") | |
| custom_modules = [ | |
| 'src.model_loader', | |
| 'src.distillation', | |
| 'src.utils', | |
| 'src.core.memory_manager', | |
| 'src.core.chunk_loader', | |
| 'src.core.cpu_optimizer', | |
| 'src.core.token_manager', | |
| 'src.medical.medical_datasets', | |
| 'src.medical.dicom_handler', | |
| 'src.medical.medical_preprocessing', | |
| 'database.database', | |
| 'database.models' | |
| ] | |
| all_good = True | |
| for module in custom_modules: | |
| try: | |
| importlib.import_module(module) | |
| print(f" β {module}") | |
| except ImportError as e: | |
| print(f" β {module}: {e}") | |
| all_good = False | |
| except Exception as e: | |
| print(f" β οΈ {module}: {e} (import error)") | |
| all_good = False | |
| return all_good | |
| def check_files(): | |
| """Check if required files exist""" | |
| print("\nπ Required files:") | |
| required_files = [ | |
| 'app.py', | |
| 'requirements.txt', | |
| 'src/__init__.py', | |
| 'src/model_loader.py', | |
| 'src/distillation.py', | |
| 'src/utils.py', | |
| 'src/core/__init__.py', | |
| 'src/medical/__init__.py', | |
| 'database/__init__.py', | |
| 'templates/index.html', | |
| 'templates/token-management.html', | |
| 'templates/medical-datasets.html', | |
| 'static/css/style.css', | |
| 'static/js/main.js' | |
| ] | |
| all_good = True | |
| for file_path in required_files: | |
| path = Path(file_path) | |
| if path.exists(): | |
| print(f" β {file_path}") | |
| else: | |
| print(f" β {file_path}") | |
| all_good = False | |
| return all_good | |
| def main(): | |
| """Main function""" | |
| print("π AI Knowledge Distillation Platform - Import Checker") | |
| print("=" * 60) | |
| # Check imports | |
| imports_ok = check_imports() | |
| # Check custom modules | |
| custom_ok = check_custom_modules() | |
| # Check files | |
| files_ok = check_files() | |
| print("\n" + "=" * 60) | |
| if imports_ok and custom_ok and files_ok: | |
| print("β All checks passed! The application should start successfully.") | |
| return 0 | |
| else: | |
| print("β Some checks failed. Please fix the issues above.") | |
| if not imports_ok: | |
| print("\nπ‘ To fix import issues:") | |
| print(" pip install -r requirements.txt") | |
| if not custom_ok: | |
| print("\nπ‘ To fix custom module issues:") | |
| print(" Check that all Python files are properly created") | |
| print(" Ensure __init__.py files exist in all directories") | |
| if not files_ok: | |
| print("\nπ‘ To fix missing files:") | |
| print(" Ensure all required files are created") | |
| print(" Check templates and static directories") | |
| return 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |