Spaces:
Running
on
Zero
Running
on
Zero
tomxxie
commited on
Commit
·
dd9bb13
1
Parent(s):
d9ae2cb
新增链接
Browse files- app.py +58 -26
- app_old.py +58 -26
app.py
CHANGED
@@ -158,11 +158,35 @@ def download_audio(input_wav_path):
|
|
158 |
else:
|
159 |
return None
|
160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
# 创建 Gradio 界面
|
162 |
-
with gr.Blocks() as demo:
|
163 |
# 添加标题
|
164 |
gr.Markdown(
|
165 |
-
|
166 |
<div style="display: flex; align-items: center; justify-content: center; text-align: center;">
|
167 |
<h1 style="font-family: 'Arial', sans-serif; color: #014377; font-size: 32px; margin-bottom: 0; display: inline-block; vertical-align: middle;">
|
168 |
OSUM Speech Understanding Model Test
|
@@ -175,17 +199,17 @@ with gr.Blocks() as demo:
|
|
175 |
with gr.Row():
|
176 |
with gr.Column(scale=1):
|
177 |
audio_input = gr.Audio(label="Record", type="filepath")
|
178 |
-
with gr.Column(scale=1, min_width=300):
|
179 |
output_text = gr.Textbox(label="Output", lines=8, placeholder="The generated result will be displayed here...", interactive=False)
|
180 |
|
181 |
# 添加任务选择和自定义输入框
|
182 |
with gr.Row():
|
183 |
task_dropdown = gr.Dropdown(
|
184 |
label="Task",
|
185 |
-
choices=list(TASK_PROMPT_MAPPING.keys()) + ["Custom Task Prompt"],
|
186 |
value="ASR (Automatic Speech Recognition)"
|
187 |
)
|
188 |
-
custom_prompt_input = gr.Textbox(label="Custom Task Prompt", placeholder="Please enter a custom task prompt...", visible=False)
|
189 |
|
190 |
# 添加按钮(下载按钮在左边,开始处理按钮在右边)
|
191 |
with gr.Row():
|
@@ -205,20 +229,24 @@ with gr.Blocks() as demo:
|
|
205 |
save_button = gr.Button("Submit Feedback", variant="secondary")
|
206 |
|
207 |
# 添加底部内容
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
|
|
|
|
|
|
|
|
222 |
|
223 |
# 绑定事件
|
224 |
def show_confirmation(output_res, input_wav_path, input_prompt):
|
@@ -229,12 +257,16 @@ with gr.Blocks() as demo:
|
|
229 |
return gr.update(visible=False)
|
230 |
|
231 |
def handle_submit(input_wav_path, task_choice, custom_prompt):
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
|
|
|
|
|
|
|
|
238 |
|
239 |
# 当任务选择框的值发生变化时,更新自定义输入框的可见性
|
240 |
task_dropdown.change(
|
@@ -256,7 +288,7 @@ with gr.Blocks() as demo:
|
|
256 |
download_button.click(
|
257 |
fn=download_audio,
|
258 |
inputs=[audio_input],
|
259 |
-
outputs=[download_button]
|
260 |
)
|
261 |
|
262 |
save_button.click(
|
|
|
158 |
else:
|
159 |
return None
|
160 |
|
161 |
+
# 自定义 CSS 样式
|
162 |
+
CSS = """
|
163 |
+
.custom-footer {
|
164 |
+
position: fixed;
|
165 |
+
bottom: 20px; /* 距离页面底部的距离 */
|
166 |
+
left: 50%;
|
167 |
+
transform: translateX(-50%);
|
168 |
+
display: flex;
|
169 |
+
align-items: center;
|
170 |
+
justify-content: center;
|
171 |
+
gap: 20px;
|
172 |
+
text-align: center;
|
173 |
+
font-weight: bold;
|
174 |
+
padding-bottom: 20px; /* 在底部添加额外的间距 */
|
175 |
+
}
|
176 |
+
.custom-footer p {
|
177 |
+
margin: 0;
|
178 |
+
}
|
179 |
+
.custom-footer img {
|
180 |
+
height: 80px;
|
181 |
+
width: auto;
|
182 |
+
}
|
183 |
+
"""
|
184 |
+
|
185 |
# 创建 Gradio 界面
|
186 |
+
with gr.Blocks(css=CSS) as demo:
|
187 |
# 添加标题
|
188 |
gr.Markdown(
|
189 |
+
"""
|
190 |
<div style="display: flex; align-items: center; justify-content: center; text-align: center;">
|
191 |
<h1 style="font-family: 'Arial', sans-serif; color: #014377; font-size: 32px; margin-bottom: 0; display: inline-block; vertical-align: middle;">
|
192 |
OSUM Speech Understanding Model Test
|
|
|
199 |
with gr.Row():
|
200 |
with gr.Column(scale=1):
|
201 |
audio_input = gr.Audio(label="Record", type="filepath")
|
202 |
+
with gr.Column(scale=1, min_width=300):
|
203 |
output_text = gr.Textbox(label="Output", lines=8, placeholder="The generated result will be displayed here...", interactive=False)
|
204 |
|
205 |
# 添加任务选择和自定义输入框
|
206 |
with gr.Row():
|
207 |
task_dropdown = gr.Dropdown(
|
208 |
label="Task",
|
209 |
+
choices=list(TASK_PROMPT_MAPPING.keys()) + ["Custom Task Prompt"],
|
210 |
value="ASR (Automatic Speech Recognition)"
|
211 |
)
|
212 |
+
custom_prompt_input = gr.Textbox(label="Custom Task Prompt", placeholder="Please enter a custom task prompt...", visible=False)
|
213 |
|
214 |
# 添加按钮(下载按钮在左边,开始处理按钮在右边)
|
215 |
with gr.Row():
|
|
|
229 |
save_button = gr.Button("Submit Feedback", variant="secondary")
|
230 |
|
231 |
# 添加底部内容
|
232 |
+
gr.HTML(
|
233 |
+
f"""
|
234 |
+
<div class="custom-footer">
|
235 |
+
<div>
|
236 |
+
<p>
|
237 |
+
<a href="http://www.nwpu-aslp.org/" target="_blank">Audio, Speech and Language Processing Group (ASLP@NPU)</a>,
|
238 |
+
</p>
|
239 |
+
<p>
|
240 |
+
Northwestern Polytechnical University
|
241 |
+
</p>
|
242 |
+
<p>
|
243 |
+
<a href="https://github.com/ASLP-lab/OSUM" target="_blank">GitHub</a>
|
244 |
+
</p>
|
245 |
+
</div>
|
246 |
+
<img src="data:image/png;base64,{encoded_string}" alt="OSUM Logo">
|
247 |
+
</div>
|
248 |
+
"""
|
249 |
+
)
|
250 |
|
251 |
# 绑定事件
|
252 |
def show_confirmation(output_res, input_wav_path, input_prompt):
|
|
|
257 |
return gr.update(visible=False)
|
258 |
|
259 |
def handle_submit(input_wav_path, task_choice, custom_prompt):
|
260 |
+
try:
|
261 |
+
if task_choice == "Custom Task Prompt":
|
262 |
+
input_prompt = custom_prompt
|
263 |
+
else:
|
264 |
+
input_prompt = TASK_PROMPT_MAPPING.get(task_choice, "未知任务类型")
|
265 |
+
output_res = do_decode(input_wav_path, input_prompt)
|
266 |
+
return output_res
|
267 |
+
except Exception as e:
|
268 |
+
print(f"Error in handle_submit: {e}")
|
269 |
+
return "Error occurred. Please check the input."
|
270 |
|
271 |
# 当任务选择框的值发生变化时,更新自定义输入框的可见性
|
272 |
task_dropdown.change(
|
|
|
288 |
download_button.click(
|
289 |
fn=download_audio,
|
290 |
inputs=[audio_input],
|
291 |
+
outputs=[download_button]
|
292 |
)
|
293 |
|
294 |
save_button.click(
|
app_old.py
CHANGED
@@ -158,11 +158,35 @@ def download_audio(input_wav_path):
|
|
158 |
else:
|
159 |
return None
|
160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
# 创建 Gradio 界面
|
162 |
-
with gr.Blocks() as demo:
|
163 |
# 添加标题
|
164 |
gr.Markdown(
|
165 |
-
|
166 |
<div style="display: flex; align-items: center; justify-content: center; text-align: center;">
|
167 |
<h1 style="font-family: 'Arial', sans-serif; color: #014377; font-size: 32px; margin-bottom: 0; display: inline-block; vertical-align: middle;">
|
168 |
OSUM Speech Understanding Model Test
|
@@ -175,17 +199,17 @@ with gr.Blocks() as demo:
|
|
175 |
with gr.Row():
|
176 |
with gr.Column(scale=1):
|
177 |
audio_input = gr.Audio(label="Record", type="filepath")
|
178 |
-
with gr.Column(scale=1, min_width=300):
|
179 |
output_text = gr.Textbox(label="Output", lines=8, placeholder="The generated result will be displayed here...", interactive=False)
|
180 |
|
181 |
# 添加任务选择和自定义输入框
|
182 |
with gr.Row():
|
183 |
task_dropdown = gr.Dropdown(
|
184 |
label="Task",
|
185 |
-
choices=list(TASK_PROMPT_MAPPING.keys()) + ["Custom Task Prompt"],
|
186 |
value="ASR (Automatic Speech Recognition)"
|
187 |
)
|
188 |
-
custom_prompt_input = gr.Textbox(label="Custom Task Prompt", placeholder="Please enter a custom task prompt...", visible=False)
|
189 |
|
190 |
# 添加按钮(下载按钮在左边,开始处理按钮在右边)
|
191 |
with gr.Row():
|
@@ -205,20 +229,24 @@ with gr.Blocks() as demo:
|
|
205 |
save_button = gr.Button("Submit Feedback", variant="secondary")
|
206 |
|
207 |
# 添加底部内容
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
|
|
|
|
|
|
|
|
222 |
|
223 |
# 绑定事件
|
224 |
def show_confirmation(output_res, input_wav_path, input_prompt):
|
@@ -229,12 +257,16 @@ with gr.Blocks() as demo:
|
|
229 |
return gr.update(visible=False)
|
230 |
|
231 |
def handle_submit(input_wav_path, task_choice, custom_prompt):
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
|
|
|
|
|
|
|
|
238 |
|
239 |
# 当任务选择框的值发生变化时,更新自定义输入框的可见性
|
240 |
task_dropdown.change(
|
@@ -256,7 +288,7 @@ with gr.Blocks() as demo:
|
|
256 |
download_button.click(
|
257 |
fn=download_audio,
|
258 |
inputs=[audio_input],
|
259 |
-
outputs=[download_button]
|
260 |
)
|
261 |
|
262 |
save_button.click(
|
|
|
158 |
else:
|
159 |
return None
|
160 |
|
161 |
+
# 自定义 CSS 样式
|
162 |
+
CSS = """
|
163 |
+
.custom-footer {
|
164 |
+
position: fixed;
|
165 |
+
bottom: 20px; /* 距离页面底部的距离 */
|
166 |
+
left: 50%;
|
167 |
+
transform: translateX(-50%);
|
168 |
+
display: flex;
|
169 |
+
align-items: center;
|
170 |
+
justify-content: center;
|
171 |
+
gap: 20px;
|
172 |
+
text-align: center;
|
173 |
+
font-weight: bold;
|
174 |
+
padding-bottom: 20px; /* 在底部添加额外的间距 */
|
175 |
+
}
|
176 |
+
.custom-footer p {
|
177 |
+
margin: 0;
|
178 |
+
}
|
179 |
+
.custom-footer img {
|
180 |
+
height: 80px;
|
181 |
+
width: auto;
|
182 |
+
}
|
183 |
+
"""
|
184 |
+
|
185 |
# 创建 Gradio 界面
|
186 |
+
with gr.Blocks(css=CSS) as demo:
|
187 |
# 添加标题
|
188 |
gr.Markdown(
|
189 |
+
"""
|
190 |
<div style="display: flex; align-items: center; justify-content: center; text-align: center;">
|
191 |
<h1 style="font-family: 'Arial', sans-serif; color: #014377; font-size: 32px; margin-bottom: 0; display: inline-block; vertical-align: middle;">
|
192 |
OSUM Speech Understanding Model Test
|
|
|
199 |
with gr.Row():
|
200 |
with gr.Column(scale=1):
|
201 |
audio_input = gr.Audio(label="Record", type="filepath")
|
202 |
+
with gr.Column(scale=1, min_width=300):
|
203 |
output_text = gr.Textbox(label="Output", lines=8, placeholder="The generated result will be displayed here...", interactive=False)
|
204 |
|
205 |
# 添加任务选择和自定义输入框
|
206 |
with gr.Row():
|
207 |
task_dropdown = gr.Dropdown(
|
208 |
label="Task",
|
209 |
+
choices=list(TASK_PROMPT_MAPPING.keys()) + ["Custom Task Prompt"],
|
210 |
value="ASR (Automatic Speech Recognition)"
|
211 |
)
|
212 |
+
custom_prompt_input = gr.Textbox(label="Custom Task Prompt", placeholder="Please enter a custom task prompt...", visible=False)
|
213 |
|
214 |
# 添加按钮(下载按钮在左边,开始处理按钮在右边)
|
215 |
with gr.Row():
|
|
|
229 |
save_button = gr.Button("Submit Feedback", variant="secondary")
|
230 |
|
231 |
# 添加底部内容
|
232 |
+
gr.HTML(
|
233 |
+
f"""
|
234 |
+
<div class="custom-footer">
|
235 |
+
<div>
|
236 |
+
<p>
|
237 |
+
<a href="http://www.nwpu-aslp.org/" target="_blank">Audio, Speech and Language Processing Group (ASLP@NPU)</a>,
|
238 |
+
</p>
|
239 |
+
<p>
|
240 |
+
Northwestern Polytechnical University
|
241 |
+
</p>
|
242 |
+
<p>
|
243 |
+
<a href="https://github.com/ASLP-lab/OSUM" target="_blank">GitHub</a>
|
244 |
+
</p>
|
245 |
+
</div>
|
246 |
+
<img src="data:image/png;base64,{encoded_string}" alt="OSUM Logo">
|
247 |
+
</div>
|
248 |
+
"""
|
249 |
+
)
|
250 |
|
251 |
# 绑定事件
|
252 |
def show_confirmation(output_res, input_wav_path, input_prompt):
|
|
|
257 |
return gr.update(visible=False)
|
258 |
|
259 |
def handle_submit(input_wav_path, task_choice, custom_prompt):
|
260 |
+
try:
|
261 |
+
if task_choice == "Custom Task Prompt":
|
262 |
+
input_prompt = custom_prompt
|
263 |
+
else:
|
264 |
+
input_prompt = TASK_PROMPT_MAPPING.get(task_choice, "未知任务类型")
|
265 |
+
output_res = do_decode(input_wav_path, input_prompt)
|
266 |
+
return output_res
|
267 |
+
except Exception as e:
|
268 |
+
print(f"Error in handle_submit: {e}")
|
269 |
+
return "Error occurred. Please check the input."
|
270 |
|
271 |
# 当任务选择框的值发生变化时,更新自定义输入框的可见性
|
272 |
task_dropdown.change(
|
|
|
288 |
download_button.click(
|
289 |
fn=download_audio,
|
290 |
inputs=[audio_input],
|
291 |
+
outputs=[download_button]
|
292 |
)
|
293 |
|
294 |
save_button.click(
|