Ridealist commited on
Commit
dd52c00
1 Parent(s): 7a5d869

feat: Add conditional branch for checking reload or generate new tts voice

Browse files
Files changed (1) hide show
  1. app.py +20 -13
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  import numpy as np
3
  import openai
 
4
 
5
  from gtts import gTTS
6
  from collections import Counter
@@ -377,7 +378,7 @@ def page4():
377
 
378
  if start:
379
  if validate_case(case_error_message):
380
- page_3_4_controller()
381
  st.experimental_rerun()
382
 
383
  #########################################################
@@ -518,6 +519,7 @@ def page5():
518
  response_container = st.container()
519
  # container for text box
520
  container = st.container()
 
521
 
522
  with container:
523
  with st.form(key='my_form', clear_on_submit=True):
@@ -526,7 +528,6 @@ def page5():
526
  audio = audiorecorder("Click to record", "Recording...")
527
  if np.array_equal(st.session_state['pre_audio'], audio):
528
  audio = np.array([])
529
- print("audio", audio)
530
 
531
  #user_input = st.text_area("You:", key='input', height=100)
532
  submit_buttom = st.form_submit_button(label='Send')
@@ -546,7 +547,8 @@ def page5():
546
  limit_num=1
547
  )
548
 
549
- if debate_main_latest_data == []:
 
550
  turn_num = 0
551
  else:
552
  turn_num = debate_main_latest_data[0]['turn_num']
@@ -565,33 +567,38 @@ def page5():
565
 
566
  else:
567
  send_error_message.error("Please record your voice first", icon="🚨")
 
568
  print("Nothing to transcribe")
569
 
570
  #TODO 사용자 input이 없을 때도 reloading으로 buffering 걸리는 문제 해결
571
  with response_container:
572
  message(st.session_state['bot_debate_history'][0], key='0_bot')
573
- text_to_speech = gTTS(text=st.session_state['bot_debate_history'][0], lang='en', slow=False)
574
- text_to_speech.save(f'audio/test_gtts_0.mp3')
575
- audio_file = open(f'audio/test_gtts_0.mp3', 'rb')
 
 
576
  audio_bytes = audio_file.read()
577
  st.audio(audio_bytes, format='audio/ogg')
578
 
579
  for i in range(len(st.session_state['user_debate_history'])):
580
  message(st.session_state['user_debate_history'][i], is_user=True, key=str(i)+'_user')
581
  message(st.session_state['bot_debate_history'][i + 1], key=str(i + 1)+'_bot')
582
- text_to_speech = gTTS(text=st.session_state['bot_debate_history'][i + 1], lang='en', slow=False)
583
- text_to_speech.save(f'audio/test_gtts_{str(i + 1)}.mp3')
584
- audio_file = open(f'audio/test_gtts_{str(i + 1)}.mp3', 'rb')
 
585
  audio_bytes = audio_file.read()
586
  st.audio(audio_bytes, format='audio/ogg')
 
587
 
588
  if st.button(label="Next",
589
- on_click=page_4_5_controller):
590
  st.write('Information submitted successfully.')
591
 
592
- print("#"*50)
593
- print(st.session_state)
594
- print("#"*50)
595
 
596
  #########################################################
597
  # Page5 - Total Debate Evaluation
 
1
  import streamlit as st
2
  import numpy as np
3
  import openai
4
+ import pprint
5
 
6
  from gtts import gTTS
7
  from collections import Counter
 
378
 
379
  if start:
380
  if validate_case(case_error_message):
381
+ page_4_5_controller()
382
  st.experimental_rerun()
383
 
384
  #########################################################
 
519
  response_container = st.container()
520
  # container for text box
521
  container = st.container()
522
+ reload = False
523
 
524
  with container:
525
  with st.form(key='my_form', clear_on_submit=True):
 
528
  audio = audiorecorder("Click to record", "Recording...")
529
  if np.array_equal(st.session_state['pre_audio'], audio):
530
  audio = np.array([])
 
531
 
532
  #user_input = st.text_area("You:", key='input', height=100)
533
  submit_buttom = st.form_submit_button(label='Send')
 
547
  limit_num=1
548
  )
549
 
550
+ print(f'debate_main_latest_data : {debate_main_latest_data}')
551
+ if not debate_main_latest_data:
552
  turn_num = 0
553
  else:
554
  turn_num = debate_main_latest_data[0]['turn_num']
 
567
 
568
  else:
569
  send_error_message.error("Please record your voice first", icon="🚨")
570
+ reload = True
571
  print("Nothing to transcribe")
572
 
573
  #TODO 사용자 input이 없을 때도 reloading으로 buffering 걸리는 문제 해결
574
  with response_container:
575
  message(st.session_state['bot_debate_history'][0], key='0_bot')
576
+ if len(st.session_state['bot_debate_history']) == 1:
577
+ text_to_speech = gTTS(text=st.session_state['bot_debate_history'][0], lang='en', slow=False)
578
+ text_to_speech.save(f"audio/bot_{st.session_state['session_num']}_res_0.mp3")
579
+
580
+ audio_file = open(f"audio/bot_{st.session_state['session_num']}_res_0.mp3", 'rb')
581
  audio_bytes = audio_file.read()
582
  st.audio(audio_bytes, format='audio/ogg')
583
 
584
  for i in range(len(st.session_state['user_debate_history'])):
585
  message(st.session_state['user_debate_history'][i], is_user=True, key=str(i)+'_user')
586
  message(st.session_state['bot_debate_history'][i + 1], key=str(i + 1)+'_bot')
587
+ if i == len(st.session_state['bot_debate_history']) - 2 and not reload:
588
+ text_to_speech = gTTS(text=st.session_state['bot_debate_history'][i + 1], lang='en', slow=False)
589
+ text_to_speech.save(f"audio/bot_{st.session_state['session_num']}_res_{str(i + 1)}.mp3")
590
+ audio_file = open(f"audio/bot_{st.session_state['session_num']}_res_{str(i + 1)}.mp3", 'rb')
591
  audio_bytes = audio_file.read()
592
  st.audio(audio_bytes, format='audio/ogg')
593
+ reload = False
594
 
595
  if st.button(label="Next",
596
+ on_click=page_5_6_controller):
597
  st.write('Information submitted successfully.')
598
 
599
+ print("#"*80)
600
+ pprint.pprint(st.session_state.to_dict())
601
+ print("#"*80)
602
 
603
  #########################################################
604
  # Page5 - Total Debate Evaluation