submission / scripts /prepare_hf_space.sh
hyeongjun User
SAFE challenge ManipDet submission
8792786
#!/usr/bin/env bash
# Prepare a directory that can be pushed to a Hugging Face Space (Docker SDK).
# Run from repo root (parent of submission/ and ManipDet/).
# Usage: bash submission/scripts/prepare_hf_space.sh [OUTPUT_DIR]
# Default OUTPUT_DIR: submission/hf_space_export
set -e
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
SUBMISSION_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
OUTPUT_DIR="${1:-${SUBMISSION_DIR}/hf_space_export}"
if [[ ! -d "$REPO_ROOT/ManipDet" ]]; then
echo "Error: ManipDet/ not found at $REPO_ROOT/ManipDet. Run from repo root (code/)." >&2
exit 1
fi
echo "Preparing HF Space export at: $OUTPUT_DIR"
rm -rf "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"
# Copy submission contents (skip output dir to avoid self-copy)
OUTPUT_BASENAME="$(basename "$OUTPUT_DIR")"
for f in "$SUBMISSION_DIR"/*; do
[ -e "$f" ] && [ "$(basename "$f")" != "$OUTPUT_BASENAME" ] && cp -R "$f" "$OUTPUT_DIR/"
done
for f in .env.example .gitignore .dockerignore .python-version .gitattributes; do
[ -f "$SUBMISSION_DIR/$f" ] && cp "$SUBMISSION_DIR/$f" "$OUTPUT_DIR/"
done
for x in .git venv models dyff-outputs test_datasets test_results hf_space_export; do
rm -rf "$OUTPUT_DIR/$x"
done
find "$OUTPUT_DIR" -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
# Copy ManipDet code (exclude runs, inference_output, .git)
mkdir -p "$OUTPUT_DIR/ManipDet"
for f in "$REPO_ROOT/ManipDet"/*; do [ -e "$f" ] && cp -R "$f" "$OUTPUT_DIR/ManipDet/"; done
for f in .gitignore; do [ -f "$REPO_ROOT/ManipDet/$f" ] && cp "$REPO_ROOT/ManipDet/$f" "$OUTPUT_DIR/ManipDet/"; done
rm -rf "$OUTPUT_DIR/ManipDet/.git" "$OUTPUT_DIR/ManipDet/runs" "$OUTPUT_DIR/ManipDet/inference_output"
find "$OUTPUT_DIR/ManipDet" -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
# Space .dockerignore: do not exclude Dockerfile or README
cat > "$OUTPUT_DIR/.dockerignore" << 'DOCKERIGNORE'
.git
.gitignore
venv
.venv
__pycache__
*.pyc
*.pyo
.pytest_cache
.coverage
htmlcov
*.log
.DS_Store
hf_space_export
test_results
dyff-outputs
DOCKERIGNORE
echo "Done. Next steps:"
echo " 1. cd $OUTPUT_DIR"
echo " 2. git init && git add . && git commit -m 'SAFE challenge ManipDet submission'"
echo " 3. Create a new Space at https://huggingface.co/new-space (SDK: Docker, in your Organization)"
echo " 4. git remote add origin https://huggingface.co/spaces/YOUR_ORG/YOUR_SPACE_NAME"
echo " 5. git push -u origin main"
echo " 6. In Space Settings > Variables (or Secrets): set MANIPDET_CHECKPOINT_REPO if using HF Model repo for checkpoint"
echo " 7. Add member safe-challenge-2025-submissions (read) to your Organization"
echo " 8. Submit at https://challenge.dyff.io/submit with your Space URL"