soiz1 commited on
Commit
949f5b0
·
verified ·
1 Parent(s): d0045c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -19
app.py CHANGED
@@ -1,31 +1,35 @@
1
  import os
2
  import zipfile
3
- from huggingface_hub import hf_hub_download
4
  import gradio as gr
5
 
6
- # Hugging Faceからデータセットをダウンロードする関数
7
  def download_and_zip(repo_id, folder_name):
8
- # Hugging Face Hubから対象データセットのファイルをダウンロード
9
  try:
10
- dataset_path = hf_hub_download(repo_id=repo_id, repo_type="dataset")
11
- except Exception as e:
12
- return f"エラー: {str(e)}"
 
 
13
 
14
- folder_path = os.path.join(dataset_path, folder_name)
 
15
 
16
- # ZIP圧縮の保存先パス
17
- zip_path = f"{folder_name}.zip"
18
 
19
- # フォルダが存在するかをチェック
20
- if os.path.exists(folder_path) and os.path.isdir(folder_path):
21
- # フォルダをZIP圧縮する
22
- with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
23
- for root, dirs, files in os.walk(folder_path):
24
- for file in files:
25
- zipf.write(os.path.join(root, file), os.path.relpath(os.path.join(root, file), folder_path))
26
- return zip_path
27
- else:
28
- return "指定されたフォルダが見つかりません"
 
 
29
 
30
  # Gradioインターフェースの作成
31
  def interface(repo_id, folder_name):
 
1
  import os
2
  import zipfile
3
+ import datasets
4
  import gradio as gr
5
 
6
+ # Hugging Faceのデータセットをダウンロードして指定されたフォルダをZIP圧縮する関数
7
  def download_and_zip(repo_id, folder_name):
 
8
  try:
9
+ # データセットをHugging Face Hubからダウンロード
10
+ dataset = datasets.load_dataset(repo_id)
11
+
12
+ # ダウンロードされたデータセットのパスを取得
13
+ dataset_path = dataset.data_files['train'] # 'train' データセットを例にします。必要に応じて変更
14
 
15
+ # フォルダのパス
16
+ folder_path = os.path.join(dataset_path, folder_name)
17
 
18
+ # ZIP圧縮の保存先パス
19
+ zip_path = f"{folder_name}.zip"
20
 
21
+ # フォルダが存在するかをチェック
22
+ if os.path.exists(folder_path) and os.path.isdir(folder_path):
23
+ # フォルダをZIP圧縮する
24
+ with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
25
+ for root, dirs, files in os.walk(folder_path):
26
+ for file in files:
27
+ zipf.write(os.path.join(root, file), os.path.relpath(os.path.join(root, file), folder_path))
28
+ return zip_path
29
+ else:
30
+ return "指定されたフォルダが見つかりません"
31
+ except Exception as e:
32
+ return f"エラー: {str(e)}"
33
 
34
  # Gradioインターフェースの作成
35
  def interface(repo_id, folder_name):