Repo_Downloader / app.py
mobenta's picture
Update app.py
f2f0a5f verified
raw
history blame
1.34 kB
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()