Update app.py
Browse files
app.py
CHANGED
@@ -1,39 +1,33 @@
|
|
1 |
import os
|
2 |
-
import
|
3 |
-
import zipfile
|
4 |
import gradio as gr
|
5 |
-
from git import Repo
|
6 |
|
7 |
-
def
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
shutil.rmtree(clone_dir)
|
15 |
-
if os.path.exists(zip_file):
|
16 |
-
os.remove(zip_file)
|
17 |
|
|
|
18 |
try:
|
19 |
-
#
|
20 |
-
|
|
|
21 |
|
22 |
-
#
|
23 |
-
with
|
24 |
-
for
|
25 |
-
|
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
|
36 |
-
result =
|
37 |
if result.endswith(".zip"):
|
38 |
return result
|
39 |
else:
|
@@ -46,12 +40,12 @@ with gr.Blocks() as demo:
|
|
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("
|
50 |
-
|
51 |
with gr.Row():
|
52 |
output = gr.File(label="Download Zip File")
|
53 |
-
|
54 |
-
download_button.click(
|
55 |
|
56 |
# Run the Gradio app
|
57 |
demo.launch()
|
|
|
1 |
import os
|
2 |
+
import requests
|
|
|
3 |
import gradio as gr
|
|
|
4 |
|
5 |
+
def download_and_save_repo(repo_url):
|
6 |
+
# 対応するzip URLを生成(GitHubの場合に応用可能)
|
7 |
+
if not repo_url.endswith(".git"):
|
8 |
+
return "Error: The provided URL does not point to a Git repository."
|
9 |
|
10 |
+
# .git を削除してzip形式のURLに変換
|
11 |
+
zip_url = repo_url.replace(".git", "/archive/refs/heads/main.zip")
|
|
|
|
|
|
|
12 |
|
13 |
+
zip_file = "repo.zip"
|
14 |
try:
|
15 |
+
# リポジトリのzipファイルをダウンロード
|
16 |
+
response = requests.get(zip_url, stream=True)
|
17 |
+
response.raise_for_status() # HTTPエラーをチェック
|
18 |
|
19 |
+
# ダウンロードしたファイルを保存
|
20 |
+
with open(zip_file, "wb") as f:
|
21 |
+
for chunk in response.iter_content(chunk_size=1024):
|
22 |
+
f.write(chunk)
|
|
|
|
|
|
|
23 |
|
24 |
return zip_file
|
25 |
except Exception as e:
|
26 |
return f"Error: {str(e)}"
|
27 |
|
28 |
# Gradio interface
|
29 |
+
def handle_download(repo_url):
|
30 |
+
result = download_and_save_repo(repo_url)
|
31 |
if result.endswith(".zip"):
|
32 |
return result
|
33 |
else:
|
|
|
40 |
repo_url_input = gr.Textbox(label="Hugging Face Repo URL", placeholder="Enter the repository URL")
|
41 |
|
42 |
with gr.Row():
|
43 |
+
download_button = gr.Button("Download Repository as Zip")
|
44 |
+
|
45 |
with gr.Row():
|
46 |
output = gr.File(label="Download Zip File")
|
47 |
+
|
48 |
+
download_button.click(handle_download, inputs=[repo_url_input], outputs=[output])
|
49 |
|
50 |
# Run the Gradio app
|
51 |
demo.launch()
|