Spaces:
Runtime error
Runtime error
trying out a form
Browse files
app.py
CHANGED
@@ -79,37 +79,41 @@ def get_langcode_with_description(input_code):
|
|
79 |
if __name__ == "__main__":
|
80 |
# input_code = st.text_input("(optional) 2 or 3-letter ISO code for input language. 2-letter codes will be converted to 3-letter codes", max_chars=3)
|
81 |
supported_codes = get_supported_codes()
|
82 |
-
index_of_desired_default = supported_codes.index("ipa")
|
83 |
-
|
84 |
-
options=supported_codes,
|
85 |
-
index=index_of_desired_default,
|
86 |
-
format_func=get_langcode_with_description
|
87 |
-
)
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
".mp3",
|
98 |
-
],
|
99 |
-
accept_multiple_files=True,
|
100 |
-
)
|
101 |
|
102 |
-
|
103 |
|
104 |
-
uploaded_files_count = len(uploaded_files)
|
105 |
-
suppress_output_threshold = 2
|
106 |
-
my_bar = st.progress(0)
|
107 |
-
for i, uploaded_file in enumerate(uploaded_files):
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
if __name__ == "__main__":
|
80 |
# input_code = st.text_input("(optional) 2 or 3-letter ISO code for input language. 2-letter codes will be converted to 3-letter codes", max_chars=3)
|
81 |
supported_codes = get_supported_codes()
|
82 |
+
index_of_desired_default = supported_codes.index("ipa")
|
83 |
+
with st.form("Allosaurus form"):
|
|
|
|
|
|
|
|
|
84 |
|
85 |
+
langcode = st.selectbox("ISO code for input language. Allosaurus doesn't need this, but it can improve accuracy",
|
86 |
+
options=supported_codes,
|
87 |
+
index=index_of_desired_default,
|
88 |
+
format_func=get_langcode_with_description
|
89 |
+
)
|
90 |
+
|
91 |
+
model = read_recognizer()
|
92 |
+
description = get_langcode_description(langcode, url=True)
|
|
|
|
|
|
|
|
|
93 |
|
94 |
+
st.write(f"Instructing Allosaurus to recognize using language {langcode}. That is, {description}")
|
95 |
|
|
|
|
|
|
|
|
|
96 |
|
97 |
+
uploaded_files = st.file_uploader("Choose a file", type=[
|
98 |
+
".wav",
|
99 |
+
".mp3",
|
100 |
+
],
|
101 |
+
accept_multiple_files=True,
|
102 |
+
)
|
103 |
+
|
104 |
+
submitted = st.form_submit_button("Submit")
|
105 |
+
if submitted:
|
106 |
+
results = {} # for better download/display
|
107 |
+
|
108 |
+
uploaded_files_count = len(uploaded_files)
|
109 |
+
suppress_output_threshold = 2
|
110 |
+
my_bar = st.progress(0)
|
111 |
+
for i, uploaded_file in enumerate(uploaded_files):
|
112 |
+
|
113 |
+
if uploaded_file is not None:
|
114 |
+
wav_file = get_path_to_wav_format(uploaded_file, uploaded_files_count>suppress_output_threshold)
|
115 |
+
result = model.recognize(wav_file, langcode)
|
116 |
+
results[uploaded_file.name] = result
|
117 |
+
files_done = i+1
|
118 |
+
my_bar.progress(files_done/uploaded_files_count)
|
119 |
+
st.write(results)
|