Spaces:
Runtime error
Runtime error
Try multiple outputs
Browse files
app.py
CHANGED
@@ -101,7 +101,7 @@ def process_func(x: np.ndarray, sampling_rate: int) -> dict:
|
|
101 |
|
102 |
|
103 |
@spaces.GPU
|
104 |
-
def recognize(file
|
105 |
if file is None:
|
106 |
raise gr.Error(
|
107 |
"No audio file submitted! "
|
@@ -110,10 +110,9 @@ def recognize(file, output_selector):
|
|
110 |
)
|
111 |
signal, sampling_rate = audiofile.read(file, duration=duration)
|
112 |
age_gender = process_func(signal, sampling_rate)
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
return {k: v for k, v in age_gender.items() if k != "age"}
|
117 |
|
118 |
|
119 |
outputs = gr.Label()
|
@@ -152,24 +151,29 @@ with gr.Blocks() as demo:
|
|
152 |
with gr.Tab(label="Input"):
|
153 |
with gr.Row():
|
154 |
with gr.Column():
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
label="
|
159 |
-
value="age",
|
160 |
)
|
|
|
|
|
|
|
|
|
|
|
161 |
submit_btn = gr.Button(value="Submit")
|
162 |
with gr.Column():
|
163 |
-
|
|
|
164 |
|
165 |
-
def update_output(output_selector):
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
|
171 |
-
output_selector.input(update_output, output_selector, output)
|
172 |
|
173 |
-
submit_btn.click(recognize, [
|
174 |
|
175 |
demo.launch(debug=True)
|
|
|
101 |
|
102 |
|
103 |
@spaces.GPU
|
104 |
+
def recognize(file):
|
105 |
if file is None:
|
106 |
raise gr.Error(
|
107 |
"No audio file submitted! "
|
|
|
110 |
)
|
111 |
signal, sampling_rate = audiofile.read(file, duration=duration)
|
112 |
age_gender = process_func(signal, sampling_rate)
|
113 |
+
age = f"{round(age_gender['age'])} years"
|
114 |
+
gender = {k: v for k, v in age_gender.items() if k != "age"}
|
115 |
+
return age, gender
|
|
|
116 |
|
117 |
|
118 |
outputs = gr.Label()
|
|
|
151 |
with gr.Tab(label="Input"):
|
152 |
with gr.Row():
|
153 |
with gr.Column():
|
154 |
+
input_file = gr.Audio(
|
155 |
+
sources="upload",
|
156 |
+
type="filepath",
|
157 |
+
label="Audio file",
|
|
|
158 |
)
|
159 |
+
# output_selector = gr.Dropdown(
|
160 |
+
# choices=["age", "gender"],
|
161 |
+
# label="Output",
|
162 |
+
# value="age",
|
163 |
+
# )
|
164 |
submit_btn = gr.Button(value="Submit")
|
165 |
with gr.Column():
|
166 |
+
output_age = gr.Textbox(label="Age")
|
167 |
+
output_gender = gr.Label(label="gender")
|
168 |
|
169 |
+
# def update_output(output_selector):
|
170 |
+
# """Set different output types for different model outputs."""
|
171 |
+
# if output_selector == "gender":
|
172 |
+
# output = gr.Label(label="gender")
|
173 |
+
# return output
|
174 |
|
175 |
+
# output_selector.input(update_output, output_selector, output)
|
176 |
|
177 |
+
submit_btn.click(recognize, [input_file], [output_age, output_gender])
|
178 |
|
179 |
demo.launch(debug=True)
|