Spaces:
Runtime error
Runtime error
Commit
•
d08ca35
1
Parent(s):
96403e9
Refactor clone_collection function arguments
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ def extract_slug(url):
|
|
9 |
|
10 |
|
11 |
def clone_collection(
|
12 |
-
source_slug,
|
13 |
):
|
14 |
api = HfApi(token=token)
|
15 |
source_slug = source_slug.strip()
|
@@ -21,8 +21,9 @@ def clone_collection(
|
|
21 |
raise gr.Error(
|
22 |
f"Collection {source_slug} does not exist or you do not have access to it."
|
23 |
)
|
24 |
-
description = f"
|
25 |
-
|
|
|
26 |
new_collection = api.create_collection(
|
27 |
dest_title,
|
28 |
namespace=dest_namespace,
|
@@ -35,7 +36,7 @@ def clone_collection(
|
|
35 |
api.add_collection_item(
|
36 |
new_collection.slug, item.item_id, item_type=item.item_type
|
37 |
)
|
38 |
-
return f"[Collection]({collection.url}) has been cloned into [new_collection.slug]({new_collection.url})"
|
39 |
|
40 |
|
41 |
title = (
|
@@ -66,13 +67,15 @@ You can then edit the collection to your liking!</p>"""
|
|
66 |
placeholder="e.g. username/collection-slug",
|
67 |
)
|
68 |
gr.Markdown("## Destination Collection info")
|
69 |
-
|
70 |
-
label="Destination Namespace",
|
71 |
-
interactive=True,
|
72 |
-
)
|
73 |
dest_title = gr.Textbox(
|
74 |
label="Destination Title",
|
75 |
)
|
|
|
|
|
|
|
|
|
|
|
76 |
with gr.Row():
|
77 |
private = gr.Checkbox(
|
78 |
False,
|
@@ -88,9 +91,9 @@ You can then edit the collection to your liking!</p>"""
|
|
88 |
clone_collection,
|
89 |
[
|
90 |
source_slug,
|
91 |
-
dest_namespace,
|
92 |
dest_title,
|
93 |
token,
|
|
|
94 |
private,
|
95 |
overwrite,
|
96 |
],
|
|
|
9 |
|
10 |
|
11 |
def clone_collection(
|
12 |
+
source_slug, dest_title, token, dest_namespace=None, private=False, exist_ok=False
|
13 |
):
|
14 |
api = HfApi(token=token)
|
15 |
source_slug = source_slug.strip()
|
|
|
21 |
raise gr.Error(
|
22 |
f"Collection {source_slug} does not exist or you do not have access to it."
|
23 |
)
|
24 |
+
description = f"Copied from {collection.title} using https://huggingface.co/spaces/librarian-bots/collection_cloner."
|
25 |
+
if dest_namespace == "username":
|
26 |
+
dest_namespace = None
|
27 |
new_collection = api.create_collection(
|
28 |
dest_title,
|
29 |
namespace=dest_namespace,
|
|
|
36 |
api.add_collection_item(
|
37 |
new_collection.slug, item.item_id, item_type=item.item_type
|
38 |
)
|
39 |
+
return f"[Collection]({collection.url}) has been cloned into [{new_collection.slug}]({new_collection.url})"
|
40 |
|
41 |
|
42 |
title = (
|
|
|
67 |
placeholder="e.g. username/collection-slug",
|
68 |
)
|
69 |
gr.Markdown("## Destination Collection info")
|
70 |
+
|
|
|
|
|
|
|
71 |
dest_title = gr.Textbox(
|
72 |
label="Destination Title",
|
73 |
)
|
74 |
+
dest_namespace = gr.Textbox(
|
75 |
+
value="username",
|
76 |
+
label="Destination Namespace (optional - defaults to your username))",
|
77 |
+
interactive=True,
|
78 |
+
)
|
79 |
with gr.Row():
|
80 |
private = gr.Checkbox(
|
81 |
False,
|
|
|
91 |
clone_collection,
|
92 |
[
|
93 |
source_slug,
|
|
|
94 |
dest_title,
|
95 |
token,
|
96 |
+
dest_namespace,
|
97 |
private,
|
98 |
overwrite,
|
99 |
],
|