codingchild commited on
Commit
cc33a71
β€’
1 Parent(s): 9fdfed4

change execute_stt

Browse files
Files changed (1) hide show
  1. app.py +29 -8
app.py CHANGED
@@ -161,9 +161,11 @@ def page_n_1_controller():
161
  # Page 1
162
  #########################################################
163
  def page1():
164
- _, _, _, home = st.columns([5, 5, 1, 1])
165
- with home:
166
- st.button("πŸ”", on_click=page_n_1_controller, use_container_width=True)
 
 
167
 
168
  st.header('User Info')
169
  st.session_state.user_id = st.text_input(
@@ -450,24 +452,38 @@ def page4():
450
  #########################################################
451
 
452
  def generate_response(prompt):
 
453
  st.session_state['user_debate_history'].append(prompt)
454
  st.session_state['total_debate_history'].append({"role": "user", "content": prompt})
455
- response = gpt_call_context(st.session_state['total_debate_history'])
 
 
 
 
 
456
  st.session_state['bot_debate_history'].append(response)
457
  st.session_state['total_debate_history'].append({"role": "assistant", "content": response})
458
  return response
459
 
460
  def execute_stt(audio, error_message):
461
- wav_file = open("audio/audio.wav", "wb")
 
 
 
 
 
462
  wav_file.write(audio.tobytes())
463
- wav_file.close()
 
464
  try:
465
- user_input = whisper_transcribe(audio)
466
  except:
467
  error_message.error("Whisper Error : The engine is currently overloaded, it will be auto-reloaded in a second")
468
  time.sleep(1)
469
  st.experimental_rerun()
470
 
 
 
471
  return user_input
472
 
473
  def page5():
@@ -582,8 +598,10 @@ def page5():
582
  if submit_buttom:
583
  if audio.any():
584
  user_input = execute_stt(audio, openai_error_bottom)
 
585
  try :
586
  response = generate_response(user_input)
 
587
  except:
588
  openai_error_bottom.error("Chat-GPT Error : The engine is currently overloaded, it will be auto-reloaded in a second")
589
  time.sleep(1)
@@ -721,7 +739,10 @@ def page6():
721
  # 총 단어
722
  # ν…μŠ€νŠΈλ₯Ό λ‹¨μ–΄λ‘œ λΆ„ν• ν•©λ‹ˆλ‹€.
723
  # 각 λ‹¨μ–΄μ˜ λΉˆλ„λ₯Ό κ³„μ‚°ν•©λ‹ˆλ‹€.
724
- total_word_count = len(user_history)
 
 
 
725
  #total_word_count = len(user_history.split())
726
  st.write("Total Word Count: ", total_word_count)
727
 
 
161
  # Page 1
162
  #########################################################
163
  def page1():
164
+
165
+ # μ²«νŽ˜μ΄μ§€λŠ” home이 λ”°λ‘œ ν•„μš”μ—†μ„ 것 κ°™μ•„μ„œ μ£Όμ„μ²˜λ¦¬ν•¨
166
+ #_, _, _, home = st.columns([5, 5, 1, 1])
167
+ # with home:
168
+ # st.button("πŸ”", on_click=page_n_1_controller, use_container_width=True)
169
 
170
  st.header('User Info')
171
  st.session_state.user_id = st.text_input(
 
452
  #########################################################
453
 
454
  def generate_response(prompt):
455
+
456
  st.session_state['user_debate_history'].append(prompt)
457
  st.session_state['total_debate_history'].append({"role": "user", "content": prompt})
458
+
459
+ if len(prompt.split()) < 10:
460
+ response = "Please speak longer!"
461
+ else:
462
+ response = gpt_call_context(st.session_state['total_debate_history'])
463
+
464
  st.session_state['bot_debate_history'].append(response)
465
  st.session_state['total_debate_history'].append({"role": "assistant", "content": response})
466
  return response
467
 
468
  def execute_stt(audio, error_message):
469
+
470
+ # 아무 말도 μž…λ ₯λ˜μ§€ μ•Šμ•˜μ„λ•Œ, 과거의 audio 파일이 μž…λ ₯λ˜λŠ” ν˜„μƒμ΄ μžˆμ—ˆμŒ
471
+ # μ˜€λ””μ˜€ 파일의 이름을 μžλ™μœΌλ‘œ λ³€κ²½ν•˜λ„λ‘ 섀정함 ([user_id]_[sesssion_num]_[real_time_stamp].wav)
472
+ user_audio_path = "audio/audio.wav" #"audio/" + str(st.session_state.user_id) + "_" + str(st.session_state.session_num) + "_" + str(time.time()) + ".wav"
473
+
474
+ wav_file = open(user_audio_path, "wb")
475
  wav_file.write(audio.tobytes())
476
+ #wav_file.close()
477
+
478
  try:
479
+ user_input = whisper_transcribe(wav_file)
480
  except:
481
  error_message.error("Whisper Error : The engine is currently overloaded, it will be auto-reloaded in a second")
482
  time.sleep(1)
483
  st.experimental_rerun()
484
 
485
+ wav_file.close()
486
+
487
  return user_input
488
 
489
  def page5():
 
598
  if submit_buttom:
599
  if audio.any():
600
  user_input = execute_stt(audio, openai_error_bottom)
601
+
602
  try :
603
  response = generate_response(user_input)
604
+ print("response", response)
605
  except:
606
  openai_error_bottom.error("Chat-GPT Error : The engine is currently overloaded, it will be auto-reloaded in a second")
607
  time.sleep(1)
 
739
  # 총 단어
740
  # ν…μŠ€νŠΈλ₯Ό λ‹¨μ–΄λ‘œ λΆ„ν• ν•©λ‹ˆλ‹€.
741
  # 각 λ‹¨μ–΄μ˜ λΉˆλ„λ₯Ό κ³„μ‚°ν•©λ‹ˆλ‹€.
742
+ total_user_turn = len(user_history)
743
+ total_word_count = len(
744
+ "".join(user_history).split() # 리슀트λ₯Ό λ¬Έμžμ—΄λ‘œ λ³€ν™˜ν•˜κ³ , 곡백을 κΈ°μ€€μœΌλ‘œ 단어λ₯Ό λΆ„ν• ν•©λ‹ˆλ‹€.
745
+ )
746
  #total_word_count = len(user_history.split())
747
  st.write("Total Word Count: ", total_word_count)
748