Update app2.py
Browse files
app2.py
CHANGED
@@ -50,4 +50,37 @@ with gr.Blocks() as demo:
|
|
50 |
|
51 |
|
52 |
demo.launch()
|
53 |
-
# 兩個頁面
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
|
52 |
demo.launch()
|
53 |
+
# 兩個頁面
|
54 |
+
|
55 |
+
# ################################################################################################################################################
|
56 |
+
import os
|
57 |
+
os.system("pip install git+https://github.com/openai/whisper.git")
|
58 |
+
import gradio as gr
|
59 |
+
import whisper
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
model = whisper.load_model("base")
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
def inference(audio):
|
68 |
+
audio = whisper.load_audio(audio)
|
69 |
+
audio = whisper.pad_or_trim(audio)
|
70 |
+
|
71 |
+
mel = whisper.log_mel_spectrogram(audio).to(model.device)
|
72 |
+
|
73 |
+
_, probs = model.detect_language(mel)
|
74 |
+
|
75 |
+
options = whisper.DecodingOptions(fp16 = False)
|
76 |
+
result = whisper.decode(model, mel, options)
|
77 |
+
|
78 |
+
return result.text
|
79 |
+
|
80 |
+
iface = gr.Interface(
|
81 |
+
fn=inference,
|
82 |
+
inputs=gr.Audio(type="filepath", label="格式可為 WAV、MP3、OGG、FLAC、AAC、M4A、WMA,單聲道、多聲道均可。"),
|
83 |
+
outputs="text"
|
84 |
+
)
|
85 |
+
|
86 |
+
iface.launch()
|