This repository has been archived by the owner on Mar 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from mertbozkir/grace/dev
Final PR for hackathon! 🧪
- Loading branch information
Showing
3 changed files
with
23 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
import streamlit as st | ||
import ast | ||
from public import tpl_bot, tpl_user | ||
|
||
from .audio import handle_text_2_speech | ||
|
||
|
||
def handle_userinput(user_question): | ||
response = st.session_state.conversation({'question': user_question}) | ||
st.session_state.chat_history = response['chat_history'] | ||
chat_history_list = response['chat_history'] | ||
|
||
chat_history = st.session_state.chat_history | ||
# Extract content from each message object | ||
for i, message in enumerate(chat_history_list): | ||
st.session_state.chat_history.insert(i, message.content) | ||
# only keep the latest 12 chat history | ||
if len(st.session_state.chat_history) >= 12: | ||
st.session_state.chat_history = st.session_state.chat_history[:-2] | ||
|
||
chat_history = st.session_state.chat_history | ||
print(f"length of chat_history is {len(chat_history)}") | ||
for i, message in enumerate(chat_history): | ||
if i % 2 == 0: # User's message #FIXME | ||
if i % 2 == 0: # User's message | ||
print(f'User question is {message}') | ||
st.write( | ||
tpl_user.replace( | ||
'{{MSG}}', message.content, | ||
'{{MSG}}', message, | ||
), unsafe_allow_html=True, | ||
) | ||
else: # AI message | ||
st.write( | ||
tpl_bot.replace( | ||
'{{MSG}}', message.content, | ||
'{{MSG}}', message, | ||
), unsafe_allow_html=True, | ||
) | ||
|
||
if len(chat_history) > 0: | ||
handle_text_2_speech(chat_history[-1].content) | ||
# if len(chat_history) > 0: | ||
# handle_text_2_speech(chat_history[-1].content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters