Spaces:
Sleeping
Sleeping
Create organize_structure.py
Browse files- organize_structure.py +145 -0
organize_structure.py
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# organize_structure.py - RUN THIS IN HF SPACE
|
| 2 |
+
import os
|
| 3 |
+
import shutil
|
| 4 |
+
import json
|
| 5 |
+
|
| 6 |
+
print("π Reorganizing AumCore AI Structure...")
|
| 7 |
+
print("="*60)
|
| 8 |
+
|
| 9 |
+
# 1. Create folders
|
| 10 |
+
folders = ['modules', 'config', 'core', 'logs', 'data']
|
| 11 |
+
for folder in folders:
|
| 12 |
+
os.makedirs(folder, exist_ok=True)
|
| 13 |
+
print(f"β
Created: {folder}/")
|
| 14 |
+
|
| 15 |
+
# 2. Create __init__.py files
|
| 16 |
+
for folder in ['modules', 'core', 'config']:
|
| 17 |
+
init_file = os.path.join(folder, '__init__.py')
|
| 18 |
+
with open(init_file, 'w') as f:
|
| 19 |
+
f.write('# Package initializer\n')
|
| 20 |
+
print(f"β
Created: {init_file}")
|
| 21 |
+
|
| 22 |
+
# 3. Create modules.json
|
| 23 |
+
modules_config = {
|
| 24 |
+
"enabled_modules": ["orchestrator", "testing", "diagnostics"],
|
| 25 |
+
"auto_start": True,
|
| 26 |
+
"module_settings": {
|
| 27 |
+
"orchestrator": {"enabled": True, "background_tasks": True},
|
| 28 |
+
"testing": {"auto_test": False, "test_on_startup": True},
|
| 29 |
+
"diagnostics": {"auto_run": True, "interval_minutes": 60}
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
config_file = 'config/modules.json'
|
| 34 |
+
with open(config_file, 'w') as f:
|
| 35 |
+
json.dump(modules_config, f, indent=4)
|
| 36 |
+
print(f"β
Created: {config_file}")
|
| 37 |
+
|
| 38 |
+
# 4. MOVE EXISTING FILES (Check each one)
|
| 39 |
+
files_to_move = [
|
| 40 |
+
('system_orchestrator.py', 'modules/orchestrator.py'),
|
| 41 |
+
('test_runner.py', 'modules/testing.py'),
|
| 42 |
+
('language_detector.py', 'core/language_detector.py'),
|
| 43 |
+
('memory_db.py', 'core/memory_db.py'),
|
| 44 |
+
('ai_core.py', 'core/ai_core.py'),
|
| 45 |
+
('reasoning_core.py', 'core/reasoning_core.py'),
|
| 46 |
+
('chain_of_thought_manager.py', 'core/chain_of_thought_manager.py'),
|
| 47 |
+
('long_term_memory.py', 'core/long_term_memory.py'),
|
| 48 |
+
('short_term_memory.py', 'core/short_term_memory.py'),
|
| 49 |
+
('config.py', 'core/config.py'),
|
| 50 |
+
]
|
| 51 |
+
|
| 52 |
+
print("\nπ Moving files:")
|
| 53 |
+
for old, new in files_to_move:
|
| 54 |
+
if os.path.exists(old):
|
| 55 |
+
shutil.move(old, new)
|
| 56 |
+
print(f" π¦ {old} β {new}")
|
| 57 |
+
else:
|
| 58 |
+
print(f" β οΈ {old} not found (already moved or doesn't exist)")
|
| 59 |
+
|
| 60 |
+
# 5. Create diagnostics module
|
| 61 |
+
print("\nπ§ Creating diagnostics module...")
|
| 62 |
+
diag_code = '''# modules/diagnostics.py - System Health Monitoring
|
| 63 |
+
from fastapi import APIRouter
|
| 64 |
+
import psutil
|
| 65 |
+
from datetime import datetime
|
| 66 |
+
|
| 67 |
+
def register_module(app, client, username):
|
| 68 |
+
router = APIRouter()
|
| 69 |
+
|
| 70 |
+
@router.get("/system/diagnostics/summary")
|
| 71 |
+
async def diagnostics_summary():
|
| 72 |
+
"""Get system health summary"""
|
| 73 |
+
try:
|
| 74 |
+
cpu = psutil.cpu_percent()
|
| 75 |
+
memory = psutil.virtual_memory()
|
| 76 |
+
disk = psutil.disk_usage('/')
|
| 77 |
+
|
| 78 |
+
return {
|
| 79 |
+
"success": True,
|
| 80 |
+
"health_score": calculate_health_score(cpu, memory.percent, disk.percent),
|
| 81 |
+
"cpu_used": cpu,
|
| 82 |
+
"memory_used": memory.percent,
|
| 83 |
+
"disk_used": disk.percent,
|
| 84 |
+
"timestamp": datetime.now().isoformat()
|
| 85 |
+
}
|
| 86 |
+
except Exception as e:
|
| 87 |
+
return {"success": False, "error": str(e)}
|
| 88 |
+
|
| 89 |
+
@router.get("/system/diagnostics/full")
|
| 90 |
+
async def diagnostics_full():
|
| 91 |
+
"""Complete diagnostics report"""
|
| 92 |
+
try:
|
| 93 |
+
from modules.orchestrator import get_system_diagnostics
|
| 94 |
+
return await get_system_diagnostics()
|
| 95 |
+
except ImportError:
|
| 96 |
+
return {"success": False, "error": "Orchestrator module not available"}
|
| 97 |
+
|
| 98 |
+
def calculate_health_score(cpu, memory, disk):
|
| 99 |
+
"""Calculate health score 0-100"""
|
| 100 |
+
score = 100
|
| 101 |
+
if cpu > 90: score -= 20
|
| 102 |
+
elif cpu > 70: score -= 10
|
| 103 |
+
if memory > 90: score -= 20
|
| 104 |
+
elif memory > 70: score -= 10
|
| 105 |
+
if disk > 90: score -= 15
|
| 106 |
+
elif disk > 70: score -= 5
|
| 107 |
+
return max(0, min(100, score))
|
| 108 |
+
|
| 109 |
+
app.include_router(router)
|
| 110 |
+
print("β
Diagnostics module registered")
|
| 111 |
+
|
| 112 |
+
# For direct imports
|
| 113 |
+
async def run_diagnostics():
|
| 114 |
+
return await diagnostics_full()
|
| 115 |
+
'''
|
| 116 |
+
|
| 117 |
+
with open('modules/diagnostics.py', 'w') as f:
|
| 118 |
+
f.write(diag_code)
|
| 119 |
+
print("β
Created: modules/diagnostics.py")
|
| 120 |
+
|
| 121 |
+
# 6. Show final structure
|
| 122 |
+
print("\n" + "="*60)
|
| 123 |
+
print("π FINAL STRUCTURE:")
|
| 124 |
+
print("="*60)
|
| 125 |
+
|
| 126 |
+
for root, dirs, files in os.walk('.'):
|
| 127 |
+
# Skip hidden directories
|
| 128 |
+
dirs[:] = [d for d in dirs if not d.startswith('.')]
|
| 129 |
+
|
| 130 |
+
level = root.count(os.sep)
|
| 131 |
+
indent = ' ' * level
|
| 132 |
+
print(f"{indent}{os.path.basename(root)}/")
|
| 133 |
+
|
| 134 |
+
subindent = ' ' * (level + 1)
|
| 135 |
+
for file in files:
|
| 136 |
+
if file.endswith(('.py', '.json', '.txt')):
|
| 137 |
+
print(f"{subindent}{file}")
|
| 138 |
+
|
| 139 |
+
print("="*60)
|
| 140 |
+
print("β
Structure organized successfully!")
|
| 141 |
+
print("π Next steps:")
|
| 142 |
+
print(" 1. Use the FINAL app.py I provided")
|
| 143 |
+
print(" 2. Restart the Space")
|
| 144 |
+
print(" 3. Test endpoints")
|
| 145 |
+
print("="*60)
|