rotate dialog & clear input after receive response from AI
This commit is contained in:
parent
261724ed8f
commit
a6a4966732
15
chat.py
15
chat.py
@ -53,17 +53,18 @@ if "user_text" not in st.session_state:
|
|||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
user_content = get_user_input()
|
if st.session_state.user_text:
|
||||||
show_chat_buttons()
|
show_conversation(st.session_state.user_text, st.session_state.model, st.session_state.role)
|
||||||
|
st.session_state.user_text = ""
|
||||||
|
|
||||||
c1, c2 = st.columns(2)
|
c1, c2 = st.columns(2)
|
||||||
with c1, c2:
|
with c1, c2:
|
||||||
model = c1.selectbox(label=st.session_state.locale.select_placeholder1, options=AI_MODEL_OPTIONS)
|
c1.selectbox(label=st.session_state.locale.select_placeholder1, key="model", options=AI_MODEL_OPTIONS)
|
||||||
role = c2.selectbox(label=st.session_state.locale.select_placeholder2,
|
c2.selectbox(label=st.session_state.locale.select_placeholder2, key="role",
|
||||||
options=st.session_state.locale.ai_role_options)
|
options=st.session_state.locale.ai_role_options)
|
||||||
|
|
||||||
if user_content:
|
get_user_input()
|
||||||
show_conversation(user_content, model, role)
|
show_chat_buttons()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -13,9 +13,8 @@ def clear_chat() -> None:
|
|||||||
st.session_state["user_text"] = ""
|
st.session_state["user_text"] = ""
|
||||||
|
|
||||||
|
|
||||||
def get_user_input() -> str:
|
def get_user_input():
|
||||||
user_text = st.text_area(label=st.session_state.locale.chat_placeholder, key="user_text")
|
st.text_area(label=st.session_state.locale.chat_placeholder, value=st.session_state.user_text, key="user_text")
|
||||||
return user_text
|
|
||||||
|
|
||||||
|
|
||||||
def show_chat_buttons() -> None:
|
def show_chat_buttons() -> None:
|
||||||
@ -32,10 +31,10 @@ def show_chat(ai_content: str, user_text: str) -> None:
|
|||||||
st.session_state.past.append(user_text)
|
st.session_state.past.append(user_text)
|
||||||
st.session_state.generated.append(ai_content)
|
st.session_state.generated.append(ai_content)
|
||||||
if st.session_state["generated"]:
|
if st.session_state["generated"]:
|
||||||
for i in range(len(st.session_state["generated"]) - 1, -1, -1):
|
for i in range(len(st.session_state["generated"])):
|
||||||
|
message(st.session_state["past"][i], is_user=True, key=str(i) + "_user", avatar_style="micah")
|
||||||
message("", key=str(i))
|
message("", key=str(i))
|
||||||
st.markdown(st.session_state["generated"][i])
|
st.markdown(st.session_state["generated"][i])
|
||||||
message(st.session_state["past"][i], is_user=True, key=str(i) + "_user", avatar_style="micah")
|
|
||||||
|
|
||||||
|
|
||||||
def show_conversation(user_content: str, model: str, role: str) -> None:
|
def show_conversation(user_content: str, model: str, role: str) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user