Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- README.md +18 -0
- app.py +39 -0
- requirements.txt +3 -0
README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Github Repo To Spaces
|
| 3 |
+
emoji: 🚚
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 4.32.1
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
hf_oauth: true
|
| 12 |
+
hf_oauth_scopes:
|
| 13 |
+
- read-repos
|
| 14 |
+
- write-repos
|
| 15 |
+
- manage-repos
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import HfApi
|
| 3 |
+
from git import Repo
|
| 4 |
+
import uuid
|
| 5 |
+
from slugify import slugify
|
| 6 |
+
|
| 7 |
+
def clone(profile: gr.OAuthProfile, oauth_token: gr.OAuthToken, repo_git, repo_hf, sdk_type):
|
| 8 |
+
folder = str(uuid.uuid4())
|
| 9 |
+
cloned_repo = Repo.clone_from(repo_git, folder)
|
| 10 |
+
|
| 11 |
+
#Upload to HF
|
| 12 |
+
api = HfApi(token=oauth_token.token)
|
| 13 |
+
api.create_repo(
|
| 14 |
+
f"{profile.username}/{slugify(repo_hf)}",
|
| 15 |
+
repo_type="space",
|
| 16 |
+
space_sdk=sdk_type
|
| 17 |
+
)
|
| 18 |
+
api.upload_folder(
|
| 19 |
+
folder_path=folder,
|
| 20 |
+
repo_id=f"{profile.username}/{slugify(repo_hf)}",
|
| 21 |
+
repo_type="space",
|
| 22 |
+
)
|
| 23 |
+
return f"https://huggingface.co/spaces/{profile.username}/{slugify(repo_hf)}"
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
with gr.Blocks() as demo:
|
| 27 |
+
gr.LoginButton()
|
| 28 |
+
with gr.Row():
|
| 29 |
+
with gr.Column():
|
| 30 |
+
repo_git = gr.Textbox(label="GitHub Repository")
|
| 31 |
+
repo_hf = gr.Textbox(label="Hugging Face Space name")
|
| 32 |
+
sdk_choices = gr.Radio(["gradio", "streamlit", "docker", "static"], label="SDK Choices")
|
| 33 |
+
with gr.Column():
|
| 34 |
+
output = gr.Textbox(label="Output repo")
|
| 35 |
+
btn = gr.Button("Bring over!")
|
| 36 |
+
btn.click(fn=clone, inputs=[repo_git, repo_hf, sdk_choices], outputs=output)
|
| 37 |
+
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GitPython
|
| 2 |
+
python-slugify
|
| 3 |
+
uuid
|