Spaces:
Running
Running
File size: 1,494 Bytes
06c5a6b 7dd9384 06c5a6b 7dd9384 06c5a6b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | import os
import asyncio
from pathlib import Path
from openspace.dashboard_server import create_app
from openspace.skill_engine.registry import SkillRegistry
from openspace.skill_engine.store import SkillStore
def sync_local_skills():
try:
print("Starting local skill sync...")
registry = SkillRegistry()
skill_dir = Path(__file__).resolve().parent / "skills"
if skill_dir.exists() and skill_dir.is_dir():
added = registry.discover_from_dirs([skill_dir])
if added:
store = SkillStore()
# Run the async sync method in a synchronous context
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
count = loop.run_until_complete(store.sync_from_registry(added))
loop.close()
print(f"Successfully synced {count} skills from {skill_dir} into database.")
else:
print("No skills discovered in directory.")
else:
print(f"Skill directory not found at {skill_dir}")
except Exception as e:
print(f"Error syncing local skills: {e}")
# Run sync before creating the app
sync_local_skills()
app = create_app()
if __name__ == "__main__":
port = int(os.environ.get("PORT", 7860))
# Enable CORS for the frontend hosted on EdgeOne Pages
from flask_cors import CORS
CORS(app, resources={r"/api/*": {"origins": "*"}})
app.run(host="0.0.0.0", port=port)
|