changed nan output to empty string
Browse files
app.py
CHANGED
@@ -136,12 +136,14 @@ def send_task(payload):
|
|
136 |
header = {
|
137 |
"Authorization": f"Bearer {os.getenv('CREATE_TASK_API_KEY')}"
|
138 |
}
|
139 |
-
response = requests.post(CREATE_TASK_URL,json=payload,headers=header)
|
140 |
try:
|
141 |
response = response.json()
|
142 |
except Exception as e:
|
143 |
logger.error("Error while sending task %s",e)
|
144 |
-
logger.
|
|
|
|
|
145 |
return "error please try again"
|
146 |
|
147 |
if payload["task"] == "transcribe_with_fastapi":
|
@@ -203,6 +205,11 @@ def transcribe_audio():
|
|
203 |
st.session_state.option_2_response_time = round(time_3 - time_2,3)
|
204 |
st.session_state.option_1_response_time = round(time_2 - time_1,3)
|
205 |
|
|
|
|
|
|
|
|
|
|
|
206 |
return transcript1, transcript2
|
207 |
|
208 |
def reset_state():
|
@@ -220,99 +227,99 @@ def reset_state():
|
|
220 |
|
221 |
def on_option_1_click():
|
222 |
if st.session_state.transcribed and not st.session_state.option_selected:
|
223 |
-
st.
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
|
239 |
def on_option_2_click():
|
240 |
if st.session_state.transcribed and not st.session_state.option_selected:
|
241 |
-
st.
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
|
257 |
def on_option_both_click():
|
258 |
if st.session_state.transcribed and not st.session_state.option_selected:
|
259 |
-
st.
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
"user_email": st.session_state.user_email,
|
266 |
"audio_path": st.session_state.audio_path,
|
267 |
"winner_model": st.session_state.option_1_model_name,
|
268 |
"loser_model": st.session_state.option_2_model_name,
|
269 |
"option_1_duration_info": [(f"{st.session_state.option_1_model_name}_duration",st.session_state.option_1_response_time)],
|
270 |
"option_2_duration_info": [(f"{st.session_state.option_2_model_name}_duration",st.session_state.option_2_response_time)],
|
271 |
-
"
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
def on_option_none_click():
|
277 |
-
if st.session_state.transcribed and not st.session_state.option_selected:
|
278 |
-
st.toast("Saving and loading results... please wait",icon="πΎ")
|
279 |
-
st.session_state.option_1_model_name_state = f"π {st.session_state.option_1_model_name} π"
|
280 |
-
st.session_state.option_2_model_name_state = f"π {st.session_state.option_2_model_name} π"
|
281 |
-
st.session_state.choice = f"You chose none option. Option 1 was {st.session_state.option_1_model_name} Option 2 was {st.session_state.option_2_model_name}"
|
282 |
-
result_queue.put({
|
283 |
-
"user_email": st.session_state.user_email,
|
284 |
-
"audio_path": st.session_state.audio_path,
|
285 |
-
"winner_model": st.session_state.option_1_model_name,
|
286 |
-
"loser_model": st.session_state.option_2_model_name,
|
287 |
-
"option_1_duration_info": [(f"{st.session_state.option_1_model_name}_duration",st.session_state.option_1_response_time)],
|
288 |
-
"option_2_duration_info": [(f"{st.session_state.option_2_model_name}_duration",st.session_state.option_2_response_time)],
|
289 |
-
"none_preferred": True
|
290 |
-
}
|
291 |
-
)
|
292 |
-
st.session_state.option_selected = True
|
293 |
|
294 |
def on_click_transcribe():
|
295 |
if st.session_state.has_audio:
|
296 |
-
st.
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
|
306 |
def on_random_click():
|
307 |
reset_state()
|
308 |
-
st.
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
|
317 |
writer_thread = threading.Thread(target=result_writer_thread)
|
318 |
writer_thread.start()
|
|
|
136 |
header = {
|
137 |
"Authorization": f"Bearer {os.getenv('CREATE_TASK_API_KEY')}"
|
138 |
}
|
139 |
+
response = requests.post(CREATE_TASK_URL,json=payload,headers=header,timeout=300)
|
140 |
try:
|
141 |
response = response.json()
|
142 |
except Exception as e:
|
143 |
logger.error("Error while sending task %s",e)
|
144 |
+
logger.error("response received %s",response.text)
|
145 |
+
if response.status_code == 413:
|
146 |
+
return "Recording too long, please try again"
|
147 |
return "error please try again"
|
148 |
|
149 |
if payload["task"] == "transcribe_with_fastapi":
|
|
|
205 |
st.session_state.option_2_response_time = round(time_3 - time_2,3)
|
206 |
st.session_state.option_1_response_time = round(time_2 - time_1,3)
|
207 |
|
208 |
+
if transcript1 == "nan":
|
209 |
+
transcript1 = ""
|
210 |
+
if transcript2 == "nan":
|
211 |
+
transcript2 = ""
|
212 |
+
|
213 |
return transcript1, transcript2
|
214 |
|
215 |
def reset_state():
|
|
|
227 |
|
228 |
def on_option_1_click():
|
229 |
if st.session_state.transcribed and not st.session_state.option_selected:
|
230 |
+
with st.spinner("πΎ Saving and loading results... please wait"):
|
231 |
+
st.session_state.option_1_model_name_state = f"π {st.session_state.option_1_model_name} π"
|
232 |
+
st.session_state.option_2_model_name_state = f"π {st.session_state.option_2_model_name} π"
|
233 |
+
st.session_state.choice = f"You chose Option 1. Option 1 was {st.session_state.option_1_model_name} Option 2 was {st.session_state.option_2_model_name}"
|
234 |
+
result_queue.put(
|
235 |
+
{
|
236 |
+
"user_email": st.session_state.user_email,
|
237 |
+
"audio_path": st.session_state.audio_path,
|
238 |
+
"winner_model": st.session_state.option_1_model_name,
|
239 |
+
"loser_model": st.session_state.option_2_model_name,
|
240 |
+
"option_1_duration_info": [(f"{st.session_state.option_1_model_name}_duration",st.session_state.option_1_response_time)],
|
241 |
+
"option_2_duration_info": [(f"{st.session_state.option_2_model_name}_duration",st.session_state.option_2_response_time)]
|
242 |
+
}
|
243 |
+
)
|
244 |
+
st.session_state.option_selected = True
|
245 |
|
246 |
def on_option_2_click():
|
247 |
if st.session_state.transcribed and not st.session_state.option_selected:
|
248 |
+
with st.spinner("πΎ Saving and loading results... please wait"):
|
249 |
+
st.session_state.option_2_model_name_state = f"π {st.session_state.option_2_model_name} π"
|
250 |
+
st.session_state.option_1_model_name_state = f"π {st.session_state.option_1_model_name} π"
|
251 |
+
st.session_state.choice = f"You chose Option 2. Option 1 was {st.session_state.option_1_model_name} Option 2 was {st.session_state.option_2_model_name}"
|
252 |
+
result_queue.put(
|
253 |
+
{
|
254 |
+
"user_email": st.session_state.user_email,
|
255 |
+
"audio_path": st.session_state.audio_path,
|
256 |
+
"winner_model": st.session_state.option_2_model_name,
|
257 |
+
"loser_model": st.session_state.option_1_model_name,
|
258 |
+
"option_1_duration_info": [(f"{st.session_state.option_1_model_name}_duration",st.session_state.option_1_response_time)],
|
259 |
+
"option_2_duration_info": [(f"{st.session_state.option_2_model_name}_duration",st.session_state.option_2_response_time)]
|
260 |
+
}
|
261 |
+
)
|
262 |
+
st.session_state.option_selected = True
|
263 |
|
264 |
def on_option_both_click():
|
265 |
if st.session_state.transcribed and not st.session_state.option_selected:
|
266 |
+
with st.spinner("πΎ Saving and loading results... please wait"):
|
267 |
+
st.session_state.option_2_model_name_state = f"π {st.session_state.option_2_model_name} π"
|
268 |
+
st.session_state.option_1_model_name_state = f"π {st.session_state.option_1_model_name} π"
|
269 |
+
st.session_state.choice = f"You chose Prefer both. Option 1 was {st.session_state.option_1_model_name} Option 2 was {st.session_state.option_2_model_name}"
|
270 |
+
result_queue.put(
|
271 |
+
{
|
272 |
+
"user_email": st.session_state.user_email,
|
273 |
+
"audio_path": st.session_state.audio_path,
|
274 |
+
"winner_model": st.session_state.option_1_model_name,
|
275 |
+
"loser_model": st.session_state.option_2_model_name,
|
276 |
+
"option_1_duration_info": [(f"{st.session_state.option_1_model_name}_duration",st.session_state.option_1_response_time)],
|
277 |
+
"option_2_duration_info": [(f"{st.session_state.option_2_model_name}_duration",st.session_state.option_2_response_time)],
|
278 |
+
"both_preferred": True
|
279 |
+
}
|
280 |
+
)
|
281 |
+
st.session_state.option_selected = True
|
282 |
+
|
283 |
+
def on_option_none_click():
|
284 |
+
if st.session_state.transcribed and not st.session_state.option_selected:
|
285 |
+
with st.spinner("πΎ Saving and loading results... please wait"):
|
286 |
+
st.session_state.option_1_model_name_state = f"π {st.session_state.option_1_model_name} π"
|
287 |
+
st.session_state.option_2_model_name_state = f"π {st.session_state.option_2_model_name} π"
|
288 |
+
st.session_state.choice = f"You chose none option. Option 1 was {st.session_state.option_1_model_name} Option 2 was {st.session_state.option_2_model_name}"
|
289 |
+
result_queue.put({
|
290 |
"user_email": st.session_state.user_email,
|
291 |
"audio_path": st.session_state.audio_path,
|
292 |
"winner_model": st.session_state.option_1_model_name,
|
293 |
"loser_model": st.session_state.option_2_model_name,
|
294 |
"option_1_duration_info": [(f"{st.session_state.option_1_model_name}_duration",st.session_state.option_1_response_time)],
|
295 |
"option_2_duration_info": [(f"{st.session_state.option_2_model_name}_duration",st.session_state.option_2_response_time)],
|
296 |
+
"none_preferred": True
|
297 |
+
}
|
298 |
+
)
|
299 |
+
st.session_state.option_selected = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
300 |
|
301 |
def on_click_transcribe():
|
302 |
if st.session_state.has_audio:
|
303 |
+
with st.spinner("πΎ Saving and loading results... please wait"):
|
304 |
+
option_1_text, option_2_text = transcribe_audio(
|
305 |
+
)
|
306 |
+
st.session_state.option_1 = option_1_text
|
307 |
+
st.session_state.option_2 = option_2_text
|
308 |
+
st.session_state.transcribed = True
|
309 |
+
st.session_state.option_1_model_name_state = ""
|
310 |
+
st.session_state.option_2_model_name_state = ""
|
311 |
+
st.session_state.option_selected = None
|
312 |
|
313 |
def on_random_click():
|
314 |
reset_state()
|
315 |
+
with st.spinner("πΎ Saving and loading results... please wait"):
|
316 |
+
fetch_audio_payload = {"task": "fetch_audio"}
|
317 |
+
array, sampling_rate, filepath = send_task(fetch_audio_payload)
|
318 |
+
st.session_state.audio = {"data":array,"sample_rate":sampling_rate,"format":"audio/wav"}
|
319 |
+
st.session_state.has_audio = True
|
320 |
+
st.session_state.current_audio_type = "random"
|
321 |
+
st.session_state.audio_path = filepath
|
322 |
+
st.session_state.option_selected = None
|
323 |
|
324 |
writer_thread = threading.Thread(target=result_writer_thread)
|
325 |
writer_thread.start()
|