Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,57 @@
|
|
1 |
-
import gradio as gr
|
2 |
import os
|
3 |
import shutil
|
4 |
-
import
|
|
|
5 |
from git import Repo
|
6 |
|
7 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
try:
|
9 |
-
#
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
return zip_path
|
22 |
except Exception as e:
|
23 |
-
return str(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
gr.Markdown("## Hugging Face リポジトリ ダウンローダー")
|
28 |
-
gr.Markdown("Hugging FaceのリポジトリURLを入力して、ZIPファイルをダウンロードできます。")
|
29 |
|
30 |
with gr.Row():
|
31 |
-
|
32 |
-
download_button = gr.Button("ダウンロード")
|
33 |
|
34 |
-
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
download_button.click(
|
37 |
-
fn=download_and_zip_repo,
|
38 |
-
inputs=input_url,
|
39 |
-
outputs=output_file
|
40 |
-
)
|
41 |
|
42 |
-
#
|
43 |
-
|
|
|
|
|
1 |
import os
|
2 |
import shutil
|
3 |
+
import zipfile
|
4 |
+
import gradio as gr
|
5 |
from git import Repo
|
6 |
|
7 |
+
def clone_and_zip_repo(repo_url):
|
8 |
+
# Directory settings
|
9 |
+
clone_dir = "cloned_repo"
|
10 |
+
zip_file = "repo.zip"
|
11 |
+
|
12 |
+
# Clean up old directories and files if they exist
|
13 |
+
if os.path.exists(clone_dir):
|
14 |
+
shutil.rmtree(clone_dir)
|
15 |
+
if os.path.exists(zip_file):
|
16 |
+
os.remove(zip_file)
|
17 |
+
|
18 |
try:
|
19 |
+
# Clone the repository
|
20 |
+
Repo.clone_from(repo_url, clone_dir)
|
21 |
+
|
22 |
+
# Create a zip file
|
23 |
+
with zipfile.ZipFile(zip_file, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
24 |
+
for root, _, files in os.walk(clone_dir):
|
25 |
+
for file in files:
|
26 |
+
file_path = os.path.join(root, file)
|
27 |
+
arcname = os.path.relpath(file_path, clone_dir)
|
28 |
+
zipf.write(file_path, arcname)
|
29 |
+
|
30 |
+
return zip_file
|
|
|
31 |
except Exception as e:
|
32 |
+
return f"Error: {str(e)}"
|
33 |
+
|
34 |
+
# Gradio interface
|
35 |
+
def download_repo(repo_url):
|
36 |
+
result = clone_and_zip_repo(repo_url)
|
37 |
+
if result.endswith(".zip"):
|
38 |
+
return result
|
39 |
+
else:
|
40 |
+
return result
|
41 |
|
42 |
+
with gr.Blocks() as demo:
|
43 |
+
gr.Markdown("## Clone and Download Hugging Face Repository")
|
|
|
|
|
44 |
|
45 |
with gr.Row():
|
46 |
+
repo_url_input = gr.Textbox(label="Hugging Face Repo URL", placeholder="Enter the repository URL")
|
|
|
47 |
|
48 |
+
with gr.Row():
|
49 |
+
download_button = gr.Button("Clone and Download")
|
50 |
+
|
51 |
+
with gr.Row():
|
52 |
+
output = gr.File(label="Download Zip File")
|
53 |
|
54 |
+
download_button.click(download_repo, inputs=[repo_url_input], outputs=[output])
|
|
|
|
|
|
|
|
|
55 |
|
56 |
+
# Run the Gradio app
|
57 |
+
demo.launch()
|