{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "import time\n", "\n", "from huggingface_hub import create_repo, HfApi\n", "\n", "import com_const as cc" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "repo_id = \"treizh/oiv_ld_phenotyping\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "create_repo(repo_id, exist_ok=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "api = HfApi()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def upload_file(file_path: Path, dst_path=None):\n", " api.upload_file(\n", " path_or_fileobj=file_path,\n", " path_in_repo=(\n", " dst_path\n", " if dst_path is not None\n", " else str(file_path.relative_to(cc.path_to_root))\n", " ),\n", " repo_id=repo_id,\n", " )" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def upload_folder(fld, multi_commits=True, multi_commits_verbose=True):\n", " api.upload_folder(\n", " folder_path=fld,\n", " repo_id=repo_id,\n", " path_in_repo=str(fld.relative_to(cc.path_to_root)),\n", " multi_commits=multi_commits,\n", " multi_commits_verbose=multi_commits_verbose,\n", " )" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def upload_big_folder(\n", " fld, multi_commits=True, multi_commits_verbose=True, max_attempts: int = -1\n", "):\n", " i = 1\n", " while i < max_attempts or max_attempts < 0:\n", " try:\n", " upload_folder(\n", " fld=fld,\n", " multi_commits=multi_commits,\n", " multi_commits_verbose=multi_commits_verbose,\n", " )\n", " except:\n", " print(f\"Trying once more: {i}\")\n", " i += 1\n", " time.sleep(100)\n", " else:\n", " break" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# for file in [\".gitignore\", \"LICENSE\", \"README.md\", \"requirements.txt\"]:\n", "# upload_file(Path(\"..\").joinpath(file), dst_path=file)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# upload_folder(cc.path_to_src)\n", "# upload_folder(cc.path_to_data)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# upload_file(file_path=cc.path_to_chk_detector.joinpath(\"leaf_disc_detector.ckpt\"))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# upload_file(file_path=cc.path_to_chk_oiv.joinpath(\"oiv_scorer.ckpt\"))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# upload_big_folder(fld=cc.path_to_leaf_patches, multi_commits_verbose=False)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# upload_big_folder(fld=cc.path_to_plates, multi_commits_verbose=False)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "env", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.2" } }, "nbformat": 4, "nbformat_minor": 2 }