Spaces:
Sleeping
Sleeping
File size: 2,361 Bytes
a8cd886 a4d7e4d 644a2ce a4d7e4d a8cd886 67b361f a4d7e4d c1694e9 a4d7e4d a8cd886 a4d7e4d a1d6c04 a4d7e4d deca531 a4d7e4d a8cd886 c33fac7 a8cd886 c1694e9 644a2ce 67b361f 644a2ce 67b361f ac40162 a4d7e4d a8cd886 a4d7e4d a8cd886 d39b290 39f2022 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
import gradio as gr
import requests
from huggingface_hub import whoami
from huggingface_hub.utils import build_hf_headers, hf_raise_for_status
from gradio_huggingfacehub_search import HuggingfaceHubSearch
ENDPOINT = "https://huggingface.co"
# ENDPOINT = "http://localhost:5564"
REPO_TYPES = ["model", "dataset", "space"]
def duplicate(oauth_token: gr.OAuthToken | None, source_repo, dst_repo, repo_type, private):
try:
if not repo_type in REPO_TYPES:
raise ValueError("need to select valid repo type")
token = oauth_token.token
_ = whoami(token)
# ^ this will throw if token is invalid
r = requests.post(
f"{ENDPOINT}/api/{repo_type}s/{source_repo}/duplicate",
headers=build_hf_headers(token=token),
json={"repository": dst_repo, "private": private},
)
hf_raise_for_status(r)
repo_url = r.json().get("url")
return (
f'Find your repo <a href=\'{repo_url}\' target="_blank" style="text-decoration:underline">here</a>',
"sp.jpg",
)
except Exception as e:
return (
f"""
### Error 😢😢😢
{e}
""",
None,
)
interface = gr.Interface(
fn=duplicate,
inputs=[
gr.LoginButton(),
HuggingfaceHubSearch(
placeholder="Source repository (e.g. osanseviero/src)",
search_type=["model", "dataset", "space"],
sumbit_on_select=False,
label="source_repo",
),
gr.Textbox(placeholder="Destination repository (e.g. osanseviero/dst)", label="dst_repo"),
gr.Dropdown(choices=REPO_TYPES, value="model", label="repo_type"),
gr.Checkbox(label="Make new repo private?"),
],
outputs=[
gr.Markdown(label="output"),
gr.Image(show_label=False),
],
title="Duplicate your repo!",
description="Duplicate a Hugging Face repository! You need to specify a write token obtained in https://hf.co/settings/tokens. This Space is a an experimental demo.",
article="<p>Find your write token at <a href='https://huggingface.co/settings/tokens' target='_blank'>token settings</a></p>",
allow_flagging="never",
live=False,
)
interface.queue()
interface.launch(show_error=True)
|