Spaces:
Running
Running
Try a single input component
Browse files
app.py
CHANGED
|
@@ -102,11 +102,10 @@ def process_func(x: np.ndarray, sampling_rate: int) -> dict:
|
|
| 102 |
|
| 103 |
|
| 104 |
@spaces.GPU
|
| 105 |
-
def recognize(
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
elif input_file:
|
| 110 |
signal, sampling_rate = audiofile.read(file, duration=duration)
|
| 111 |
else:
|
| 112 |
raise gr.Error(
|
|
@@ -167,21 +166,21 @@ with gr.Blocks() as demo:
|
|
| 167 |
with gr.Tab(label="Input"):
|
| 168 |
with gr.Row():
|
| 169 |
with gr.Column():
|
| 170 |
-
input_selection = gr.Radio(
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
)
|
| 175 |
input_file = gr.Audio(
|
| 176 |
-
sources="upload",
|
| 177 |
type="filepath",
|
| 178 |
label="Audio file",
|
| 179 |
)
|
| 180 |
-
input_microphone = gr.Audio(
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
)
|
| 185 |
|
| 186 |
# output_selector = gr.Dropdown(
|
| 187 |
# choices=["age", "gender"],
|
|
@@ -201,14 +200,13 @@ with gr.Blocks() as demo:
|
|
| 201 |
|
| 202 |
# output_selector.input(update_output, output_selector, output)
|
| 203 |
|
| 204 |
-
inputs = [input_microphone, input_file]
|
| 205 |
outputs = [output_age, output_gender]
|
| 206 |
|
| 207 |
-
input_selection.change(toggle_input, input_selection, inputs)
|
| 208 |
-
input_microphone.change(lambda x: x, input_microphone, outputs)
|
| 209 |
-
input_file.change(lambda x: x, input_file, outputs)
|
| 210 |
|
| 211 |
-
submit_btn.click(recognize,
|
| 212 |
|
| 213 |
|
| 214 |
demo.launch(debug=True)
|
|
|
|
| 102 |
|
| 103 |
|
| 104 |
@spaces.GPU
|
| 105 |
+
def recognize(input_file):
|
| 106 |
+
# sampling_rate, signal = input_microphone
|
| 107 |
+
# signal = signal.astype(np.float32, order="C") / 32768.0
|
| 108 |
+
if input_file:
|
|
|
|
| 109 |
signal, sampling_rate = audiofile.read(file, duration=duration)
|
| 110 |
else:
|
| 111 |
raise gr.Error(
|
|
|
|
| 166 |
with gr.Tab(label="Input"):
|
| 167 |
with gr.Row():
|
| 168 |
with gr.Column():
|
| 169 |
+
# input_selection = gr.Radio(
|
| 170 |
+
# ["microphone", "file"],
|
| 171 |
+
# value="file",
|
| 172 |
+
# label="How would you like to upload your audio?",
|
| 173 |
+
# )
|
| 174 |
input_file = gr.Audio(
|
| 175 |
+
sources=["upload", "microphone"],
|
| 176 |
type="filepath",
|
| 177 |
label="Audio file",
|
| 178 |
)
|
| 179 |
+
# input_microphone = gr.Audio(
|
| 180 |
+
# sources="microphone",
|
| 181 |
+
# type="filepath",
|
| 182 |
+
# label="Microphone",
|
| 183 |
+
# )
|
| 184 |
|
| 185 |
# output_selector = gr.Dropdown(
|
| 186 |
# choices=["age", "gender"],
|
|
|
|
| 200 |
|
| 201 |
# output_selector.input(update_output, output_selector, output)
|
| 202 |
|
|
|
|
| 203 |
outputs = [output_age, output_gender]
|
| 204 |
|
| 205 |
+
# input_selection.change(toggle_input, input_selection, inputs)
|
| 206 |
+
# input_microphone.change(lambda x: x, input_microphone, outputs)
|
| 207 |
+
# input_file.change(lambda x: x, input_file, outputs)
|
| 208 |
|
| 209 |
+
submit_btn.click(recognize, input_file, outputs)
|
| 210 |
|
| 211 |
|
| 212 |
demo.launch(debug=True)
|