File size: 1,596 Bytes
2338bc5
 
d4925d2
 
2338bc5
 
d4925d2
 
 
 
 
 
 
 
 
 
 
2338bc5
d4925d2
 
 
 
 
 
 
 
 
 
 
 
2338bc5
d4925d2
 
 
 
 
 
 
 
 
2338bc5
d4925d2
 
2338bc5
 
d4925d2
2338bc5
d4925d2
 
 
 
 
2338bc5
d4925d2
2338bc5
d4925d2
 
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
import os
import shutil
import zipfile
import gradio as gr
from git import Repo

def clone_and_zip_repo(repo_url):
    # Directory settings
    clone_dir = "cloned_repo"
    zip_file = "repo.zip"

    # Clean up old directories and files if they exist
    if os.path.exists(clone_dir):
        shutil.rmtree(clone_dir)
    if os.path.exists(zip_file):
        os.remove(zip_file)

    try:
        # Clone the repository
        Repo.clone_from(repo_url, clone_dir)

        # Create a zip file
        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)}"

# Gradio interface
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])

# Run the Gradio app
demo.launch()