|
import os |
|
import shutil |
|
import zipfile |
|
import gradio as gr |
|
from git import Repo |
|
|
|
def clone_and_zip_repo(repo_url): |
|
|
|
clone_dir = "cloned_repo" |
|
zip_file = "repo.zip" |
|
|
|
|
|
if os.path.exists(clone_dir): |
|
shutil.rmtree(clone_dir) |
|
if os.path.exists(zip_file): |
|
os.remove(zip_file) |
|
|
|
try: |
|
|
|
Repo.clone_from(repo_url, clone_dir) |
|
|
|
|
|
with zipfile.ZipFile(zip_file, 'w', zipfile.ZIP_DEFLATED) as zipf: |
|
for root, _, files in os.walk(clone_dir): |
|
for file in files: |
|
file_path = os.path.join(root, file) |
|
arcname = os.path.relpath(file_path, clone_dir) |
|
zipf.write(file_path, arcname) |
|
|
|
return zip_file |
|
except Exception as e: |
|
return f"Error: {str(e)}" |
|
|
|
|
|
def download_repo(repo_url): |
|
result = clone_and_zip_repo(repo_url) |
|
if result.endswith(".zip"): |
|
return result |
|
else: |
|
return result |
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("## Clone and Download Hugging Face Repository") |
|
|
|
with gr.Row(): |
|
repo_url_input = gr.Textbox(label="Hugging Face Repo URL", placeholder="Enter the repository URL") |
|
|
|
with gr.Row(): |
|
download_button = gr.Button("Clone and Download") |
|
|
|
with gr.Row(): |
|
output = gr.File(label="Download Zip File") |
|
|
|
download_button.click(download_repo, inputs=[repo_url_input], outputs=[output]) |
|
|
|
|
|
demo.launch() |
|
|