Upload folder using huggingface_hub
Browse files- src/repo_manager.ipynb +142 -0
src/repo_manager.ipynb
CHANGED
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"from huggingface_hub import create_repo, HfApi\n",
|
10 |
+
"\n",
|
11 |
+
"import com_const as cc"
|
12 |
+
]
|
13 |
+
},
|
14 |
+
{
|
15 |
+
"cell_type": "code",
|
16 |
+
"execution_count": 2,
|
17 |
+
"metadata": {},
|
18 |
+
"outputs": [],
|
19 |
+
"source": [
|
20 |
+
"repo_id = \"treizh/oiv_ld_phenotyping\""
|
21 |
+
]
|
22 |
+
},
|
23 |
+
{
|
24 |
+
"cell_type": "code",
|
25 |
+
"execution_count": 3,
|
26 |
+
"metadata": {},
|
27 |
+
"outputs": [
|
28 |
+
{
|
29 |
+
"data": {
|
30 |
+
"text/plain": [
|
31 |
+
"RepoUrl('https://huggingface.co/treizh/oiv_ld_phenotyping', endpoint='https://huggingface.co', repo_type='model', repo_id='treizh/oiv_ld_phenotyping')"
|
32 |
+
]
|
33 |
+
},
|
34 |
+
"execution_count": 3,
|
35 |
+
"metadata": {},
|
36 |
+
"output_type": "execute_result"
|
37 |
+
}
|
38 |
+
],
|
39 |
+
"source": [
|
40 |
+
"create_repo(repo_id, exist_ok=True)"
|
41 |
+
]
|
42 |
+
},
|
43 |
+
{
|
44 |
+
"cell_type": "code",
|
45 |
+
"execution_count": 4,
|
46 |
+
"metadata": {},
|
47 |
+
"outputs": [],
|
48 |
+
"source": [
|
49 |
+
"api = HfApi()"
|
50 |
+
]
|
51 |
+
},
|
52 |
+
{
|
53 |
+
"cell_type": "code",
|
54 |
+
"execution_count": 5,
|
55 |
+
"metadata": {},
|
56 |
+
"outputs": [
|
57 |
+
{
|
58 |
+
"data": {
|
59 |
+
"text/plain": [
|
60 |
+
"CommitInfo(commit_url='https://huggingface.co/treizh/oiv_ld_phenotyping/commit/ac0c4c71a2b6842d45cd5fa99ca15429f647027c', commit_message='Upload .gitignore with huggingface_hub', commit_description='', oid='ac0c4c71a2b6842d45cd5fa99ca15429f647027c', pr_url=None, pr_revision=None, pr_num=None)"
|
61 |
+
]
|
62 |
+
},
|
63 |
+
"execution_count": 5,
|
64 |
+
"metadata": {},
|
65 |
+
"output_type": "execute_result"
|
66 |
+
}
|
67 |
+
],
|
68 |
+
"source": [
|
69 |
+
"api.upload_file(path_or_fileobj=cc.path_to_root.joinpath(\".gitignore\"), path_in_repo=\".gitignore\", repo_id=repo_id)"
|
70 |
+
]
|
71 |
+
},
|
72 |
+
{
|
73 |
+
"cell_type": "code",
|
74 |
+
"execution_count": null,
|
75 |
+
"metadata": {},
|
76 |
+
"outputs": [],
|
77 |
+
"source": [
|
78 |
+
"def upload_folder(fld):\n",
|
79 |
+
" api.upload_folder(folder_path=fld, repo_id=repo_id, path_in_repo=fld.name)"
|
80 |
+
]
|
81 |
+
},
|
82 |
+
{
|
83 |
+
"cell_type": "code",
|
84 |
+
"execution_count": 6,
|
85 |
+
"metadata": {},
|
86 |
+
"outputs": [
|
87 |
+
{
|
88 |
+
"data": {
|
89 |
+
"text/plain": [
|
90 |
+
"CommitInfo(commit_url='https://huggingface.co/treizh/oiv_ld_phenotyping/commit/fc262e75f2db77ba4440372fe5e564be596968bb', commit_message='Upload folder using huggingface_hub', commit_description='', oid='fc262e75f2db77ba4440372fe5e564be596968bb', pr_url=None, pr_revision=None, pr_num=None)"
|
91 |
+
]
|
92 |
+
},
|
93 |
+
"execution_count": 6,
|
94 |
+
"metadata": {},
|
95 |
+
"output_type": "execute_result"
|
96 |
+
}
|
97 |
+
],
|
98 |
+
"source": [
|
99 |
+
"api.upload_folder(folder_path=cc.path_to_src, repo_id=repo_id, path_in_repo=cc.path_to_src.name)"
|
100 |
+
]
|
101 |
+
},
|
102 |
+
{
|
103 |
+
"cell_type": "code",
|
104 |
+
"execution_count": null,
|
105 |
+
"metadata": {},
|
106 |
+
"outputs": [],
|
107 |
+
"source": [
|
108 |
+
"# for file in cc.path_to_src.rglob(\"*\"):\n",
|
109 |
+
"# if api.file_exists(repo_id=repo_name, filename=file.name) is True:\n",
|
110 |
+
"# api.delete_file(path_in_repo=file.name, repo_id=repo_name)"
|
111 |
+
]
|
112 |
+
},
|
113 |
+
{
|
114 |
+
"cell_type": "code",
|
115 |
+
"execution_count": null,
|
116 |
+
"metadata": {},
|
117 |
+
"outputs": [],
|
118 |
+
"source": []
|
119 |
+
}
|
120 |
+
],
|
121 |
+
"metadata": {
|
122 |
+
"kernelspec": {
|
123 |
+
"display_name": "env",
|
124 |
+
"language": "python",
|
125 |
+
"name": "python3"
|
126 |
+
},
|
127 |
+
"language_info": {
|
128 |
+
"codemirror_mode": {
|
129 |
+
"name": "ipython",
|
130 |
+
"version": 3
|
131 |
+
},
|
132 |
+
"file_extension": ".py",
|
133 |
+
"mimetype": "text/x-python",
|
134 |
+
"name": "python",
|
135 |
+
"nbconvert_exporter": "python",
|
136 |
+
"pygments_lexer": "ipython3",
|
137 |
+
"version": "3.9.2"
|
138 |
+
}
|
139 |
+
},
|
140 |
+
"nbformat": 4,
|
141 |
+
"nbformat_minor": 2
|
142 |
+
}
|