File size: 1,882 Bytes
83d67af
 
a8cd886
83d67af
 
 
a8cd886
83d67af
 
 
 
41c301c
83d67af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import tempfile

import gradio as gr
from huggingface_hub import create_repo, whoami, repo_exists, upload_folder, snapshot_download
import os


def submit(source_repo, token):
    hfa = os.getenv('HFA_TOKEN')

    org = "huggingface-assignments"
    username = whoami(token)["name"]

    target_repo = f"{org}/{username}-submission-0"

    while repo_exists(target_repo, token=hfa):
        dst_split = target_repo.split('-')
        dst_index = int(dst_split[-1])
        dst_split[-1] = str(dst_index + 1)
        target_repo = '-'.join(dst_split)

    create_repo(target_repo, token=hfa, private=True)

    with tempfile.TemporaryDirectory() as tmp:
        snapshot_download(source_repo, local_dir=tmp, local_dir_use_symlinks=False)
        upload_folder(repo_id=target_repo, folder_path=tmp, token=hfa)

    return "success"

description = "<h3>Submit your Hugging Face assignment.</h3> \nEnter the source repository (that should be private and only " \
              "accessible to you!) and your read token. \n\nWe'll duplicate it privately so that we may take a look. " \
              "We do not save your read token."

article = "<p>Find your read token at <a href='https://huggingface.co/settings/token' target='_blank'>token settings" \
          "</a></p>"

with gr.Blocks(title="Submit your assignment!") as demo:
    with gr.Column():
        gr.Markdown(description)

        with gr.Column():
            source = gr.Textbox(placeholder="Source repository (e.g. lysandre/submission)")
            token = gr.Textbox(placeholder="Read access token")
            with gr.Row():
                button = gr.Button("Submit", variant="primary")

        with gr.Column():
            output = gr.Markdown()

        gr.Markdown(article)

    button.click(submit, inputs=[source, token], outputs=output, concurrency_limit=1)

demo.queue(max_size=10).launch(show_api=True)