davanstrien HF staff commited on
Commit
2e284e5
1 Parent(s): 7b9d2a1

Refactor push_to_hf function and update UI

Browse files
Files changed (1) hide show
  1. app.py +36 -30
app.py CHANGED
@@ -53,7 +53,10 @@ def upload_directory_to_hf(
53
 
54
 
55
  def push_to_hf(
56
- source_github_repository, destination_hf_hub_repository, hf_token, subdirectory=None
 
 
 
57
  ):
58
  gr.Info("Cloning source GitHub repository...")
59
  repo, temporary_directory = clone_into_temp_dir(source_github_repository)
@@ -66,7 +69,7 @@ def push_to_hf(
66
  upload_directory_to_hf(
67
  repo_id=destination_hf_hub_repository,
68
  directory=src_directory,
69
- token=hf_token,
70
  private=False,
71
  )
72
  gr.Info("Syncing with Hugging Face Hub...Done")
@@ -152,42 +155,46 @@ with gr.Blocks(theme=gr.themes.Base()) as demo:
152
  """<center> GitHub is a great place for sharing code but the Hugging Face Hub has many advantages for sharing datasets.
153
  <br> This Space will guide you through the process of migrating a dataset from GitHub to the Hugging Face Hub. </center>"""
154
  )
 
 
 
155
  gr.Markdown("### Location of existing dataset")
156
  gr.Markdown("URL for the GitHub repository where the dataset is currently hosted")
157
  source_github_repository = gr.Textbox(lines=1, label="Source GitHub Repository URL")
158
- gr.Markdown("### Select files and folder to migrate")
159
- gr.Markdown(
160
- "(Optional): select a specific folder and/or files to migrate from the GitHub repository. If you select a folder all the files in that folder will be migrated."
161
- )
162
- folder_in_github_repo = gr.Dropdown(
163
- None,
164
- label="Folder in the GitHub Repository to migrate",
165
- allow_custom_value=True,
166
- visible=True,
167
- )
168
- files_in_github_repo = gr.Dropdown(
169
- None,
170
- label="Files in GitHub Repository to migrate",
171
- allow_custom_value=True,
172
- visible=True,
173
- )
174
- source_github_repository.change(
175
- show_files_and_directories,
176
- [source_github_repository],
177
- [folder_in_github_repo, files_in_github_repo],
178
- )
 
179
  gr.Markdown("### Destination for your migrated dataset")
180
  gr.Markdown("Destination repository for your dataset on the Hugging Face Hub")
181
  destination_hf_hub_repository = gr.Textbox(
182
  label="Destination Hugging Face Repository",
183
  placeholder="i.e. <hugging face username>/<repository_name>",
184
  )
185
- gr.Markdown("## Authentication")
186
- gr.Markdown(
187
- """You need to provide a token with write access to the namespace you want to upload to.
188
- You can generate/access your Hugging FAce token from [here](https://huggingface.co/settings/token)."""
189
- )
190
- hf_token = gr.Textbox(label="Hugging Face Token", type="password")
191
  summit_btn = gr.Button("Migrate Dataset")
192
  result = gr.Markdown(label="Summary", visible=True)
193
  summit_btn.click(
@@ -195,7 +202,6 @@ with gr.Blocks(theme=gr.themes.Base()) as demo:
195
  [
196
  source_github_repository,
197
  destination_hf_hub_repository,
198
- hf_token,
199
  folder_in_github_repo,
200
  ],
201
  [result],
 
53
 
54
 
55
  def push_to_hf(
56
+ source_github_repository,
57
+ destination_hf_hub_repository,
58
+ hf_token: gr.OAuthToken,
59
+ subdirectory=None,
60
  ):
61
  gr.Info("Cloning source GitHub repository...")
62
  repo, temporary_directory = clone_into_temp_dir(source_github_repository)
 
69
  upload_directory_to_hf(
70
  repo_id=destination_hf_hub_repository,
71
  directory=src_directory,
72
+ token=hf_token.token,
73
  private=False,
74
  )
75
  gr.Info("Syncing with Hugging Face Hub...Done")
 
155
  """<center> GitHub is a great place for sharing code but the Hugging Face Hub has many advantages for sharing datasets.
156
  <br> This Space will guide you through the process of migrating a dataset from GitHub to the Hugging Face Hub. </center>"""
157
  )
158
+ with gr.Row():
159
+ gr.LoginButton(size="sm")
160
+ gr.LogoutButton(size="sm")
161
  gr.Markdown("### Location of existing dataset")
162
  gr.Markdown("URL for the GitHub repository where the dataset is currently hosted")
163
  source_github_repository = gr.Textbox(lines=1, label="Source GitHub Repository URL")
164
+ with gr.Accordion("Advanced Options", open=False):
165
+ gr.Markdown("### Select files and folder to migrate")
166
+ gr.Markdown(
167
+ "(Optional): select a specific folder and/or files to migrate from the GitHub repository. If you select a folder all the files in that folder will be migrated."
168
+ )
169
+ folder_in_github_repo = gr.Dropdown(
170
+ None,
171
+ label="Folder in the GitHub Repository to migrate",
172
+ allow_custom_value=True,
173
+ visible=True,
174
+ )
175
+ files_in_github_repo = gr.Dropdown(
176
+ None,
177
+ label="Files in GitHub Repository to migrate",
178
+ allow_custom_value=True,
179
+ visible=True,
180
+ )
181
+ source_github_repository.change(
182
+ show_files_and_directories,
183
+ [source_github_repository],
184
+ [folder_in_github_repo, files_in_github_repo],
185
+ )
186
  gr.Markdown("### Destination for your migrated dataset")
187
  gr.Markdown("Destination repository for your dataset on the Hugging Face Hub")
188
  destination_hf_hub_repository = gr.Textbox(
189
  label="Destination Hugging Face Repository",
190
  placeholder="i.e. <hugging face username>/<repository_name>",
191
  )
192
+ # gr.Markdown("## Authentication")
193
+ # gr.Markdown(
194
+ # """You need to provide a token with write access to the namespace you want to upload to.
195
+ # You can generate/access your Hugging FAce token from [here](https://huggingface.co/settings/token)."""
196
+ # )
197
+ # hf_token = gr.Textbox(label="Hugging Face Token", type="password")
198
  summit_btn = gr.Button("Migrate Dataset")
199
  result = gr.Markdown(label="Summary", visible=True)
200
  summit_btn.click(
 
202
  [
203
  source_github_repository,
204
  destination_hf_hub_repository,
 
205
  folder_in_github_repo,
206
  ],
207
  [result],