Spaces:
Sleeping
Sleeping
File size: 1,996 Bytes
68ab054 ab4fda4 68ab054 f2f0a5f 68ab054 ab4fda4 68ab054 ab4fda4 68ab054 f2f0a5f ab4fda4 68ab054 ab4fda4 68ab054 ab4fda4 68ab054 fe57bad f2f0a5f 68ab054 ab4fda4 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 57 58 59 60 61 62 63 |
import gradio as gr
import os
import git
import shutil
import zipfile
# 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]
# Remove the folder if it already exists (optional step)
if os.path.exists(repo_name):
shutil.rmtree(repo_name)
# Clone the repository
git.Repo.clone_from(repo_url, repo_name)
# Zip the cloned repository
zip_file = f"{repo_name}.zip"
shutil.make_archive(repo_name, 'zip', repo_name)
# Return the path to the zip file for downloading
return zip_file
except Exception as e:
return f"An error occurred: {str(e)}"
# Gradio Interface
def download_repo(repo_type, repo_url):
if repo_type in ["GitHub", "Hugging Face"]:
zip_file = clone_repo(repo_url)
if os.path.exists(zip_file):
return zip_file # Return path to the zip file for download
else:
return "Failed to create the ZIP file."
else:
return "Invalid repository type selected."
# Gradio Interface with file download
def zip_download_link(repo_type, repo_url):
zip_file = download_repo(repo_type, repo_url)
if isinstance(zip_file, str) and zip_file.endswith(".zip"):
return gr.File(zip_file) # Provide a downloadable file
else:
return "An error occurred."
# Create the Gradio interface
interface = gr.Interface(
fn=zip_download_link,
inputs=[
gr.Radio(choices=["GitHub", "Hugging Face"], label="Repository Type"),
gr.Textbox(label="Repository URL (GitHub or Hugging Face)")
],
outputs="file", # File output to allow ZIP download
title="Repository Cloner & Downloader",
description="Enter the GitHub or Hugging Face Space URL to clone and download as a ZIP."
)
# Launch the app
if __name__ == "__main__":
interface.launch()
|