dmcartor commited on
Commit
bd771cb
·
verified ·
1 Parent(s): 4edff3f

Update app with ASR elements

Browse files

Add transformer pipeline with Whisper large v3 to perform ASR elements, and added an ASR interface to provide audio inputs.

Files changed (1) hide show
  1. app.py +22 -9
app.py CHANGED
@@ -1,12 +1,19 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
2
  from huggingface_hub import InferenceClient
3
 
4
- """
5
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
- """
7
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
9
-
10
  def respond(
11
  message,
12
  history: list[tuple[str, str]],
@@ -39,10 +46,10 @@ def respond(
39
  response += token
40
  yield response
41
 
42
- """
43
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
44
- """
45
- demo = gr.ChatInterface(
46
  respond,
47
  additional_inputs=[
48
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
@@ -58,6 +65,12 @@ demo = gr.ChatInterface(
58
  ],
59
  )
60
 
 
 
 
 
 
 
61
 
62
  if __name__ == "__main__":
63
- demo.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Use a pipeline as a high-level helper for automatic speech recognition
5
+ pipe = pipeline("automatic-speech-recognition", model="openai/whisper-large-v3")
6
+
7
+ # Define the function for ASR
8
+ def transcribe(file):
9
+ result = pipe(file)["text"]
10
+ return result
11
+
12
+ # Retain the ChatInterface setup from the existing app.py
13
  from huggingface_hub import InferenceClient
14
 
 
 
 
15
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
16
 
 
17
  def respond(
18
  message,
19
  history: list[tuple[str, str]],
 
46
  response += token
47
  yield response
48
 
49
+ # Create two separate Gradio interfaces
50
+ asr_interface = gr.Interface(fn=transcribe, inputs="file", outputs="text", title="ASR Transcription", description="Upload an audio file and get the transcription.")
51
+
52
+ chat_interface = gr.ChatInterface(
53
  respond,
54
  additional_inputs=[
55
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
 
65
  ],
66
  )
67
 
68
+ # Combine the two interfaces into a single Gradio Blocks application
69
+ with gr.Blocks() as demo:
70
+ gr.Markdown("# ASR and Chatbot Application")
71
+ asr_interface.render()
72
+ gr.Markdown("----")
73
+ chat_interface.render()
74
 
75
  if __name__ == "__main__":
76
+ demo.launch()