Spaces:
Build error
Build error
#!/usr/bin/env python3 | |
# | |
# Copyright 2022 Xiaomi Corp. (authors: Fangjun Kuang) | |
# | |
# See LICENSE for clarification regarding multiple authors | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
import gradio as gr | |
demo = gr.Blocks() | |
def process_uploaded_file(uploaded_file: str): | |
print("uploaded_file", uploaded_file) | |
return "hello" | |
with demo: | |
gr.Markdown("Upload audio from disk or record from microphone for recognition") | |
with gr.Tabs(): | |
with gr.TabItem("Upload from disk"): | |
uploaded_file = gr.inputs.Audio( | |
source="upload", # Choose between "microphone", "upload" | |
type="filepath", | |
optional=False, | |
label="Upload from disk", | |
) | |
upload_button = gr.Button("Upload") | |
uploaded_output = ( | |
gr.outputs.Textbox(label="Recognized speech for uploaded file"), | |
) | |
with gr.TabItem("Record from microphone"): | |
microphone = gr.inputs.Audio( | |
source="microphone", # Choose between "microphone", "upload" | |
type="filepath", | |
optional=False, | |
label="Record from microphone", | |
) | |
recorded_output = ( | |
gr.outputs.Textbox(label="Recognized speech for recordings"), | |
) | |
record_button = gr.Button("Record") | |
upload_button.click( | |
process_uploaded_file, | |
inputs=uploaded_file, | |
outputs=uploaded_output, | |
) | |
record_button.click( | |
process_uploaded_file, | |
inputs=microphone, | |
outputs=recorded_output, | |
) | |
if __name__ == "__main__": | |
demo.launch() | |