soiz1 commited on
Commit
148a42e
Β·
verified Β·
1 Parent(s): b77d102

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -5,6 +5,15 @@ import shutil
5
  import gradio as gr
6
  import time
7
 
 
 
 
 
 
 
 
 
 
8
  def process_and_zip_folders(huggingface_dataset_url, output_dir):
9
  # URLからγƒͺγƒγ‚ΈγƒˆγƒͺIDγ‚’ζŠ½ε‡Ί
10
  if huggingface_dataset_url.startswith("https://huggingface.co/"):
@@ -19,6 +28,9 @@ def process_and_zip_folders(huggingface_dataset_url, output_dir):
19
  dataset_path = None
20
  for attempt in range(retry_attempts):
21
  try:
 
 
 
22
  dataset_path = snapshot_download(repo_id, repo_type="dataset", force_download=True)
23
  break # ζˆεŠŸγ—γŸε ΄εˆγ―γƒ«γƒΌγƒ—γ‚’η΅‚δΊ†
24
  except OSError as e:
@@ -63,6 +75,9 @@ def process_and_zip_folders(huggingface_dataset_url, output_dir):
63
 
64
  def gradio_interface():
65
  def start_process(huggingface_url, output_directory):
 
 
 
66
  zip_files = process_and_zip_folders(huggingface_url, output_directory)
67
  return zip_files
68
 
 
5
  import gradio as gr
6
  import time
7
 
8
+ def clear_cache():
9
+ """Hugging Faceキャッシγƒ₯γ‚’ε‰Šι™€γ™γ‚‹ι–’ζ•°γ€‚"""
10
+ cache_dir = os.path.expanduser("~/.cache/huggingface")
11
+ if os.path.exists(cache_dir):
12
+ print(f"Clearing cache at: {cache_dir}")
13
+ shutil.rmtree(cache_dir)
14
+ else:
15
+ print("No cache found to clear.")
16
+
17
  def process_and_zip_folders(huggingface_dataset_url, output_dir):
18
  # URLからγƒͺγƒγ‚ΈγƒˆγƒͺIDγ‚’ζŠ½ε‡Ί
19
  if huggingface_dataset_url.startswith("https://huggingface.co/"):
 
28
  dataset_path = None
29
  for attempt in range(retry_attempts):
30
  try:
31
+ if attempt > 0:
32
+ print(f"Retrying... (Attempt {attempt + 1})")
33
+ clear_cache() # キャッシγƒ₯ε‰Šι™€
34
  dataset_path = snapshot_download(repo_id, repo_type="dataset", force_download=True)
35
  break # ζˆεŠŸγ—γŸε ΄εˆγ―γƒ«γƒΌγƒ—γ‚’η΅‚δΊ†
36
  except OSError as e:
 
75
 
76
  def gradio_interface():
77
  def start_process(huggingface_url, output_directory):
78
+ # ε‡ΊεŠ›γƒ‡γ‚£γƒ¬γ‚―γƒˆγƒͺγŒε­˜εœ¨γ—γͺγ„ε ΄εˆγ―δ½œζˆ
79
+ if not os.path.exists(output_directory):
80
+ os.makedirs(output_directory, exist_ok=True)
81
  zip_files = process_and_zip_folders(huggingface_url, output_directory)
82
  return zip_files
83