Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
-
import torch
|
4 |
-
import librosa
|
5 |
|
6 |
-
#
|
7 |
-
model_name = "openai/whisper-large
|
8 |
-
|
9 |
-
model = WhisperForConditionalGeneration.from_pretrained(model_name)
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
# モデルによる文字起こし
|
23 |
-
with torch.no_grad():
|
24 |
-
predicted_ids = model.generate(input_features=input_features)
|
25 |
-
|
26 |
-
# 文字起こし結果のデコード
|
27 |
-
transcription = processor.decode(predicted_ids[0], skip_special_tokens=True)
|
28 |
-
|
29 |
-
return transcription
|
30 |
-
|
31 |
-
# Gradioのインターフェース作成
|
32 |
-
interface = gr.Interface(
|
33 |
-
fn=transcribe_audio,
|
34 |
-
inputs=gr.Audio(type="filepath"), # マイクやファイルから音声を入力
|
35 |
-
outputs="text",
|
36 |
-
live=True
|
37 |
-
)
|
38 |
-
|
39 |
-
# インターフェースの起動
|
40 |
-
interface.launch(share=True)
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
|
|
|
|
3 |
|
4 |
+
# Whisperモデルを読み込み
|
5 |
+
model_name = "openai/whisper-small" # 他のサイズも使用可能(tiny, base, largeなど)
|
6 |
+
transcriber = pipeline("automatic-speech-recognition", model=model_name)
|
|
|
7 |
|
8 |
+
def transcribe(audio):
|
9 |
+
"""
|
10 |
+
音声ファイルを文字起こしする関数
|
11 |
+
"""
|
12 |
+
result = transcriber(audio)
|
13 |
+
return result["text"]
|
14 |
|
15 |
+
# Gradioインターフェース
|
16 |
+
with gr.Blocks() as demo:
|
17 |
+
gr.Markdown("### 音声文字起こしデモ")
|
18 |
+
audio_input = gr.Audio(source="upload", type="filepath", label="音声ファイルをアップロード")
|
19 |
+
text_output = gr.Textbox(label="文字起こし結果")
|
20 |
+
transcribe_button = gr.Button("文字起こし")
|
21 |
+
transcribe_button.click(transcribe, inputs=audio_input, outputs=text_output)
|
22 |
|
23 |
+
# アプリケーションを起動
|
24 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|