soiz1 commited on
Commit
4843bdd
·
verified ·
1 Parent(s): 1f259e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -18
app.py CHANGED
@@ -3,35 +3,28 @@ 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:
34
- return result
35
 
36
  with gr.Blocks() as demo:
37
  gr.Markdown("## Clone and Download Hugging Face Repository")
@@ -43,9 +36,9 @@ with gr.Blocks() as demo:
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()
 
3
  import gradio as gr
4
 
5
  def download_and_save_repo(repo_url):
 
6
  if not repo_url.endswith(".git"):
7
+ return None, "Error: The provided URL does not point to a Git repository."
8
 
 
9
  zip_url = repo_url.replace(".git", "/archive/refs/heads/main.zip")
 
10
  zip_file = "repo.zip"
11
+
12
  try:
 
13
  response = requests.get(zip_url, stream=True)
14
+ response.raise_for_status()
15
 
 
16
  with open(zip_file, "wb") as f:
17
  for chunk in response.iter_content(chunk_size=1024):
18
  f.write(chunk)
19
 
20
+ return zip_file, "Repository downloaded and zipped successfully."
21
  except Exception as e:
22
+ return None, f"Error: {str(e)}"
23
 
24
  # Gradio interface
25
  def handle_download(repo_url):
26
+ file_path, message = download_and_save_repo(repo_url)
27
+ return file_path, message
 
 
 
28
 
29
  with gr.Blocks() as demo:
30
  gr.Markdown("## Clone and Download Hugging Face Repository")
 
36
  download_button = gr.Button("Download Repository as Zip")
37
 
38
  with gr.Row():
39
+ output_file = gr.File(label="Download Zip File")
40
+ output_message = gr.Textbox(label="Status", interactive=False)
41
+
42
+ download_button.click(handle_download, inputs=[repo_url_input], outputs=[output_file, output_message])
43
 
 
44
  demo.launch()