Spaces:
Runtime error
Runtime error
Change generate_kwargs
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import time
|
|
|
|
| 3 |
from pathlib import Path
|
| 4 |
|
| 5 |
import gradio as gr
|
|
@@ -9,13 +10,16 @@ import torch
|
|
| 9 |
from loguru import logger
|
| 10 |
from transformers import pipeline
|
| 11 |
|
|
|
|
|
|
|
| 12 |
is_hf = os.getenv("SYSTEM") == "spaces"
|
| 13 |
|
| 14 |
generate_kwargs = {
|
| 15 |
"language": "Japanese",
|
| 16 |
-
"do_sample": False,
|
| 17 |
-
"num_beams": 1,
|
| 18 |
-
"no_repeat_ngram_size": 3,
|
|
|
|
| 19 |
}
|
| 20 |
|
| 21 |
|
|
@@ -46,6 +50,8 @@ logger.success("Pipelines initialized!")
|
|
| 46 |
|
| 47 |
@spaces.GPU
|
| 48 |
def transcribe_common(audio: str, model: str) -> tuple[str, float]:
|
|
|
|
|
|
|
| 49 |
filename = Path(audio).name
|
| 50 |
logger.info(f"Model: {model}")
|
| 51 |
logger.info(f"Audio: {filename}")
|
|
@@ -55,7 +61,8 @@ def transcribe_common(audio: str, model: str) -> tuple[str, float]:
|
|
| 55 |
duration = librosa.get_duration(y=y, sr=sr)
|
| 56 |
logger.info(f"Duration: {duration:.2f}s")
|
| 57 |
if duration > 15:
|
| 58 |
-
|
|
|
|
| 59 |
start_time = time.time()
|
| 60 |
result = pipe_dict[model](y, generate_kwargs=generate_kwargs)["text"]
|
| 61 |
end_time = time.time()
|
|
@@ -97,18 +104,16 @@ initial_md = """
|
|
| 97 |
|
| 98 |
- 音声認識モデル [kotoba-whisper-v2.0](https://huggingface.co/kotoba-tech/kotoba-whisper-v2.0) をファインチューンした**未完成のモデル**のお試し
|
| 99 |
- https://huggingface.co/litagin/galgame-whisper-wip
|
|
|
|
|
|
|
| 100 |
- 現在0.1エポックくらい
|
| 101 |
-
- 日本語のみ対応
|
| 102 |
-
- デモでは音声は15秒まで
|
| 103 |
- 比較できるように他モデルもついでに試せる
|
| 104 |
|
| 105 |
-
pipeに渡しているkwargs
|
| 106 |
```python
|
| 107 |
generate_kwargs = {
|
| 108 |
"language": "Japanese",
|
| 109 |
-
"
|
| 110 |
-
"num_beams": 1,
|
| 111 |
-
"no_repeat_ngram_size": 3, # 3回以上の繰り返しを防ぐ
|
| 112 |
}
|
| 113 |
```
|
| 114 |
"""
|
|
|
|
| 1 |
import os
|
| 2 |
import time
|
| 3 |
+
import warnings
|
| 4 |
from pathlib import Path
|
| 5 |
|
| 6 |
import gradio as gr
|
|
|
|
| 10 |
from loguru import logger
|
| 11 |
from transformers import pipeline
|
| 12 |
|
| 13 |
+
warnings.filterwarnings("ignore")
|
| 14 |
+
|
| 15 |
is_hf = os.getenv("SYSTEM") == "spaces"
|
| 16 |
|
| 17 |
generate_kwargs = {
|
| 18 |
"language": "Japanese",
|
| 19 |
+
# "do_sample": False,
|
| 20 |
+
# "num_beams": 1,
|
| 21 |
+
# "no_repeat_ngram_size": 3,
|
| 22 |
+
"max_new_tokens": 64,
|
| 23 |
}
|
| 24 |
|
| 25 |
|
|
|
|
| 50 |
|
| 51 |
@spaces.GPU
|
| 52 |
def transcribe_common(audio: str, model: str) -> tuple[str, float]:
|
| 53 |
+
if not audio:
|
| 54 |
+
return "No audio file", 0
|
| 55 |
filename = Path(audio).name
|
| 56 |
logger.info(f"Model: {model}")
|
| 57 |
logger.info(f"Audio: {filename}")
|
|
|
|
| 61 |
duration = librosa.get_duration(y=y, sr=sr)
|
| 62 |
logger.info(f"Duration: {duration:.2f}s")
|
| 63 |
if duration > 15:
|
| 64 |
+
logger.error(f"Audio too long, limit is 15 seconds, got {duration:.2f}s")
|
| 65 |
+
return f"Audio too long, limit is 15 seconds, got {duration:.2f}s", 0
|
| 66 |
start_time = time.time()
|
| 67 |
result = pipe_dict[model](y, generate_kwargs=generate_kwargs)["text"]
|
| 68 |
end_time = time.time()
|
|
|
|
| 104 |
|
| 105 |
- 音声認識モデル [kotoba-whisper-v2.0](https://huggingface.co/kotoba-tech/kotoba-whisper-v2.0) をファインチューンした**未完成のモデル**のお試し
|
| 106 |
- https://huggingface.co/litagin/galgame-whisper-wip
|
| 107 |
+
- デモでは**音声は15秒まで**しか受け付けません
|
| 108 |
+
- 日本語のみ対応 (Japanese only)
|
| 109 |
- 現在0.1エポックくらい
|
|
|
|
|
|
|
| 110 |
- 比較できるように他モデルもついでに試せる
|
| 111 |
|
| 112 |
+
pipeに渡しているkwargsは以下の最低限のもの:
|
| 113 |
```python
|
| 114 |
generate_kwargs = {
|
| 115 |
"language": "Japanese",
|
| 116 |
+
"max_new_tokens": 64,
|
|
|
|
|
|
|
| 117 |
}
|
| 118 |
```
|
| 119 |
"""
|