Spaces:
Running
Running
| #!/usr/bin/env python3 | |
| """ | |
| OpenClaw sync script for HuggingClaw-Cain | |
| Initializes the OpenClaw agent with proper configuration. | |
| """ | |
| import os | |
| import sys | |
| import json | |
| import logging | |
| from datetime import datetime | |
| # Configure logging | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' | |
| ) | |
| logger = logging.getLogger(__name__) | |
| def load_config(): | |
| """Load OpenClaw configuration""" | |
| config_path = os.path.join(os.path.dirname(__file__), "..", "dataset", ".openclaw", "openclaw.json") | |
| try: | |
| with open(config_path, 'r') as f: | |
| config = json.load(f) | |
| return config | |
| except Exception as e: | |
| logger.error(f"Failed to load config: {str(e)}") | |
| return None | |
| def main(): | |
| """Main sync function""" | |
| try: | |
| logger.info("Starting Cain sync process...") | |
| # Load configuration | |
| config = load_config() | |
| if not config: | |
| logger.error("Failed to load configuration") | |
| return 1 | |
| # Get configuration from environment | |
| model = os.getenv("MODEL", "openrouter/openai/gpt-oss-20b") | |
| port = os.getenv("PORT", "7860") | |
| # Update config with environment values | |
| config["model"] = model | |
| config["port"] = int(port) | |
| logger.info(f"Cain sync configured with model: {model}") | |
| logger.info(f"Running on port: {port}") | |
| # Initialize OpenClaw service | |
| from openclaw import OpenClaw | |
| # Create OpenClaw instance | |
| claw = OpenClaw(**config) | |
| # Start the service | |
| logger.info("Starting OpenClaw service...") | |
| claw.start() | |
| # Create a completion marker | |
| with open("/tmp/sync_complete", "w") as f: | |
| f.write(f"Sync completed at {datetime.now().isoformat()}") | |
| return 0 | |
| except ImportError as e: | |
| logger.error(f"OpenClaw module not found: {str(e)}") | |
| logger.info("Please ensure OpenClaw is installed: pip install openclaw") | |
| return 1 | |
| except Exception as e: | |
| logger.error(f"Error during sync: {str(e)}") | |
| return 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) |