Spaces:
Sleeping
Sleeping
| # organize_structure.py - RUN THIS IN HF SPACE | |
| import os | |
| import shutil | |
| import json | |
| print("π Reorganizing AumCore AI Structure...") | |
| print("="*60) | |
| # 1. Create folders | |
| folders = ['modules', 'config', 'core', 'logs', 'data'] | |
| for folder in folders: | |
| os.makedirs(folder, exist_ok=True) | |
| print(f"β Created: {folder}/") | |
| # 2. Create __init__.py files | |
| for folder in ['modules', 'core', 'config']: | |
| init_file = os.path.join(folder, '__init__.py') | |
| with open(init_file, 'w') as f: | |
| f.write('# Package initializer\n') | |
| print(f"β Created: {init_file}") | |
| # 3. Create modules.json | |
| modules_config = { | |
| "enabled_modules": ["orchestrator", "testing", "diagnostics"], | |
| "auto_start": True, | |
| "module_settings": { | |
| "orchestrator": {"enabled": True, "background_tasks": True}, | |
| "testing": {"auto_test": False, "test_on_startup": True}, | |
| "diagnostics": {"auto_run": True, "interval_minutes": 60} | |
| } | |
| } | |
| config_file = 'config/modules.json' | |
| with open(config_file, 'w') as f: | |
| json.dump(modules_config, f, indent=4) | |
| print(f"β Created: {config_file}") | |
| # 4. MOVE EXISTING FILES (Check each one) | |
| files_to_move = [ | |
| ('system_orchestrator.py', 'modules/orchestrator.py'), | |
| ('test_runner.py', 'modules/testing.py'), | |
| ('language_detector.py', 'core/language_detector.py'), | |
| ('memory_db.py', 'core/memory_db.py'), | |
| ('ai_core.py', 'core/ai_core.py'), | |
| ('reasoning_core.py', 'core/reasoning_core.py'), | |
| ('chain_of_thought_manager.py', 'core/chain_of_thought_manager.py'), | |
| ('long_term_memory.py', 'core/long_term_memory.py'), | |
| ('short_term_memory.py', 'core/short_term_memory.py'), | |
| ('config.py', 'core/config.py'), | |
| ] | |
| print("\nπ Moving files:") | |
| for old, new in files_to_move: | |
| if os.path.exists(old): | |
| shutil.move(old, new) | |
| print(f" π¦ {old} β {new}") | |
| else: | |
| print(f" β οΈ {old} not found (already moved or doesn't exist)") | |
| # 5. Create diagnostics module | |
| print("\nπ§ Creating diagnostics module...") | |
| diag_code = '''# modules/diagnostics.py - System Health Monitoring | |
| from fastapi import APIRouter | |
| import psutil | |
| from datetime import datetime | |
| def register_module(app, client, username): | |
| router = APIRouter() | |
| @router.get("/system/diagnostics/summary") | |
| async def diagnostics_summary(): | |
| """Get system health summary""" | |
| try: | |
| cpu = psutil.cpu_percent() | |
| memory = psutil.virtual_memory() | |
| disk = psutil.disk_usage('/') | |
| return { | |
| "success": True, | |
| "health_score": calculate_health_score(cpu, memory.percent, disk.percent), | |
| "cpu_used": cpu, | |
| "memory_used": memory.percent, | |
| "disk_used": disk.percent, | |
| "timestamp": datetime.now().isoformat() | |
| } | |
| except Exception as e: | |
| return {"success": False, "error": str(e)} | |
| @router.get("/system/diagnostics/full") | |
| async def diagnostics_full(): | |
| """Complete diagnostics report""" | |
| try: | |
| from modules.orchestrator import get_system_diagnostics | |
| return await get_system_diagnostics() | |
| except ImportError: | |
| return {"success": False, "error": "Orchestrator module not available"} | |
| def calculate_health_score(cpu, memory, disk): | |
| """Calculate health score 0-100""" | |
| score = 100 | |
| if cpu > 90: score -= 20 | |
| elif cpu > 70: score -= 10 | |
| if memory > 90: score -= 20 | |
| elif memory > 70: score -= 10 | |
| if disk > 90: score -= 15 | |
| elif disk > 70: score -= 5 | |
| return max(0, min(100, score)) | |
| app.include_router(router) | |
| print("β Diagnostics module registered") | |
| # For direct imports | |
| async def run_diagnostics(): | |
| return await diagnostics_full() | |
| ''' | |
| with open('modules/diagnostics.py', 'w') as f: | |
| f.write(diag_code) | |
| print("β Created: modules/diagnostics.py") | |
| # 6. Show final structure | |
| print("\n" + "="*60) | |
| print("π FINAL STRUCTURE:") | |
| print("="*60) | |
| for root, dirs, files in os.walk('.'): | |
| # Skip hidden directories | |
| dirs[:] = [d for d in dirs if not d.startswith('.')] | |
| level = root.count(os.sep) | |
| indent = ' ' * level | |
| print(f"{indent}{os.path.basename(root)}/") | |
| subindent = ' ' * (level + 1) | |
| for file in files: | |
| if file.endswith(('.py', '.json', '.txt')): | |
| print(f"{subindent}{file}") | |
| print("="*60) | |
| print("β Structure organized successfully!") | |
| print("π Next steps:") | |
| print(" 1. Use the FINAL app.py I provided") | |
| print(" 2. Restart the Space") | |
| print(" 3. Test endpoints") | |
| print("="*60) |