intersteller2887 commited on
Commit
ed2d077
·
verified ·
1 Parent(s): 82023b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -3,25 +3,29 @@ import os
3
  import json
4
  import pandas as pd
5
  import random
 
6
  from datasets import load_dataset
7
  from huggingface_hub import HfApi
8
 
9
  dataset = load_dataset("intersteller2887/Turing-test-dataset", split="train")
10
 
11
- print(os.getcwd())
12
- print(dataset[0])
13
 
14
- all_data_audio_paths = [
15
- item["audio"]["path"]
16
- for item in dataset
17
- if item["audio"] and "path" in item["audio"]
18
- ]
19
 
20
- """valid_audio_paths = [path for path in all_data_audio_paths if os.path.exists(path)]
21
- print(f"Total valid audio files: {len(valid_audio_paths)}")"""
 
 
 
 
 
 
22
 
 
23
 
24
- sample1_audio_path = next((p for p in all_data_audio_paths if p.endswith("/home/user/.cache/huggingface/hub/datasets--intersteller2887--Turing-test-dataset/snapshots/5cd5dd6c5badbbce22a66b3b49c4224751b10375/data/bf_train_L2_T01_1_glm.wav")), None)
25
  print(sample1_audio_path)
26
 
27
  # ==============================================================================
@@ -491,8 +495,8 @@ with gr.Blocks(theme=gr.themes.Soft(), css=".gradio-container {max-width: 960px
491
  # 程序入口 (Entry Point)
492
  # ==============================================================================
493
  if __name__ == "__main__":
494
- if not os.path.exists("audio"):
495
- os.makedirs("audio")
496
  # A quick check to see if we're in a deployed Space, to avoid local errors.
497
  if "SPACE_ID" in os.environ:
498
  print("Running in a Hugging Face Space, checking for audio files...")
 
3
  import json
4
  import pandas as pd
5
  import random
6
+ import shutil
7
  from datasets import load_dataset
8
  from huggingface_hub import HfApi
9
 
10
  dataset = load_dataset("intersteller2887/Turing-test-dataset", split="train")
11
 
12
+ target_audio_dir = "/home/user/app/audio"
13
+ os.makedirs(target_audio_dir, exist_ok=True)
14
 
15
+ local_audio_paths = []
 
 
 
 
16
 
17
+ for item in dataset:
18
+ src_path = item["audio"]["path"]
19
+ if src_path and os.path.exists(src_path):
20
+ filename = os.path.basename(src_path)
21
+ dst_path = os.path.join(target_audio_dir, filename)
22
+ if not os.path.exists(dst_path):
23
+ shutil.copy(src_path, dst_path)
24
+ local_audio_paths.append(dst_path)
25
 
26
+ all_data_audio_paths = local_audio_paths
27
 
28
+ sample1_audio_path = next((p for p in all_data_audio_paths if p.endswith("sample1.wav")), None)
29
  print(sample1_audio_path)
30
 
31
  # ==============================================================================
 
495
  # 程序入口 (Entry Point)
496
  # ==============================================================================
497
  if __name__ == "__main__":
498
+ """if not os.path.exists("audio"):
499
+ os.makedirs("audio")"""
500
  # A quick check to see if we're in a deployed Space, to avoid local errors.
501
  if "SPACE_ID" in os.environ:
502
  print("Running in a Hugging Face Space, checking for audio files...")