Spaces:
Runtime error
Runtime error
codingchild
commited on
Commit
β’
cc33a71
1
Parent(s):
9fdfed4
change execute_stt
Browse files
app.py
CHANGED
@@ -161,9 +161,11 @@ def page_n_1_controller():
|
|
161 |
# Page 1
|
162 |
#########################################################
|
163 |
def page1():
|
164 |
-
|
165 |
-
|
166 |
-
|
|
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
462 |
wav_file.write(audio.tobytes())
|
463 |
-
wav_file.close()
|
|
|
464 |
try:
|
465 |
-
user_input = whisper_transcribe(
|
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 |
-
|
|
|
|
|
|
|
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 |
|