Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,50 +1,50 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from funasr import AutoModel
|
| 3 |
-
import torch
|
| 4 |
-
|
| 5 |
-
model_name = "iic/
|
| 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()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from funasr import AutoModel
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
model_name = "iic/SenseVoiceSmall"
|
| 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()
|