Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
6affd9cd
Unverified
Commit
6affd9cd
authored
May 31, 2023
by
NielsRogge
Committed by
GitHub
May 31, 2023
Browse files
[PushToHub] Make it possible to upload folders (#23920)
Add first draft
parent
4aa13224
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
0 deletions
+22
-0
src/transformers/utils/hub.py
src/transformers/utils/hub.py
+22
-0
No files found.
src/transformers/utils/hub.py
View file @
6affd9cd
...
@@ -701,9 +701,31 @@ class PushToHubMixin:
...
@@ -701,9 +701,31 @@ class PushToHubMixin:
for
f
in
os
.
listdir
(
working_dir
)
for
f
in
os
.
listdir
(
working_dir
)
if
f
not
in
files_timestamps
or
os
.
path
.
getmtime
(
os
.
path
.
join
(
working_dir
,
f
))
>
files_timestamps
[
f
]
if
f
not
in
files_timestamps
or
os
.
path
.
getmtime
(
os
.
path
.
join
(
working_dir
,
f
))
>
files_timestamps
[
f
]
]
]
# filter for actual files + folders at the root level
modified_files
=
[
f
for
f
in
modified_files
if
os
.
path
.
isfile
(
os
.
path
.
join
(
working_dir
,
f
))
or
os
.
path
.
isdir
(
os
.
path
.
join
(
working_dir
,
f
))
]
operations
=
[]
operations
=
[]
# upload standalone files
for
file
in
modified_files
:
for
file
in
modified_files
:
operations
.
append
(
CommitOperationAdd
(
path_or_fileobj
=
os
.
path
.
join
(
working_dir
,
file
),
path_in_repo
=
file
))
operations
.
append
(
CommitOperationAdd
(
path_or_fileobj
=
os
.
path
.
join
(
working_dir
,
file
),
path_in_repo
=
file
))
if
os
.
path
.
isdir
(
os
.
path
.
join
(
working_dir
,
file
)):
# go over individual files of folder
for
f
in
os
.
listdir
(
os
.
path
.
join
(
working_dir
,
file
)):
operations
.
append
(
CommitOperationAdd
(
path_or_fileobj
=
os
.
path
.
join
(
working_dir
,
file
,
f
),
path_in_repo
=
os
.
path
.
join
(
file
,
f
)
)
)
else
:
operations
.
append
(
CommitOperationAdd
(
path_or_fileobj
=
os
.
path
.
join
(
working_dir
,
file
),
path_in_repo
=
file
)
)
logger
.
info
(
f
"Uploading the following files to
{
repo_id
}
:
{
','
.
join
(
modified_files
)
}
"
)
logger
.
info
(
f
"Uploading the following files to
{
repo_id
}
:
{
','
.
join
(
modified_files
)
}
"
)
return
create_commit
(
return
create_commit
(
repo_id
=
repo_id
,
operations
=
operations
,
commit_message
=
commit_message
,
token
=
token
,
create_pr
=
create_pr
repo_id
=
repo_id
,
operations
=
operations
,
commit_message
=
commit_message
,
token
=
token
,
create_pr
=
create_pr
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment