unknown commited on
Commit
6dedffc
·
1 Parent(s): b9196ed

Add app.py

Browse files
app.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # app.py (at repo root)
2
+ from ui.app import demo
3
+
4
+ if __name__ == "__main__":
5
+ demo.launch(server_name="0.0.0.0", server_port=7860)
runs/whisper_small_86383839/run_meta.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "run_id": "whisper_small_86383839",
3
+ "manifest_path": "data/manifest.jsonl",
4
+ "model_info": {
5
+ "name": "faster-whisper",
6
+ "model_name": "small",
7
+ "device": "cpu",
8
+ "compute_type": "int8"
9
+ },
10
+ "asr_config": {
11
+ "language": "zh",
12
+ "task": "transcribe",
13
+ "beam_size": 5,
14
+ "best_of": 5,
15
+ "temperature": 0.0,
16
+ "vad_filter": true,
17
+ "chunk_length_s": null,
18
+ "initial_prompt": null
19
+ }
20
+ }
scripts/run_cv_zhcn_quickstart.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import json
3
+ import os
4
+ import subprocess
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ def run_cmd(cmd, cwd=None):
9
+ print("\n[CMD]", " ".join(cmd))
10
+ r = subprocess.run(cmd, cwd=cwd, shell=False)
11
+ if r.returncode != 0:
12
+ raise SystemExit(f"Command failed with code {r.returncode}: {' '.join(cmd)}")
13
+
14
+ def ensure_deps():
15
+ # datasets 用来下载数据;soundfile 用来更稳地处理音频;tqdm 只是打印
16
+ run_cmd([sys.executable, "-m", "pip", "install", "-U", "pip"])
17
+ run_cmd([sys.executable, "-m", "pip", "install", "-U", "datasets", "soundfile", "tqdm"])
18
+
19
+ def build_manifest_common_voice_zhcn(out_manifest: Path, num_samples: int, split: str, cache_dir: Path | None):
20
+ from datasets import load_dataset
21
+
22
+ out_manifest.parent.mkdir(parents=True, exist_ok=True)
23
+
24
+ # Common Voice 版本可能会变;这条通常最稳:直接用当前可用版本。
25
+ # 如果你发现某个版本不可用,就把这行改成你能 load 成功的版本。
26
+ dataset_name = "mozilla-foundation/common_voice_11_0"
27
+ config_name = "zh-CN"
28
+
29
+ print(f"\n[INFO] Loading dataset: {dataset_name} / {config_name} / split={split} / num={num_samples}")
30
+ ds = load_dataset(
31
+ dataset_name,
32
+ config_name,
33
+ split=f"{split}[:{num_samples}]",
34
+ cache_dir=str(cache_dir) if cache_dir else None,
35
+ trust_remote_code=False,
36
+ )
37
+
38
+ # 生成 manifest:写绝对路径,避免 Windows 相对路径找不到文件
39
+ count = 0
40
+ with out_manifest.open("w", encoding="utf-8") as f:
41
+ for i, item in enumerate(ds):
42
+ audio = item.get("audio", None)
43
+ if not audio or not audio.get("path"):
44
+ continue
45
+
46
+ audio_path = Path(audio["path"]).resolve() # 绝对路径
47
+ if not audio_path.exists():
48
+ # 极少数情况下 path 可能还没落盘;跳过
49
+ continue
50
+
51
+ ref = item.get("sentence") or item.get("text") or ""
52
+ if not ref.strip():
53
+ continue
54
+
55
+ record = {
56
+ "utt_id": f"cv_zhcn_{i}",
57
+ "audio_uri": str(audio_path),
58
+ "ref_text": ref,
59
+ "meta": {
60
+ "dataset": dataset_name,
61
+ "config": config_name,
62
+ "split": split,
63
+ "speaker": item.get("client_id"),
64
+ "gender": item.get("gender"),
65
+ "accent": item.get("accent"),
66
+ "age": item.get("age"),
67
+ "sample_rate": audio.get("sampling_rate"),
68
+ },
69
+ }
70
+ f.write(json.dumps(record, ensure_ascii=False) + "\n")
71
+ count += 1
72
+
73
+ if count == 0:
74
+ raise SystemExit("No samples written to manifest. Try another split (e.g., 'train') or increase num_samples.")
75
+
76
+ print(f"[OK] Manifest written: {out_manifest} (samples={count})")
77
+
78
+ def main():
79
+ ap = argparse.ArgumentParser()
80
+ ap.add_argument("--num", type=int, default=20, help="Number of samples to download (default: 20)")
81
+ ap.add_argument("--split", type=str, default="validation", help="Dataset split: train/validation/test (default: validation)")
82
+ ap.add_argument("--model_name", type=str, default="small", help="Whisper model size for faster-whisper (default: small)")
83
+ ap.add_argument("--device", type=str, default="cpu", help="cpu or cuda (default: cpu)")
84
+ ap.add_argument("--compute_type", type=str, default="int8", help="int8/float16/float32 etc. (default: int8)")
85
+ ap.add_argument("--cache_dir", type=str, default="", help="Optional HF datasets cache dir")
86
+ ap.add_argument("--skip_deps", action="store_true", help="Skip installing datasets/soundfile")
87
+ args = ap.parse_args()
88
+
89
+ project_root = Path(__file__).resolve().parents[1]
90
+ os.chdir(project_root)
91
+
92
+ if not args.skip_deps:
93
+ ensure_deps()
94
+
95
+ cache_dir = Path(args.cache_dir).resolve() if args.cache_dir else None
96
+ manifest_path = project_root / "data" / "manifest.jsonl"
97
+
98
+ build_manifest_common_voice_zhcn(
99
+ out_manifest=manifest_path,
100
+ num_samples=args.num,
101
+ split=args.split,
102
+ cache_dir=cache_dir,
103
+ )
104
+
105
+ # 调用你现有的 pipeline:相当于执行
106
+ # python -m pipeline.run_all --manifest data/manifest.jsonl --model_name ... --device ... --compute_type ...
107
+ run_cmd([
108
+ sys.executable, "-m", "pipeline.run_all",
109
+ "--manifest", str(manifest_path),
110
+ "--model_name", args.model_name,
111
+ "--device", args.device,
112
+ "--compute_type", args.compute_type,
113
+ ], cwd=str(project_root))
114
+
115
+ print("\n[DONE] Pipeline finished.")
116
+ print("You can now run UI:")
117
+ print(f" {sys.executable} -m ui.app")
118
+
119
+ if __name__ == "__main__":
120
+ main()
ui/app.py CHANGED
@@ -85,4 +85,3 @@ with gr.Blocks() as demo:
85
  run_dd.change(on_select_run, inputs=[run_dd], outputs=[summary_md, align_tbl, events_tbl])
86
  btn.click(search_events, inputs=[run_dd, error_cls, contains], outputs=[result_tbl])
87
 
88
- demo.launch()
 
85
  run_dd.change(on_select_run, inputs=[run_dd], outputs=[summary_md, align_tbl, events_tbl])
86
  btn.click(search_events, inputs=[run_dd, error_cls, contains], outputs=[result_tbl])
87