Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -149,21 +149,19 @@ def model_inference(
|
|
| 149 |
|
| 150 |
|
| 151 |
html_intro = """
|
| 152 |
-
<div>
|
| 153 |
-
<
|
| 154 |
-
<p
|
| 155 |
-
|
| 156 |
-
<h2 style="font-size: 22px;margin-left: 0px;">用法</h2> <p style="font-size: 18px;margin-left: 20px;">上传音频文件或通过麦克风输入,然后选择任务和语言。音频被转录成相应的文本以及相关的情绪(😊快乐,😡愤怒/兴奋,😔悲伤)和声音事件类型(😀笑声,🎼音乐,👏掌声,🤧咳嗽和打喷嚏,😔哭泣)。事件标签放在文本的前面,情感放在文本的后面。</p>
|
| 157 |
-
<h2 style="font-size: 22px;margin-left: 0px;">目录</h2>
|
| 158 |
-
<p style="font-size: 18px;margin-left: 20px;"><a href="https://github.com/FunAudioLLM/SenseVoice" target="_blank">SenseVoice</a>:多语言语音理解模型</p>
|
| 159 |
-
<p style="font-size: 18px;margin-left: 20px;"><a href="https://github.com/modelscope/FunASR" target="_blank">FunASR</a>:基本语音识别工具包</p>
|
| 160 |
-
<p style="font-size: 18px;margin-left: 20px;"><a href="https://github.com/FunAudioLLM/CosyVoice" target="_blank">CosyVoice</a>:高质量多语言TTS模型</p>
|
| 161 |
-
</div>
|
| 162 |
-
<div style="text-align: center; font-size: 15px; font-weight: bold; color: red; margin-bottom: 20px;">
|
| 163 |
-
⚠️ 该演示仅供学术研究和体验使用。
|
| 164 |
</div>
|
| 165 |
"""
|
| 166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
lang_options = [
|
| 168 |
("自动检测", "auto"),
|
| 169 |
("中文", "zh"),
|
|
@@ -173,55 +171,30 @@ lang_options = [
|
|
| 173 |
("한국어", "ko"),
|
| 174 |
("无语音", "nospeech"),
|
| 175 |
]
|
| 176 |
-
example_list = [
|
| 177 |
-
[f"{model.model_path}/example/zh.mp3", "auto"],
|
| 178 |
-
[f"{model.model_path}/example/en.mp3", "auto"],
|
| 179 |
-
[f"{model.model_path}/example/yue.mp3", "auto"],
|
| 180 |
-
[f"{model.model_path}/example/ja.mp3", "auto"],
|
| 181 |
-
[f"{model.model_path}/example/ko.mp3", "auto"],
|
| 182 |
-
[f"{model.model_path}/example/rich_1.wav", "auto"],
|
| 183 |
-
[f"{model.model_path}/example/rich_2.wav", "auto"],
|
| 184 |
-
[f"{model.model_path}/example/longwav_1.wav", "auto"],
|
| 185 |
-
]
|
| 186 |
|
| 187 |
-
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 188 |
gr.HTML(html_intro)
|
| 189 |
with gr.Row():
|
| 190 |
with gr.Column(scale=2):
|
| 191 |
-
audio_inputs = gr.Audio(label="上传音频
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
with gr.Accordion("高级设置", open=False):
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
value="Emoji格式化",
|
| 196 |
-
label="选择输出格式",
|
| 197 |
-
)
|
| 198 |
-
language_inputs = gr.Dropdown(
|
| 199 |
-
choices=lang_options, value="auto", label="识别语言"
|
| 200 |
-
)
|
| 201 |
-
use_itn_checkbox = gr.Checkbox(
|
| 202 |
-
value=True, label="启用标点和逆文本正规化"
|
| 203 |
-
)
|
| 204 |
-
merge_vad_checkbox = gr.Checkbox(
|
| 205 |
-
value=True, label="合并VAD切分的音频片段"
|
| 206 |
-
)
|
| 207 |
merge_length_slider = gr.Slider(
|
| 208 |
-
minimum=5,
|
| 209 |
-
maximum=30,
|
| 210 |
-
value=15,
|
| 211 |
-
step=1,
|
| 212 |
-
label="合并后片段最大长度(秒)",
|
| 213 |
-
)
|
| 214 |
-
ban_emo_unk_checkbox = gr.Checkbox(
|
| 215 |
-
value=False, label="禁用未知情感标签"
|
| 216 |
)
|
|
|
|
| 217 |
fn_button = gr.Button("开始识别", variant="primary")
|
| 218 |
with gr.Column(scale=3):
|
| 219 |
text_outputs = gr.Textbox(label="识别结果", lines=20)
|
| 220 |
-
gr.Examples(
|
| 221 |
-
examples=example_list,
|
| 222 |
-
inputs=[audio_inputs, language_inputs],
|
| 223 |
-
label="示例音频 (点击即可试用)",
|
| 224 |
-
)
|
| 225 |
fn_button.click(
|
| 226 |
fn=model_inference,
|
| 227 |
inputs=[
|
|
|
|
| 149 |
|
| 150 |
|
| 151 |
html_intro = """
|
| 152 |
+
<div style="text-align: center; font-family: var(--font-sans);">
|
| 153 |
+
<h1 style="font-size: 28px;">SenseVoice-Small 语音识别</h1>
|
| 154 |
+
<p>SenseVoice 是具有音频理解能力的音频基础模型,包括语音识别(ASR)、语种识别(LID)、语音情感识别(SER)和声学事件分类(AEC)或声学事件检测(AED)。</p>
|
| 155 |
+
<p style="font-size: small; color: #888;">支持 MP3, WAV, FLAC, M4A 等常见音频格式。</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
</div>
|
| 157 |
"""
|
| 158 |
|
| 159 |
+
custom_css = """
|
| 160 |
+
body, .gradio-container {
|
| 161 |
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
| 162 |
+
}
|
| 163 |
+
"""
|
| 164 |
+
|
| 165 |
lang_options = [
|
| 166 |
("自动检测", "auto"),
|
| 167 |
("中文", "zh"),
|
|
|
|
| 171 |
("한국어", "ko"),
|
| 172 |
("无语音", "nospeech"),
|
| 173 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
|
| 176 |
gr.HTML(html_intro)
|
| 177 |
with gr.Row():
|
| 178 |
with gr.Column(scale=2):
|
| 179 |
+
audio_inputs = gr.Audio(label="上传/录制音频")
|
| 180 |
+
language_inputs = gr.Dropdown(
|
| 181 |
+
choices=lang_options, value="auto", label="源语言"
|
| 182 |
+
)
|
| 183 |
+
output_format_dropdown = gr.Dropdown(
|
| 184 |
+
choices=["纯净文本", "原始富文本", "Emoji 格式"],
|
| 185 |
+
value="纯净文本",
|
| 186 |
+
label="输出格式",
|
| 187 |
+
)
|
| 188 |
with gr.Accordion("高级设置", open=False):
|
| 189 |
+
use_itn_checkbox = gr.Checkbox(value=True, label="自动添加标点与格式化")
|
| 190 |
+
merge_vad_checkbox = gr.Checkbox(value=True, label="优化长音频断句")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
merge_length_slider = gr.Slider(
|
| 192 |
+
minimum=5, maximum=30, value=15, step=1, label="断句最大长度(秒)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
)
|
| 194 |
+
ban_emo_unk_checkbox = gr.Checkbox(value=False, label="强制情感分类")
|
| 195 |
fn_button = gr.Button("开始识别", variant="primary")
|
| 196 |
with gr.Column(scale=3):
|
| 197 |
text_outputs = gr.Textbox(label="识别结果", lines=20)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
fn_button.click(
|
| 199 |
fn=model_inference,
|
| 200 |
inputs=[
|