multimodalart HF staff commited on
Commit
db5eb35
1 Parent(s): d16bb44

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import HfApi
3
+ from git import Repo
4
+ import uuid
5
+
6
+
7
+ def clone(profile: gr.OAuthProfile, oauth_token: gr.OAuthToken, repo_git, repo_hf):
8
+ folder = uuid.uuid1()
9
+ cloned_repo = Repo.clone_from(repo_git, folder)
10
+ #Upload to HF
11
+ api = HfApi(token=oauth_token)
12
+ api.upload_folder(
13
+ folder_path=cloned_repo,
14
+ repo_id={profile.username}/{repo_hf},
15
+ repo_type="space",
16
+ )
17
+ return f"https://huggingface.co/{profile.username}/{repo_hf}"
18
+
19
+
20
+ with gr.Blocks() as demo:
21
+ gr.LoginButton()
22
+ with gr.Row():
23
+ with gr.Column():
24
+ repo_git = gr.Textbox(label="GitHub Repository")
25
+ repo_hf = gr.Textbox(label="Hugging Face Space name")
26
+ with gr.Column():
27
+ output = gr.Textbox(label="Output repo")
28
+ btn = gr.Button("Bring over!")
29
+ btn.click(fn=clone, inputs=[repo_git, repo_hf], outputs=output)
30
+
31
+ if __name__ == "__main__":
32
+ demo.launch()