File size: 1,337 Bytes
db5eb35
 
 
 
12451eb
db5eb35
6702974
88dd322
db5eb35
7c0fb07
f6b4a60
db5eb35
33c8181
cecd3d3
f6b4a60
 
6702974
cecd3d3
db5eb35
b76f040
5c2a11f
db5eb35
 
233589f
db5eb35
 
 
 
 
 
 
 
ce6f085
db5eb35
 
 
ce6f085
db5eb35
 
 
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
import gradio as gr
from huggingface_hub import HfApi
from git import Repo
import uuid 
from slugify import slugify

def clone(profile: gr.OAuthProfile, oauth_token: gr.OAuthToken, repo_git, repo_hf, sdk_type):
    folder = str(uuid.uuid4())
    cloned_repo = Repo.clone_from(repo_git, folder)
    cloned_repo.git.submodule('update', '--init', '--recursive')

    #Upload to HF
    api = HfApi(token=oauth_token.token)
    api.create_repo(
        f"{profile.username}/{slugify(repo_hf)}",
        repo_type="space",
        space_sdk=sdk_type
    )
    api.upload_folder(
        folder_path=folder,
        repo_id=f"{profile.username}/{slugify(repo_hf)}",
        repo_type="space",
    )
    return f"https://huggingface.co/spaces/{profile.username}/{slugify(repo_hf)}"


with gr.Blocks() as demo:
    gr.LoginButton()
    with gr.Row():
        with gr.Column():
            repo_git = gr.Textbox(label="GitHub Repository")
            repo_hf = gr.Textbox(label="Hugging Face Space name")
            sdk_choices = gr.Radio(["gradio", "streamlit", "docker", "static"], label="SDK Choices")
        with gr.Column():
            output = gr.Textbox(label="Output repo")
    btn = gr.Button("Bring over!")
    btn.click(fn=clone, inputs=[repo_git, repo_hf, sdk_choices], outputs=output)

if __name__ == "__main__":
    demo.launch()