Choultion-Rudas commited on
Commit
02fb9d5
·
verified ·
1 Parent(s): 54a0094

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +50 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from funasr import AutoModel
3
+ import torch
4
+
5
+ model_name = "iic/SenseVoice"
6
+
7
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
8
+
9
+ try:
10
+ model = AutoModel(
11
+ model=model_name,
12
+ vad_model="fsmn-vad",
13
+ vad_kwargs={"max_single_segment_time": 30000},
14
+ device=device,
15
+ )
16
+ model_loaded_successfully = True
17
+ except Exception:
18
+ model = None
19
+ model_loaded_successfully = False
20
+
21
+
22
+ def transcribe_audio(audio_file_path):
23
+ if not model_loaded_successfully:
24
+ return "模型加载失败。很可能是免费硬件的内存不足,请按教程切换到 'iic/SenseVoiceSmall' 模型。"
25
+
26
+ if audio_file_path is None:
27
+ return "错误:请上传或录制音频。"
28
+
29
+ res = model.generate(
30
+ input=audio_file_path,
31
+ batch_size_s=60,
32
+ language="auto",
33
+ use_itn=True,
34
+ )
35
+
36
+ return res[0]["text"]
37
+
38
+
39
+ iface = gr.Interface(
40
+ fn=transcribe_audio,
41
+ inputs=gr.Audio(
42
+ sources=["upload", "microphone"], type="filepath", label="上传音频或录音"
43
+ ),
44
+ outputs=gr.Textbox(label="识别结果"),
45
+ title="SenseVoice 在线体验版",
46
+ description="应用启动时需要下载和加载模型,请耐心等待。",
47
+ allow_flagging="never",
48
+ )
49
+
50
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ funasr
2
+ modelscope
3
+ torch
4
+ torchaudio
5
+ gradio