kh-CHEUNG commited on
Commit
1a40aec
·
verified ·
1 Parent(s): c46a1db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -16
app.py CHANGED
@@ -74,40 +74,72 @@ def respond(
74
  @spaces.GPU
75
  def transcribe(inputs, task):
76
  if inputs is None:
77
- raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
78
-
79
- text = asr_pl(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
80
  return text
81
 
82
  demo = gr.Blocks()
83
-
84
- transcribe_interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
 
87
  """
88
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
89
  """
90
 
91
- chat_interface = gr.ChatInterface(
92
- respond,
93
- title="Enlight Innovations Limited -- Demo",
94
- description="This demo is desgined to illustrate our basic idea and feasibility in implementation.",
95
- additional_inputs=[
96
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
97
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
98
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
99
- gr.Slider(
100
  minimum=0.1,
101
  maximum=1.0,
102
  value=0.95,
103
  step=0.05,
104
  label="Top-p (nucleus sampling)",
105
- ),
 
 
 
 
 
 
 
 
 
 
106
  ],
107
  )
108
 
 
 
 
 
 
 
109
  with demo:
110
- gr.TabbedInterface([transcribe_interface, chat_interface], ["Step 1: Transcribe", "Step 2: "])
 
111
 
112
  if __name__ == "__main__":
113
  demo.queue().launch() #demo.launch()
 
74
  @spaces.GPU
75
  def transcribe(inputs, task):
76
  if inputs is None:
77
+ raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
78
+
79
+ text = asr_pl(asr_inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
80
  return text
81
 
82
  demo = gr.Blocks()
83
+ audio_input = gr.Audio(sources="upload", type="filepath", label="Audio file")
84
+ audio_input_choice = gr.Radio(["audio file", "microphone"], label="Audio", value="audio file")
85
+ task_input_choice = gr.Radio(["transcribe", "translate"], label="Task", value="transcribe")
86
+
87
+ transcribe_interface = gr.Interface(
88
+ fn=transcribe,
89
+ inputs=[
90
+ audio_input,
91
+ audio_input_choice,
92
+ task_input_choice,
93
+ ],
94
+ outputs="text",
95
+ title="Whisper Large V3: Transcribe Audio",
96
+ description=(
97
+ "Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the"
98
+ f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
99
+ " of arbitrary length."
100
+ ),
101
+ allow_flagging="never",
102
+ )
103
 
104
 
105
  """
106
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
107
  """
108
 
109
+ application_title = "Enlight Innovations Limited -- Demo"
110
+ application_description = "This demo is desgined to illustrate our basic idea and feasibility in implementation."
111
+ chatbot_sys_output = gr.Textbox(value="You are a friendly Chatbot.", label="System message")
112
+ chatbot_max_tokens = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
113
+ chatbot_temperature = gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature")
114
+ chatbot_top_p = gr.Slider(
 
 
 
115
  minimum=0.1,
116
  maximum=1.0,
117
  value=0.95,
118
  step=0.05,
119
  label="Top-p (nucleus sampling)",
120
+ )
121
+
122
+ chat_interface = gr.ChatInterface(
123
+ respond,
124
+ title=application_title,
125
+ description=application_description,
126
+ additional_inputs=[
127
+ chatbot_sys_output,
128
+ chatbot_max_tokens,
129
+ chatbot_temperature,
130
+ chatbot_top_p,
131
  ],
132
  )
133
 
134
+ def update_audio_input(audio_input_choice):
135
+ if user_choice == "audio file":
136
+ return gr.Audio(sources="upload", type="filepath", label="Audio file")
137
+ elif user_choice == "microphone":
138
+ gr.Audio(sources="microphone", type="filepath")
139
+
140
  with demo:
141
+ gr.TabbedInterface([transcribe_interface, chat_interface], ["Step 1: Transcribe", "Step 2: Extract"])
142
+ audio_input_choice.change(update_audio_input, audio_input_choice, audio_input)
143
 
144
  if __name__ == "__main__":
145
  demo.queue().launch() #demo.launch()