jcplus commited on
Commit
a770b25
·
verified ·
1 Parent(s): 80aa5c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -41
app.py CHANGED
@@ -1,29 +1,28 @@
1
  import gradio as gr
2
- from huggingface_hub import create_repo, upload_file, Repository, whoami
3
  import os
4
  import shutil
5
 
6
  def duplicate(source_repo, dst_repo, token, repo_type):
7
  # Get username from token
8
  username = whoami(token=token)["name"]
9
- repo_namespace, dst_id = dst_repo.split("/")
10
- org = repo_namespace if repo_namespace != username else None
11
-
 
12
  # Create the destination repo
13
  if repo_type in ["space", "dataset"]:
14
  url = create_repo(
15
- repo_id=dst_id,
16
  token=token,
17
- organization=org,
18
  repo_type=repo_type,
19
  space_sdk="gradio" if repo_type == "space" else None,
20
  private=False
21
  )
22
  else:
23
  url = create_repo(
24
- repo_id=dst_id,
25
  token=token,
26
- organization=org,
27
  private=False
28
  )
29
 
@@ -39,7 +38,7 @@ def duplicate(source_repo, dst_repo, token, repo_type):
39
  local_dir=local_dir,
40
  clone_from=full_path,
41
  repo_type=repo_type if repo_type in ["space", "dataset"] else None,
42
- use_auth_token=token
43
  )
44
 
45
  # Upload files
@@ -63,37 +62,48 @@ def duplicate(source_repo, dst_repo, token, repo_type):
63
 
64
  return f"Find your repo <a href='{url}' target='_blank' style='text-decoration:underline'>here</a>"
65
 
66
- # Updated Gradio interface
67
- interface = gr.Interface(
68
- fn=duplicate,
69
- inputs=[
70
- gr.Textbox(
71
- label="Source repository",
72
- placeholder="e.g. osanseviero/src"
73
- ),
74
- gr.Textbox(
75
- label="Destination repository",
76
- placeholder="e.g. osanseviero/dst"
77
- ),
78
- gr.Textbox(
79
- label="Write access token",
80
- type="password",
81
- placeholder="Your HF token"
82
- ),
83
- gr.Dropdown(
84
- choices=["model", "dataset", "space"],
85
- label="Repository type",
86
- value="model"
87
- )
88
- ],
89
- outputs=gr.HTML(),
90
- title="Duplicate your repo!",
91
- description="Duplicate a Hugging Face repository! You need to specify a write token obtained from https://hf.co/settings/tokens. This Space is an experimental demo.",
92
- article="""
93
- <p>Find your write token at
94
- <a href='https://huggingface.co/settings/tokens' target='_blank'>token settings</a></p>
95
- """,
96
- allow_flagging="never"
97
- )
 
 
 
 
 
 
 
 
 
 
 
98
 
99
  interface.launch()
 
1
  import gradio as gr
2
+ from huggingface_hub import create_repo, upload_file, whoami, Repository
3
  import os
4
  import shutil
5
 
6
  def duplicate(source_repo, dst_repo, token, repo_type):
7
  # Get username from token
8
  username = whoami(token=token)["name"]
9
+
10
+ # For organization repos, the full repo_id should include org name (e.g., "orgname/reponame")
11
+ # No separate organization parameter needed anymore
12
+
13
  # Create the destination repo
14
  if repo_type in ["space", "dataset"]:
15
  url = create_repo(
16
+ repo_id=dst_repo,
17
  token=token,
 
18
  repo_type=repo_type,
19
  space_sdk="gradio" if repo_type == "space" else None,
20
  private=False
21
  )
22
  else:
23
  url = create_repo(
24
+ repo_id=dst_repo,
25
  token=token,
 
26
  private=False
27
  )
28
 
 
38
  local_dir=local_dir,
39
  clone_from=full_path,
40
  repo_type=repo_type if repo_type in ["space", "dataset"] else None,
41
+ token=token # Updated from use_auth_token to token
42
  )
43
 
44
  # Upload files
 
62
 
63
  return f"Find your repo <a href='{url}' target='_blank' style='text-decoration:underline'>here</a>"
64
 
65
+ # Updated Gradio interface for version 4.x
66
+ with gr.Blocks(title="Duplicate your repo!") as interface:
67
+ gr.Markdown("""
68
+ # Duplicate your repo!
69
+ Duplicate a Hugging Face repository! You need to specify a write token obtained from https://hf.co/settings/tokens.
70
+ This Space is an experimental demo.
71
+ """)
72
+
73
+ with gr.Row():
74
+ with gr.Column():
75
+ source_input = gr.Textbox(
76
+ label="Source repository",
77
+ placeholder="e.g. osanseviero/src"
78
+ )
79
+ dest_input = gr.Textbox(
80
+ label="Destination repository",
81
+ placeholder="e.g. osanseviero/dst"
82
+ )
83
+ token_input = gr.Textbox(
84
+ label="Write access token",
85
+ type="password",
86
+ placeholder="Your HF token"
87
+ )
88
+ repo_type_input = gr.Dropdown(
89
+ choices=["model", "dataset", "space"],
90
+ label="Repository type",
91
+ value="model"
92
+ )
93
+ submit_btn = gr.Button("Duplicate")
94
+
95
+ with gr.Column():
96
+ output = gr.HTML(label="Result")
97
+
98
+ gr.Markdown("""
99
+ Find your write token at
100
+ [token settings](https://huggingface.co/settings/tokens)
101
+ """)
102
+
103
+ submit_btn.click(
104
+ fn=duplicate,
105
+ inputs=[source_input, dest_input, token_input, repo_type_input],
106
+ outputs=output
107
+ )
108
 
109
  interface.launch()