Spaces:
Running
Running
| 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) | |