Juna190825 commited on
Commit
f7dbb6f
·
verified ·
1 Parent(s): 0c589fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -1
app.py CHANGED
@@ -56,6 +56,20 @@ def list_dataset_files(repo_id: str):
56
  except Exception as e:
57
  return [], f"Error: {e}"
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  def load_audio(repo_id, file_path):
60
  try:
61
  local_path = hf_hub_download(
@@ -64,10 +78,18 @@ def load_audio(repo_id, file_path):
64
  repo_type="dataset",
65
  token=os.getenv("HF_TOKEN")
66
  )
67
- return local_path
 
 
 
 
 
 
 
68
  except Exception as e:
69
  return None
70
 
 
71
  with gr.Blocks() as demo:
72
  gr.Markdown("# 🎧 List & Play Audio Files from a HF Dataset Repo")
73
 
 
56
  except Exception as e:
57
  return [], f"Error: {e}"
58
 
59
+ # def load_audio(repo_id, file_path):
60
+ # try:
61
+ # local_path = hf_hub_download(
62
+ # repo_id=repo_id,
63
+ # filename=file_path,
64
+ # repo_type="dataset",
65
+ # token=os.getenv("HF_TOKEN")
66
+ # )
67
+ # return local_path
68
+ # except Exception as e:
69
+ # return None
70
+ import shutil
71
+ import tempfile
72
+
73
  def load_audio(repo_id, file_path):
74
  try:
75
  local_path = hf_hub_download(
 
78
  repo_type="dataset",
79
  token=os.getenv("HF_TOKEN")
80
  )
81
+
82
+ # Copy to a temp file Gradio is allowed to serve
83
+ tmp_dir = tempfile.gettempdir()
84
+ safe_path = os.path.join(tmp_dir, os.path.basename(local_path))
85
+ shutil.copy(local_path, safe_path)
86
+
87
+ return safe_path
88
+
89
  except Exception as e:
90
  return None
91
 
92
+
93
  with gr.Blocks() as demo:
94
  gr.Markdown("# 🎧 List & Play Audio Files from a HF Dataset Repo")
95