kh-CHEUNG commited on
Commit
106b63b
1 Parent(s): cddb038

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -48
app.py CHANGED
@@ -82,61 +82,61 @@ def transcribe(inputs, task):
82
  text = asr_pl(asr_inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
83
  return text
84
 
85
- demo = gr.Blocks()
86
- audio_input = gr.Audio(sources="microphone", type="filepath", label="Audio: from microphone") #gr.Audio(sources="upload", type="filepath", label="Audio: from file")
87
- audio_input_choice = gr.Radio(["audio file", "microphone"], label="Audio", value="audio file")
88
- task_input_choice = gr.Radio(["transcribe", "translate"], label="Task", value="transcribe")
89
-
90
- transcribe_interface = gr.Interface(
91
- fn=transcribe,
92
- inputs=[
93
- audio_input,
94
- audio_input_choice,
95
- task_input_choice,
96
- ],
97
- outputs="text",
98
- title=application_title,
99
- description=application_description,
100
- allow_flagging="never",
101
- )
102
-
103
-
104
- """
105
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
106
- """
107
-
108
- chatbot_sys_output = gr.Textbox(value="You are a friendly Chatbot.", label="System message")
109
- chatbot_max_tokens = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
110
- chatbot_temperature = gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature")
111
- chatbot_top_p = gr.Slider(
112
- minimum=0.1,
113
- maximum=1.0,
114
- value=0.95,
115
- step=0.05,
116
- label="Top-p (nucleus sampling)",
117
- )
118
-
119
- chat_interface = gr.ChatInterface(
120
- respond,
121
- title=application_title,
122
- description=application_description,
123
- additional_inputs=[
124
- chatbot_sys_output,
125
- chatbot_max_tokens,
126
- chatbot_temperature,
127
- chatbot_top_p,
128
- ],
129
- )
130
-
131
  def update_audio_input(audio_input_choice):
132
  if audio_input_choice == "audio file":
133
  return gr.Audio(sources="upload", type="filepath", label="Audio: from file")
134
  elif audio_input_choice == "microphone":
135
  return gr.Audio(sources="microphone", type="filepath", label="Audio: from microphone")
136
 
137
- audio_input_choice.change(update_audio_input, audio_input_choice, audio_input)
138
- with demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  gr.TabbedInterface([transcribe_interface, chat_interface], ["Step 1: Transcribe", "Step 2: Extract"])
 
140
 
141
  if __name__ == "__main__":
142
  demo.queue().launch() #demo.launch()
 
82
  text = asr_pl(asr_inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
83
  return text
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  def update_audio_input(audio_input_choice):
86
  if audio_input_choice == "audio file":
87
  return gr.Audio(sources="upload", type="filepath", label="Audio: from file")
88
  elif audio_input_choice == "microphone":
89
  return gr.Audio(sources="microphone", type="filepath", label="Audio: from microphone")
90
 
91
+
92
+ with gr.Blocks() as demo:
93
+ audio_input = gr.Audio(sources="microphone", type="filepath", label="Audio: from microphone") #gr.Audio(sources="upload", type="filepath", label="Audio: from file")
94
+ audio_input_choice = gr.Radio(["audio file", "microphone"], label="Audio", value="audio file")
95
+ task_input_choice = gr.Radio(["transcribe", "translate"], label="Task", value="transcribe")
96
+
97
+ transcribe_interface = gr.Interface(
98
+ fn=transcribe,
99
+ inputs=[
100
+ audio_input,
101
+ audio_input_choice,
102
+ task_input_choice,
103
+ ],
104
+ outputs="text",
105
+ title=application_title,
106
+ description=application_description,
107
+ allow_flagging="never",
108
+ )
109
+
110
+
111
+ """
112
+ For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
113
+ """
114
+
115
+ chatbot_sys_output = gr.Textbox(value="You are a friendly Chatbot.", label="System message")
116
+ chatbot_max_tokens = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
117
+ chatbot_temperature = gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature")
118
+ chatbot_top_p = gr.Slider(
119
+ minimum=0.1,
120
+ maximum=1.0,
121
+ value=0.95,
122
+ step=0.05,
123
+ label="Top-p (nucleus sampling)",
124
+ )
125
+
126
+ chat_interface = gr.ChatInterface(
127
+ respond,
128
+ title=application_title,
129
+ description=application_description,
130
+ additional_inputs=[
131
+ chatbot_sys_output,
132
+ chatbot_max_tokens,
133
+ chatbot_temperature,
134
+ chatbot_top_p,
135
+ ],
136
+ )
137
+
138
  gr.TabbedInterface([transcribe_interface, chat_interface], ["Step 1: Transcribe", "Step 2: Extract"])
139
+ audio_input_choice.change(update_audio_input, audio_input_choice, audio_input)
140
 
141
  if __name__ == "__main__":
142
  demo.queue().launch() #demo.launch()