Spaces:
Sleeping
Sleeping
Download src/gaia/utils/cli/organize_files.py from jm-vis/Final_Assignment_GAIAAgent: direct link, hf CLI and curl.
- Browser
- Download file 6.35 kB
-
https://huggingface.co/spaces/jm-vis/Final_Assignment_GAIAAgent/resolve/main/src/gaia/utils/cli/organize_files.py
- Command line
-
hf download hf://spaces/jm-vis/Final_Assignment_GAIAAgent/src/gaia/utils/cli/organize_files.py
-
curl -L -o organize_files.py https://huggingface.co/spaces/jm-vis/Final_Assignment_GAIAAgent/resolve/main/src/gaia/utils/cli/organize_files.py
6.35 kB
| #!/usr/bin/env python | |
| """ | |
| GAIA Project File Organizer | |
| This script organizes files in the GAIA project by moving them to appropriate directories: | |
| 1. Moves deployment-related files to the deployment directory | |
| 2. Moves example notebooks to the examples directory | |
| 3. Moves utility scripts to the utils directory | |
| Usage: | |
| python src/gaia/utils/cli/organize_files.py [--dry-run] | |
| """ | |
| import os | |
| import sys | |
| import shutil | |
| import logging | |
| import argparse | |
| from pathlib import Path | |
| from typing import Dict, List, Tuple | |
| # Configure logging | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format="%(asctime)s - %(levelname)s - %(message)s", | |
| handlers=[ | |
| logging.StreamHandler() | |
| ] | |
| ) | |
| logger = logging.getLogger("organize_files") | |
| # Files to move to deployment directory | |
| DEPLOYMENT_FILES = [ | |
| "prepare_for_hf_deployment.py", | |
| "hf_deployment_instructions.md", | |
| "huggingface_space_deployment_guide.md", | |
| "huggingface_space_update_guide.md", | |
| "huggingface_space_update_guide.md", | |
| "huggingface_space_cleanup.md", | |
| "huggingface_space_deployment_summary.md", | |
| "space_config.json", | |
| "deploy_to_hf.py", | |
| "deploy_to_huggingface_credential.py", | |
| "deploy_to_huggingface_dotenv.py", | |
| "deploy_to_huggingface_env.py", | |
| "deploy_to_huggingface.py", | |
| "deploy_with_token.py", | |
| "deployment_checklist.md", | |
| "deployment_readiness_report.json", | |
| "deployment_readiness_report.md", | |
| "deployment_verification.py", | |
| "final_deployment_guide.md", | |
| "complete_deployment_guide.md", | |
| "complete_deployment_solution.md", | |
| "get_huggingface_token.py", | |
| "test_deployment_readiness.py", | |
| "verify_deployment_readiness.py", | |
| "production_cleanup.py", | |
| "production_readiness_check.py", | |
| "production_test.py", | |
| "production_verification_report.md", | |
| ] | |
| # Example notebooks to move to examples directory | |
| EXAMPLE_FILES = [ | |
| "mail_sorting.ipynb", | |
| "agent.ipynb" | |
| ] | |
| # Utility scripts to move to utils directory | |
| UTIL_FILES = [ | |
| "generate_env_template.py", | |
| "fix_encoding.py", | |
| "fix_graph_imports.py", | |
| "remove_debug_statements.py", | |
| "remove_duplicate_tests.py", | |
| "run_verification_tests.py", | |
| "simple_memory_test.py", | |
| "simple_test.py", | |
| "validate_app_simple.py", | |
| "validate_app.py", | |
| "update_agent.py", | |
| "verify_components.py", | |
| "verify_minimal.py", | |
| "create_env_and_test.py" | |
| ] | |
| def move_file(src: str, dest_dir: str, dry_run: bool = False) -> bool: | |
| """ | |
| Move a file to the specified directory | |
| Args: | |
| src: Source file path | |
| dest_dir: Destination directory | |
| dry_run: If True, only show what would be moved without making changes | |
| Returns: | |
| bool: True if successful or would be successful, False otherwise | |
| """ | |
| if not os.path.exists(src): | |
| logger.warning(f"Source file does not exist: {src}") | |
| return False | |
| if not os.path.exists(dest_dir): | |
| if dry_run: | |
| logger.info(f"DRY RUN: Would create directory: {dest_dir}") | |
| else: | |
| os.makedirs(dest_dir, exist_ok=True) | |
| logger.info(f"Created directory: {dest_dir}") | |
| dest_path = os.path.join(dest_dir, os.path.basename(src)) | |
| if dry_run: | |
| logger.info(f"DRY RUN: Would move {src} -> {dest_path}") | |
| return True | |
| try: | |
| shutil.move(src, dest_path) | |
| logger.info(f"Moved {src} -> {dest_path}") | |
| return True | |
| except Exception as e: | |
| logger.error(f"Error moving {src} to {dest_path}: {str(e)}") | |
| return False | |
| def main(): | |
| """Main function to organize files.""" | |
| parser = argparse.ArgumentParser(description="GAIA Project File Organizer") | |
| parser.add_argument("--dry-run", action="store_true", help="Show what would be moved without making changes") | |
| args = parser.parse_args() | |
| if args.dry_run: | |
| logger.info("Running in DRY RUN mode - no files will be moved") | |
| # Track results | |
| results = { | |
| "deployment": {"success": 0, "failed": 0, "missing": 0}, | |
| "examples": {"success": 0, "failed": 0, "missing": 0}, | |
| "utils": {"success": 0, "failed": 0, "missing": 0} | |
| } | |
| # Move deployment files | |
| logger.info("\n=== Moving deployment files ===") | |
| for file in DEPLOYMENT_FILES: | |
| if os.path.exists(file): | |
| success = move_file(file, "deployment", args.dry_run) | |
| if success: | |
| results["deployment"]["success"] += 1 | |
| else: | |
| results["deployment"]["failed"] += 1 | |
| else: | |
| logger.info(f"File not found (skipping): {file}") | |
| results["deployment"]["missing"] += 1 | |
| # Move example files | |
| logger.info("\n=== Moving example files ===") | |
| for file in EXAMPLE_FILES: | |
| if os.path.exists(file): | |
| success = move_file(file, "examples", args.dry_run) | |
| if success: | |
| results["examples"]["success"] += 1 | |
| else: | |
| results["examples"]["failed"] += 1 | |
| else: | |
| logger.info(f"File not found (skipping): {file}") | |
| results["examples"]["missing"] += 1 | |
| # Move utility files | |
| logger.info("\n=== Moving utility files ===") | |
| for file in UTIL_FILES: | |
| if os.path.exists(file): | |
| success = move_file(file, "utils", args.dry_run) | |
| if success: | |
| results["utils"]["success"] += 1 | |
| else: | |
| results["utils"]["failed"] += 1 | |
| else: | |
| logger.info(f"File not found (skipping): {file}") | |
| results["utils"]["missing"] += 1 | |
| # Print summary | |
| logger.info("\n=== File Organization Summary ===") | |
| logger.info(f"Deployment Files: {results['deployment']['success']} moved, {results['deployment']['failed']} failed, {results['deployment']['missing']} not found") | |
| logger.info(f"Example Files: {results['examples']['success']} moved, {results['examples']['failed']} failed, {results['examples']['missing']} not found") | |
| logger.info(f"Utility Files: {results['utils']['success']} moved, {results['utils']['failed']} failed, {results['utils']['missing']} not found") | |
| # Return success code if no failures | |
| total_failures = sum(result["failed"] for result in results.values()) | |
| return 0 if total_failures == 0 else 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) |