File size: 1,339 Bytes
68ab054
 
 
 
 
f2f0a5f
 
68ab054
 
 
 
 
 
 
f2f0a5f
68ab054
f2f0a5f
68ab054
 
 
 
f2f0a5f
 
 
 
68ab054
 
 
 
 
 
 
fe57bad
f2f0a5f
68ab054
 
f2f0a5f
 
68ab054
 
 
 
 
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
import gradio as gr
import os
import git
import shutil

# Function to clone a GitHub or Hugging Face Space repository
def clone_repo(repo_url):
    try:
        # Extract repo name from URL
        repo_name = repo_url.split('/')[-1]
        
        # Clone the repository
        if not os.path.exists(repo_name):
            git.Repo.clone_from(repo_url, repo_name)
            return f"Repository '{repo_name}' cloned successfully from {repo_url}."
        else:
            return f"Repository '{repo_name}' already exists locally."
    except Exception as e:
        return f"An error occurred: {str(e)}"

# Gradio Interface
def download_repo(repo_type, repo_url):
    # Handle both GitHub and Hugging Face Space repositories with git clone
    if repo_type in ["GitHub", "Hugging Face"]:
        return clone_repo(repo_url)
    else:
        return "Invalid repository type selected."

# Create the Gradio interface
interface = gr.Interface(
    fn=download_repo,
    inputs=[
        gr.Radio(choices=["GitHub", "Hugging Face"], label="Repository Type"),
        gr.Textbox(label="Repository URL (GitHub or Hugging Face)")
    ],
    outputs="text",
    title="Repository Cloner",
    description="Enter the GitHub repo URL or Hugging Face Space URL to clone."
)

# Launch the app
if __name__ == "__main__":
    interface.launch()