Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from huggingface_hub import create_repo, upload_file,
|
| 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 |
-
|
| 11 |
-
|
|
|
|
| 12 |
# Create the destination repo
|
| 13 |
if repo_type in ["space", "dataset"]:
|
| 14 |
url = create_repo(
|
| 15 |
-
repo_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=
|
| 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 |
-
|
| 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 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 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()
|