soiz1 commited on
Commit
2338bc5
·
verified ·
1 Parent(s): 5b1e270

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import shutil
4
+ import tempfile
5
+ from git import Repo
6
+
7
+ def download_and_zip_repo(huggingface_url):
8
+ try:
9
+ # 一時ディレクトリを作成
10
+ with tempfile.TemporaryDirectory() as temp_dir:
11
+ # リポジトリをクローン
12
+ Repo.clone_from(huggingface_url, temp_dir)
13
+
14
+ # ZIPファイルのパスを指定
15
+ zip_path = os.path.join(temp_dir, "repository.zip")
16
+
17
+ # クローンしたリポジトリをZIP形式で圧縮
18
+ shutil.make_archive(zip_path.replace(".zip", ""), 'zip', temp_dir)
19
+
20
+ # 圧縮したZIPファイルを返す
21
+ return zip_path
22
+ except Exception as e:
23
+ return str(e)
24
+
25
+ # Gradioインターフェースの定義
26
+ with gr.Blocks() as app:
27
+ gr.Markdown("## Hugging Face リポジトリ ダウンローダー")
28
+ gr.Markdown("Hugging FaceのリポジトリURLを入力して、ZIPファイルをダウンロードできます。")
29
+
30
+ with gr.Row():
31
+ input_url = gr.Textbox(label="Hugging Face リポジトリのURLを入力")
32
+ download_button = gr.Button("ダウンロード")
33
+
34
+ output_file = gr.File(label="ダウンロードされたZIPファイル")
35
+
36
+ download_button.click(
37
+ fn=download_and_zip_repo,
38
+ inputs=input_url,
39
+ outputs=output_file
40
+ )
41
+
42
+ # アプリを起動
43
+ app.launch()