Spaces:
Runtime error
Runtime error
feat: inplement OpenAI api or internal server error handling code
Browse files
app.py
CHANGED
@@ -164,7 +164,6 @@ def save_info(user_id):
|
|
164 |
|
165 |
def page1():
|
166 |
st.header('User Info')
|
167 |
-
|
168 |
user_input = st.text_input(
|
169 |
label='User ID',
|
170 |
# key='user_id',
|
@@ -488,9 +487,12 @@ def execute_stt(audio, error_message):
|
|
488 |
try:
|
489 |
user_input = whisper_transcribe(wav_file)
|
490 |
except:
|
491 |
-
error_message.
|
492 |
time.sleep(1)
|
493 |
-
st.
|
|
|
|
|
|
|
494 |
|
495 |
# close file
|
496 |
wav_file.close()
|
@@ -522,9 +524,12 @@ def page5():
|
|
522 |
result = gpt_call(user_input)
|
523 |
st.session_state.ask_gpt_prev_response = result
|
524 |
except:
|
525 |
-
|
526 |
-
time.sleep(1
|
527 |
-
st.
|
|
|
|
|
|
|
528 |
|
529 |
put_item(
|
530 |
table=dynamodb.Table('DEBO_gpt_ask'),
|
@@ -545,17 +550,16 @@ def page5():
|
|
545 |
value=result,
|
546 |
height=400)
|
547 |
|
548 |
-
# Chat-GPT api error handling
|
549 |
-
gpt_error_top = st.empty()
|
550 |
-
|
551 |
# default system prompt settings
|
552 |
if not st.session_state['total_debate_history']:
|
553 |
|
554 |
# bot role, pros and cons
|
555 |
-
if st.session_state
|
556 |
bot_role = "Cons"
|
557 |
-
|
558 |
bot_role = "Pros"
|
|
|
|
|
559 |
|
560 |
debate_preset = "\n".join([
|
561 |
"Debate Rules: ",
|
@@ -573,9 +577,12 @@ def page5():
|
|
573 |
try:
|
574 |
response = gpt_call(debate_preset + "\n" + first_prompt, role="system")
|
575 |
except:
|
576 |
-
|
577 |
time.sleep(1)
|
578 |
-
st.
|
|
|
|
|
|
|
579 |
|
580 |
st.session_state['total_debate_history'].append({"role": "assistant", "content": response})
|
581 |
st.session_state['bot_debate_history'].append(response)
|
@@ -615,9 +622,12 @@ def page5():
|
|
615 |
response = generate_response(user_input)
|
616 |
print("response", response)
|
617 |
except:
|
618 |
-
openai_error_bottom.
|
619 |
time.sleep(1)
|
620 |
-
st.
|
|
|
|
|
|
|
621 |
st.session_state['pre_audio'] = audio
|
622 |
|
623 |
debate_main_latest_data = get_lastest_item(
|
@@ -649,7 +659,15 @@ def page5():
|
|
649 |
reload = True
|
650 |
|
651 |
with response_container:
|
652 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
653 |
if len(st.session_state['bot_debate_history']) == 1:
|
654 |
text_to_speech = gTTS(text=st.session_state['bot_debate_history'][0], lang='en', slow=False)
|
655 |
text_to_speech.save(f"audio/bot_{st.session_state['session_num']}_res_0.mp3")
|
|
|
164 |
|
165 |
def page1():
|
166 |
st.header('User Info')
|
|
|
167 |
user_input = st.text_input(
|
168 |
label='User ID',
|
169 |
# key='user_id',
|
|
|
487 |
try:
|
488 |
user_input = whisper_transcribe(wav_file)
|
489 |
except:
|
490 |
+
error_message.warning('Whisper Error : The engine is currently overloaded. Please click Rerun button in a second.', icon="⚠️")
|
491 |
time.sleep(1)
|
492 |
+
rerun = st.button(label="Rerun")
|
493 |
+
if rerun:
|
494 |
+
st.experimental_rerun()
|
495 |
+
st.stop()
|
496 |
|
497 |
# close file
|
498 |
wav_file.close()
|
|
|
524 |
result = gpt_call(user_input)
|
525 |
st.session_state.ask_gpt_prev_response = result
|
526 |
except:
|
527 |
+
st.warning('Chat-GPT Error : The engine is currently overloaded. Please click Rerun button in a second', icon="⚠️")
|
528 |
+
time.sleep(1)
|
529 |
+
rerun = st.button(label="Rerun")
|
530 |
+
if rerun:
|
531 |
+
st.experimental_rerun()
|
532 |
+
st.stop()
|
533 |
|
534 |
put_item(
|
535 |
table=dynamodb.Table('DEBO_gpt_ask'),
|
|
|
550 |
value=result,
|
551 |
height=400)
|
552 |
|
|
|
|
|
|
|
553 |
# default system prompt settings
|
554 |
if not st.session_state['total_debate_history']:
|
555 |
|
556 |
# bot role, pros and cons
|
557 |
+
if st.session_state.pros_and_cons == "Pros":
|
558 |
bot_role = "Cons"
|
559 |
+
elif st.session_state.pros_and_cons == "Cons":
|
560 |
bot_role = "Pros"
|
561 |
+
else:
|
562 |
+
bot_role = "(Not yet Determined)"
|
563 |
|
564 |
debate_preset = "\n".join([
|
565 |
"Debate Rules: ",
|
|
|
577 |
try:
|
578 |
response = gpt_call(debate_preset + "\n" + first_prompt, role="system")
|
579 |
except:
|
580 |
+
st.warning('Chat-GPT Error : The engine is currently overloaded. Please click Rerun button in a second', icon="⚠️")
|
581 |
time.sleep(1)
|
582 |
+
rerun = st.button(label="Rerun")
|
583 |
+
if rerun:
|
584 |
+
st.experimental_rerun()
|
585 |
+
st.stop()
|
586 |
|
587 |
st.session_state['total_debate_history'].append({"role": "assistant", "content": response})
|
588 |
st.session_state['bot_debate_history'].append(response)
|
|
|
622 |
response = generate_response(user_input)
|
623 |
print("response", response)
|
624 |
except:
|
625 |
+
openai_error_bottom.warning('Chat-GPT Error : The engine is currently overloaded. Please click Rerun button in a second', icon="⚠️")
|
626 |
time.sleep(1)
|
627 |
+
rerun = st.button(label="Rerun")
|
628 |
+
if rerun:
|
629 |
+
st.experimental_rerun()
|
630 |
+
st.stop()
|
631 |
st.session_state['pre_audio'] = audio
|
632 |
|
633 |
debate_main_latest_data = get_lastest_item(
|
|
|
659 |
reload = True
|
660 |
|
661 |
with response_container:
|
662 |
+
try:
|
663 |
+
message(st.session_state['bot_debate_history'][0], key='0_bot')
|
664 |
+
except:
|
665 |
+
st.warning('Server Error : Unexpected Server error occur. Please click Rerun button in a second.', icon="⚠️")
|
666 |
+
time.sleep(1)
|
667 |
+
rerun = st.button(label="Rerun")
|
668 |
+
if rerun:
|
669 |
+
st.experimental_rerun()
|
670 |
+
st.stop()
|
671 |
if len(st.session_state['bot_debate_history']) == 1:
|
672 |
text_to_speech = gTTS(text=st.session_state['bot_debate_history'][0], lang='en', slow=False)
|
673 |
text_to_speech.save(f"audio/bot_{st.session_state['session_num']}_res_0.mp3")
|