Spaces:
Running
Running
Update app.py
Browse filesClean app using pipeline only
app.py
CHANGED
@@ -1,45 +1,23 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
#
|
5 |
asr = pipeline("automatic-speech-recognition", model="openai/whisper-base")
|
6 |
|
7 |
-
#
|
8 |
-
llm = pipeline("text-generation", model="mrm8488/t5-base-finetuned-question-generation-ap", max_new_tokens=100)
|
9 |
-
|
10 |
-
# Xử lý âm thanh: Nhận dạng giọng nói
|
11 |
def transcribe(audio_file):
|
12 |
if audio_file is None:
|
13 |
-
return "
|
14 |
result = asr(audio_file)
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
# Gradio UI
|
26 |
-
with gr.Blocks() as demo:
|
27 |
-
gr.Markdown("# Voice Assistant Demo")
|
28 |
-
gr.Markdown("### Gửi file âm thanh để nhận diện giọng nói bằng Whisper")
|
29 |
-
|
30 |
-
with gr.Row():
|
31 |
-
audio_input = gr.Audio(label="Chọn file âm thanh", type="filepath")
|
32 |
-
btn_transcribe = gr.Button("Nhận diện giọng nói")
|
33 |
-
|
34 |
-
transcript_output = gr.Textbox(label="Kết quả nhận diện")
|
35 |
-
|
36 |
-
btn_transcribe.click(fn=transcribe, inputs=audio_input, outputs=transcript_output)
|
37 |
-
|
38 |
-
gr.Markdown("### Gửi văn bản vào mô hình LLM")
|
39 |
-
llm_input = gr.Textbox(label="Văn bản đầu vào")
|
40 |
-
btn_llm = gr.Button("Gửi vào LLM")
|
41 |
-
llm_output = gr.Textbox(label="Kết quả LLM")
|
42 |
-
|
43 |
-
btn_llm.click(fn=ask_llm, inputs=llm_input, outputs=llm_output)
|
44 |
|
45 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Tạo pipeline nhận diện giọng nói
|
5 |
asr = pipeline("automatic-speech-recognition", model="openai/whisper-base")
|
6 |
|
7 |
+
# Hàm xử lý âm thanh
|
|
|
|
|
|
|
8 |
def transcribe(audio_file):
|
9 |
if audio_file is None:
|
10 |
+
return "Chưa có file âm thanh."
|
11 |
result = asr(audio_file)
|
12 |
+
return result["text"]
|
13 |
+
|
14 |
+
# Tạo giao diện
|
15 |
+
demo = gr.Interface(
|
16 |
+
fn=transcribe,
|
17 |
+
inputs=gr.Audio(source="upload", type="filepath", label="Tải lên file âm thanh (.wav, .mp3...)"),
|
18 |
+
outputs=gr.Textbox(label="Kết quả chuyển văn bản"),
|
19 |
+
title="Nhận diện giọng nói bằng Whisper",
|
20 |
+
description="Tải file âm thanh và hệ thống sẽ nhận diện nội dung giọng nói bằng mô hình Whisper của OpenAI."
|
21 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
demo.launch()
|