| 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 |
| ) |
|
|
| |
| 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(): |
| btn = gr.Button("Bring over!") |
| 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") |
| output = gr.Textbox(label="Output repo") |
| |
| btn.click(fn=clone, inputs=[repo_git, repo_hf, sdk_choices], outputs=output) |
| |
| |
| demo.launch(theme="NeoPy/Soft") |
|
|