Ridealist commited on
Commit
d116916
โ€ข
1 Parent(s): 925cca6

feat: apply transaction atomic architecture and rearange code.

Browse files
Files changed (1) hide show
  1. app.py +24 -24
app.py CHANGED
@@ -160,7 +160,6 @@ def page1():
160
  st.header('User Info')
161
  user_input = st.text_input(
162
  label='User ID',
163
- # key='user_id',
164
  max_chars=100,
165
  placeholder="Enter user ID",
166
  )
@@ -476,21 +475,20 @@ def page4():
476
  #########################################################
477
 
478
  def generate_response(prompt):
479
-
480
- st.session_state['user_debate_history'].append(prompt)
481
- st.session_state['total_debate_history'].append({"role": "user", "content": prompt})
482
-
483
  if len(prompt.split()) < 5:
484
  response = "Please speak longer!"
485
  else:
486
- response = gpt_call_context(st.session_state['total_debate_history'])
487
-
488
- st.session_state['bot_debate_history'].append(response)
489
- st.session_state['total_debate_history'].append({"role": "assistant", "content": response})
490
- return response
491
-
492
- def execute_stt(audio, error_message):
 
 
493
 
 
494
  # audio ๊ธฐ๋ก ๋ˆ„์ 
495
  #user_audio_path = "audio/" + str(st.session_state.user_id) + "_" + str(st.session_state.session_num) + "_" + str(time.time()) + ".wav"
496
  # audio ๊ธฐ๋ก์„ ๋ˆ„์ ํ•˜๊ณ  ์‹ถ์ง€ ์•Š๋‹ค๋ฉด
@@ -501,18 +499,10 @@ def execute_stt(audio, error_message):
501
 
502
  try:
503
  user_input = whisper_transcribe(wav_file)
 
 
504
  except:
505
- error_message.warning('Whisper Error : The engine is currently overloaded. Please click "Rerun" button below.', icon="โš ๏ธ")
506
- time.sleep(1)
507
- rerun = st.button(label="Rerun", type="primary")
508
- if rerun:
509
- st.experimental_rerun()
510
- st.stop()
511
-
512
- # close file
513
- wav_file.close()
514
-
515
- return user_input
516
 
517
  def page5():
518
 
@@ -628,7 +618,17 @@ def page5():
628
  #if submit_button and user_input:
629
  if submit_button:
630
  if audio.any():
631
- user_input = execute_stt(audio, openai_error_bottom)
 
 
 
 
 
 
 
 
 
 
632
  try :
633
  response = generate_response(user_input)
634
  except:
 
160
  st.header('User Info')
161
  user_input = st.text_input(
162
  label='User ID',
 
163
  max_chars=100,
164
  placeholder="Enter user ID",
165
  )
 
475
  #########################################################
476
 
477
  def generate_response(prompt):
 
 
 
 
478
  if len(prompt.split()) < 5:
479
  response = "Please speak longer!"
480
  else:
481
+ try:
482
+ response = gpt_call_context(st.session_state['total_debate_history'])
483
+ st.session_state['user_debate_history'].append(prompt)
484
+ st.session_state['total_debate_history'].append({"role": "user", "content": prompt})
485
+ st.session_state['bot_debate_history'].append(response)
486
+ st.session_state['total_debate_history'].append({"role": "assistant", "content": response})
487
+ return response
488
+ except:
489
+ raise RuntimeError("ChatGPT API Error")
490
 
491
+ def execute_stt(audio):
492
  # audio ๊ธฐ๋ก ๋ˆ„์ 
493
  #user_audio_path = "audio/" + str(st.session_state.user_id) + "_" + str(st.session_state.session_num) + "_" + str(time.time()) + ".wav"
494
  # audio ๊ธฐ๋ก์„ ๋ˆ„์ ํ•˜๊ณ  ์‹ถ์ง€ ์•Š๋‹ค๋ฉด
 
499
 
500
  try:
501
  user_input = whisper_transcribe(wav_file)
502
+ wav_file.close()
503
+ return user_input
504
  except:
505
+ raise RuntimeError("Whisper API Error")
 
 
 
 
 
 
 
 
 
 
506
 
507
  def page5():
508
 
 
618
  #if submit_button and user_input:
619
  if submit_button:
620
  if audio.any():
621
+ try:
622
+ # user_input = execute_stt(audio)
623
+ user_input = "More detials about our issue here. 1. More objective measures: Academic performance is a more objective measure of a student's abilities than other factors such as extracurricular activities, personal essays, or letters of recommendation. These other factors can be biased towards students who have more resources and opportunities. 5. Saves time and money: If colleges only admitted students based on academic performance, they would not need to spend resources on evaluating personal essays, interviews, or other subjective measures of ability. This could save time and money for both colleges and students. "
624
+ except:
625
+ openai_error_bottom.warning('Whisper Error : The engine is currently overloaded. Please click "Rerun" button below.', icon="โš ๏ธ")
626
+ time.sleep(1)
627
+ rerun = st.button(label="Rerun", type="primary")
628
+ reload = True
629
+ if rerun:
630
+ st.experimental_rerun()
631
+ st.stop()
632
  try :
633
  response = generate_response(user_input)
634
  except: