machinelearnAn commited on
Commit
4d6dff0
·
verified ·
1 Parent(s): 50a6ac5

Upload 4 files

Browse files
Files changed (4) hide show
  1. README.md +17 -8
  2. app.py +59 -0
  3. packages.txt +1 -0
  4. requirements.txt +3 -0
README.md CHANGED
@@ -1,14 +1,23 @@
1
  ---
2
- title: NihongoMiniteto
3
- emoji: 🐢
4
  colorFrom: pink
5
  colorTo: purple
6
  sdk: gradio
7
- sdk_version: 5.44.1
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- short_description: Trick on choukai test
12
  ---
13
 
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: JP Audio → Text (Upload Only)
3
+ emoji: 🗾
4
  colorFrom: pink
5
  colorTo: purple
6
  sdk: gradio
7
+ python_version: "3.10"
8
+ suggested_hardware: "a10g-small"
 
 
 
9
  ---
10
 
11
+ **日本語音声(最大2分)をアップロードしてテキスト化**する最小構成のSpaceです。
12
+ - モデル: `faster-whisper`(デフォルトは `Systran/faster-whisper-small`)
13
+ - 言語は固定で **日本語** に設定(`language="ja"`)
14
+ - マイク録音UIは無効。**アップロードのみ**。
15
+
16
+ ### 環境変数(任意)
17
+ - `MODEL_NAME` … 例: `Systran/faster-whisper-small`, `large-v3`, `distil-large-v3`
18
+ - `VAD_FILTER` … `"1"`(既定)/ `"0"`
19
+ - `MAX_SECONDS` … 既定: `120`
20
+
21
+ ### 注意
22
+ - ハードウェアは CPU でも動作しますが、GPU のほうが高速です(Settings → Hardware)。
23
+ - `packages.txt` で `ffmpeg` をインストールしています。
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from faster_whisper import WhisperModel
4
+ import soundfile as sf
5
+
6
+ # Fixed config for this app
7
+ MODEL_NAME = os.getenv("MODEL_NAME", "Systran/faster-whisper-small") # fast & accurate enough for short clips
8
+ LANGUAGE = "ja" # force Japanese
9
+ VAD = os.getenv("VAD_FILTER", "1") == "1"
10
+ MAX_SECONDS = int(os.getenv("MAX_SECONDS", "120")) # 2 minutes
11
+
12
+ _model = None
13
+
14
+ def get_model():
15
+ global _model
16
+ if _model is not None:
17
+ return _model
18
+ # GPU first, then CPU fallbacks
19
+ for device, compute_type in [("cuda", "float16"), ("cuda", "int8_float16"), ("cpu", "int8")]:
20
+ try:
21
+ m = WhisperModel(MODEL_NAME, device=device, compute_type=compute_type)
22
+ _model = m
23
+ print(f"[load] {MODEL_NAME} on {device}/{compute_type}")
24
+ return _model
25
+ except Exception as e:
26
+ print(f"[load-failed] {device}/{compute_type}: {e}")
27
+ continue
28
+ raise RuntimeError("Unable to load model.")
29
+
30
+ def transcribe_upload(audio_path):
31
+ if not audio_path:
32
+ return "ファイルが選択されていません。"
33
+
34
+ # duration guard
35
+ try:
36
+ data, sr = sf.read(audio_path)
37
+ duration = len(data) / float(sr)
38
+ if duration > MAX_SECONDS:
39
+ return f"音声が長すぎます({duration:.1f}秒)。最大{MAX_SECONDS}秒のファイルのみ対応しています。"
40
+ except Exception as e:
41
+ print(f"[warn] duration check failed: {e}")
42
+
43
+ model = get_model()
44
+ segments, info = model.transcribe(
45
+ audio_path,
46
+ language=LANGUAGE, # 固定: 日本語
47
+ task="transcribe",
48
+ vad_filter=VAD,
49
+ )
50
+ text = "".join(seg.text for seg in segments)
51
+ return text.strip()
52
+
53
+ with gr.Blocks() as demo:
54
+ gr.Markdown("# 🇯🇵 日本語 音声→テキスト(アップロードのみ)\n- 日本語の音声ファイル(最大2分)をアップロードしてください。\n- 変換後のテキストが下に表示されます。")
55
+ audio = gr.Audio(sources=["upload"], type="filepath", label="音声ファイルをアップロード(<2分)")
56
+ out = gr.Textbox(lines=8, label="テキスト")
57
+ gr.Button("文字起こし").click(transcribe_upload, inputs=[audio], outputs=[out])
58
+
59
+ demo.queue(concurrency_count=2).launch()
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ffmpeg
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ faster-whisper>=1.1.0
2
+ gradio>=4.40.0
3
+ soundfile