#!/usr/bin/env python3 """Script to upload all updates from the last 3 days to khiemdztv/civic-backup.""" import os import sys from pathlib import Path from huggingface_hub import HfApi, CommitOperationAdd REPO_ID = "khiemdztv/civic-backup" REPO_TYPE = "model" ROOT_DIR = Path(__file__).resolve().parent.parent # 1. Source code, configs, tests, web demo, reports, and documentation files UPDATE_FILES = [ # Documentation, papers, and notes "cic.docx", "cic.md", "cic.2026-09-24.docx", "cic.2026-09-24.md", "dcument.md", "docs/presentation.md", "gg.md", "final.md", "superfinal.md", "superfinal.docx", "superfinal.pdf", # Figures & Diagrams "figures/hinh11_huan_luyen.png", "figures/hinh11_huan_luyen.svg", "figures/hinh17_tien_hoa.png", "figures/hinh17_tien_hoa.svg", "figures/hinh23_quy_trinh_du_lieu.png", "figures/hinh23_quy_trinh_du_lieu.svg", # Configs "configs/action_policy.yaml", "configs/generation.yaml", "configs/weak_rules.yaml", "configs/evidence_gate.yaml", # Source code "src/common/schema.py", "src/common/provinces.py", "src/generation/gemini_reasoner.py", "src/generation/temporal_note.py", "src/inference/pipeline.py", "src/inference/server.py", "src/inference/conversation.py", "src/inference/verifier_shadow.py", "src/inference/static/index.html", "src/preprocessing/pii.py", "src/retrieval/retriever.py", "src/retrieval/router.py", # Data & Splits "data/splits/regression_followup.jsonl", # Spaces & Scripts "hf_space/app.py", "static_space/index.html", "static_space/README.md", "run_backend_demo.sh", "scripts/deploy_to_hf.py", "scripts/build_superfinal_docx.py", "scripts/make_final_figures.py", "scripts/eval_regression.py", "scripts/verifier_shadow_report.py", "scripts/09_local_law.sh", "scripts/10_legal_all.sh", "scripts/fix_all_kb.py", "scripts/fix_index_html.py", "scripts/inject_fast_kb.py", "scripts/tthc_catalog.json", "scripts/vbpl_catalog.json", "scripts/build_full_catalog.py", "scripts/do_upload.py", # Tests & Evaluations "tests/test_gemini_reasoner.py", "tests/test_pii_names.py", "tests/test_conversation.py", "tests/test_verifier_shadow.py", "tests/test_local_law_temporal.py", "tests/test_legal_store_mask.py", # Reports & JSON outputs "reports/regression_results_gemini.json", "reports/regression_results_gemini.md", "reports/regression_results_gemini_shadow.json", "reports/regression_results_gemini_shadow.md", "reports/regression_results.json", "reports/regression_results.md", "reports/regression_followup.json", "reports/regression_followup.md", "reports/acceptance_summary.json", "reports/acceptance_predictions.jsonl", "reports/logs/verifier_shadow.jsonl", "test_resp.json", "test_resp_final.json", "test_resp_new.json", ] # 2. Large model file (if missing or needs proper extension) MODEL_FILES = [ "models/civic_nlu/model_int8.onnx" ] def upload_batch(api: HfApi, file_list, commit_message: str): operations = [] print(f"\n--- Preparing commit: '{commit_message}' ---") for rel_path in file_list: local_path = ROOT_DIR / rel_path if not local_path.exists(): print(f"⚠️ Warning: File not found locally: {local_path}") continue size = local_path.stat().st_size print(f" Adding: {rel_path} ({size:,} bytes)") operations.append( CommitOperationAdd( path_in_repo=rel_path, path_or_fileobj=str(local_path) ) ) if not operations: print("No operations to commit.") return print(f"Submitting commit to {REPO_ID} with {len(operations)} files...") try: commit_info = api.create_commit( repo_id=REPO_ID, repo_type=REPO_TYPE, operations=operations, commit_message=commit_message, ) print(f"✅ Commit successful: {commit_info.commit_url}") except Exception as e: print(f"⚠️ Notice / Error during commit: {e}") def main(): api = HfApi() # Upload source code, docs, figures, configs, tests batch upload_batch( api, UPDATE_FILES, "Backup latest CIVIC AI code, demo, docs, diagrams, and evaluation reports" ) # Upload model file (if modified) upload_batch( api, MODEL_FILES, "Backup civic_nlu model_int8.onnx" ) print("\n🎉 All updates have been successfully uploaded to https://huggingface.co/khiemdztv/civic-backup") if __name__ == "__main__": main()