dmcartor commited on
Commit
7dfdabd
·
verified ·
1 Parent(s): 72f0206

App.py update to add recording ability

Browse files

Added the option to record audio as well as upload an audio file, and made some interface changes for improved interaction.

Files changed (1) hide show
  1. app.py +20 -3
app.py CHANGED
@@ -9,6 +9,11 @@ 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
 
@@ -46,9 +51,19 @@ def respond(
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=[
@@ -67,10 +82,12 @@ chat_interface = gr.ChatInterface(
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()
 
9
  result = pipe(file)["text"]
10
  return result
11
 
12
+ # Function to handle direct audio recording
13
+ def record_and_transcribe(audio):
14
+ result = pipe(audio)["text"]
15
+ return result
16
+
17
  # Retain the ChatInterface setup from the existing app.py
18
  from huggingface_hub import InferenceClient
19
 
 
51
  response += token
52
  yield response
53
 
54
+ # Create the ASR interface with a label and functionality for both file upload and direct recording
55
+ asr_interface = gr.Interface(
56
+ fn=transcribe,
57
+ inputs=[
58
+ gr.File(label="Upload an audio file"),
59
+ gr.Audio(source="microphone", type="filepath", label="Record audio directly")
60
+ ],
61
+ outputs="text",
62
+ title="ASR Transcription",
63
+ description="Upload an audio file or record audio directly and get the transcription."
64
+ )
65
 
66
+ # Retain the ChatInterface setup from the existing app.py
67
  chat_interface = gr.ChatInterface(
68
  respond,
69
  additional_inputs=[
 
82
 
83
  # Combine the two interfaces into a single Gradio Blocks application
84
  with gr.Blocks() as demo:
85
+ gr.Markdown(" ") # Adding space between the top and the ASR interface title
86
  gr.Markdown("# ASR and Chatbot Application")
87
+ gr.Markdown(" ") # Adding space between the ASR title and interface
88
  asr_interface.render()
89
  gr.Markdown("----")
90
  chat_interface.render()
91
 
92
  if __name__ == "__main__":
93
+ demo.launch()