wang0507 commited on
Commit
6f40988
·
1 Parent(s): c6ec7e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -14
app.py CHANGED
@@ -1,34 +1,36 @@
1
- import os
2
- os.system("pip install git+https://github.com/openai/whisper.git")
3
  import gradio as gr
4
  import whisper
5
-
6
-
7
 
8
  model = whisper.load_model("large")
9
 
10
 
11
-
12
  def inference(audio):
13
  audio = whisper.load_audio(audio)
14
  audio = whisper.pad_or_trim(audio)
15
-
16
  mel = whisper.log_mel_spectrogram(audio).to(model.device)
17
-
18
  _, probs = model.detect_language(mel)
19
-
20
- options = whisper.DecodingOptions(fp16 = False)
21
  result = whisper.decode(model, mel, options)
22
-
23
  print(result.text)
24
- return result.text, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
25
-
 
 
26
  iface = gr.Interface(
27
  fn=inference,
28
  inputs=gr.Audio(type="filepath", label="上传音频文件 (.mp3, .wav等)"),
29
  outputs="text"
30
  )
31
 
32
- # 启动 Gradio 界面
33
- iface.launch()
 
 
 
 
34
 
 
 
 
1
  import gradio as gr
2
  import whisper
3
+ import soundfile as sf
 
4
 
5
  model = whisper.load_model("large")
6
 
7
 
 
8
  def inference(audio):
9
  audio = whisper.load_audio(audio)
10
  audio = whisper.pad_or_trim(audio)
11
+
12
  mel = whisper.log_mel_spectrogram(audio).to(model.device)
13
+
14
  _, probs = model.detect_language(mel)
15
+
16
+ options = whisper.DecodingOptions(fp16=False)
17
  result = whisper.decode(model, mel, options)
18
+
19
  print(result.text)
20
+
21
+ return result.text
22
+
23
+
24
  iface = gr.Interface(
25
  fn=inference,
26
  inputs=gr.Audio(type="filepath", label="上传音频文件 (.mp3, .wav等)"),
27
  outputs="text"
28
  )
29
 
30
+ # 启动 Gradio 界面并获取永久链接
31
+ share_link = iface.share()
32
+
33
+ # 打印永久链接
34
+ print(f"Gradio Interface URL: {share_link}")
35
+
36