Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Initial commit
Browse files- .gitignore +1 -0
- README.md +3 -6
- app.py +51 -72
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.env
|
README.md
CHANGED
@@ -1,13 +1,10 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: π»
|
4 |
-
colorFrom:
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.0.10
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
11 |
-
---
|
12 |
-
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
|
|
|
1 |
---
|
2 |
+
title: Submit
|
3 |
emoji: π»
|
4 |
+
colorFrom: purple
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
|
|
7 |
app_file: app.py
|
8 |
pinned: false
|
9 |
license: mit
|
10 |
+
---
|
|
|
|
app.py
CHANGED
@@ -1,75 +1,54 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
from huggingface_hub import create_repo,
|
3 |
-
import
|
4 |
-
|
5 |
|
6 |
-
def
|
7 |
-
|
8 |
-
|
|
|
9 |
username = whoami(token)["name"]
|
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 |
-
file_path = os.path.join(local_dir, filename)
|
53 |
-
if os.path.isfile(file_path) or os.path.islink(file_path):
|
54 |
-
os.unlink(file_path)
|
55 |
-
elif os.path.isdir(file_path):
|
56 |
-
shutil.rmtree(file_path)
|
57 |
-
|
58 |
-
return f"Find your repo <a href='{url}' target=\"_blank\" style=\"text-decoration:underline\">here</a>", "sp.jpg"
|
59 |
-
|
60 |
-
interface = gr.Interface(
|
61 |
-
fn=duplicate,
|
62 |
-
inputs=[
|
63 |
-
gr.inputs.Textbox(placeholder="Source repository (e.g. osanseviero/src)"),
|
64 |
-
gr.inputs.Textbox(placeholder="Destination repository (e.g. osanseviero/dst)"),
|
65 |
-
gr.inputs.Textbox(placeholder="Write access token"),
|
66 |
-
gr.inputs.Dropdown(choices=["model", "dataset", "space"])
|
67 |
-
],
|
68 |
-
outputs=["html", "image"] ,
|
69 |
-
title="Duplicate your repo!",
|
70 |
-
description="Duplicate a Hugging Face repository! You need to specify a write token obtained in https://hf.co/settings/token. This Space is a an experimental demo.",
|
71 |
-
article="<p>Find your write token at <a href='https://huggingface.co/settings/token' target='_blank'>token settings</a></p>",
|
72 |
-
allow_flagging=False,
|
73 |
-
live=False,
|
74 |
-
)
|
75 |
-
interface.launch(enable_queue=True)
|
|
|
1 |
+
import tempfile
|
2 |
+
|
3 |
import gradio as gr
|
4 |
+
from huggingface_hub import create_repo, whoami, repo_exists, upload_folder, snapshot_download
|
5 |
+
import os
|
6 |
+
|
7 |
|
8 |
+
def submit(source_repo, token):
|
9 |
+
hfa = os.getenv('HFA_TOKEN')
|
10 |
+
|
11 |
+
org = "huggingface-assignments"
|
12 |
username = whoami(token)["name"]
|
13 |
+
|
14 |
+
target_repo = f"{org}/{username}-submission-0"
|
15 |
+
|
16 |
+
while repo_exists(target_repo, token=hfa):
|
17 |
+
dst_split = target_repo.split('-')
|
18 |
+
dst_index = int(dst_split[-1])
|
19 |
+
dst_split[-1] = str(dst_index + 1)
|
20 |
+
target_repo = '-'.join(dst_split)
|
21 |
+
|
22 |
+
create_repo(target_repo, token=hfa, private=True)
|
23 |
+
|
24 |
+
with tempfile.TemporaryDirectory() as tmp:
|
25 |
+
snapshot_download(source_repo, local_dir=tmp, local_dir_use_symlinks=False)
|
26 |
+
upload_folder(repo_id=target_repo, folder_path=tmp, token=hfa)
|
27 |
+
|
28 |
+
return "success"
|
29 |
+
|
30 |
+
description = "<h3>Submit your Hugging Face assignment.</h3> \nEnter the source repository (that should be private and only " \
|
31 |
+
"accessible to you!) and your read token. \n\nWe'll duplicate it privately so that we may take a look. " \
|
32 |
+
"We do not save your read token."
|
33 |
+
|
34 |
+
article = "<p>Find your read token at <a href='https://huggingface.co/settings/token' target='_blank'>token settings" \
|
35 |
+
"</a></p>"
|
36 |
+
|
37 |
+
with gr.Blocks(title="Submit your assignment!") as demo:
|
38 |
+
with gr.Column():
|
39 |
+
gr.Markdown(description)
|
40 |
+
|
41 |
+
with gr.Column():
|
42 |
+
source = gr.Textbox(placeholder="Source repository (e.g. lysandre/submission)")
|
43 |
+
token = gr.Textbox(placeholder="Read access token")
|
44 |
+
with gr.Row():
|
45 |
+
button = gr.Button("Submit", variant="primary")
|
46 |
+
|
47 |
+
with gr.Column():
|
48 |
+
output = gr.Markdown()
|
49 |
+
|
50 |
+
gr.Markdown(article)
|
51 |
+
|
52 |
+
button.click(submit, inputs=[source, token], outputs=output, concurrency_limit=1)
|
53 |
+
|
54 |
+
demo.queue(max_size=10).launch(show_api=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|