Spaces:
Sleeping
Sleeping
File size: 1,794 Bytes
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 45 46 47 48 49 50 51 52 53 54 55 56 |
import gradio as gr
import os
import git
from huggingface_hub import snapshot_download
import shutil
# Function to clone a GitHub repository
def download_github_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"GitHub repository '{repo_name}' downloaded successfully."
else:
return f"GitHub repository '{repo_name}' already exists locally."
except Exception as e:
return f"An error occurred: {str(e)}"
# Function to download a Hugging Face model or dataset
def download_huggingface_repo(repo_id):
try:
# Download the Hugging Face model or dataset snapshot
repo_path = snapshot_download(repo_id)
return f"Hugging Face repository '{repo_id}' downloaded successfully."
except Exception as e:
return f"An error occurred: {str(e)}"
# Gradio Interface
def download_repo(repo_type, repo_url_or_id):
if repo_type == "GitHub":
return download_github_repo(repo_url_or_id)
elif repo_type == "Hugging Face":
return download_huggingface_repo(repo_url_or_id)
else:
return "Invalid repository type selected."
# Create the Gradio interface
interface = gr.Interface(
fn=download_repo,
inputs=[
gr.inputs.Radio(choices=["GitHub", "Hugging Face"], label="Repository Type"),
gr.inputs.Textbox(label="Repository URL (GitHub) or Repo ID (Hugging Face)")
],
outputs="text",
title="Repository Downloader",
description="Enter the GitHub repo URL or Hugging Face repo ID to download."
)
# Launch the app
if __name__ == "__main__":
interface.launch()
|