ident_ui.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import streamlit as st
  2. from ident_v2 import IdentV2
  3. from streamlit_chat import message
  4. st.set_page_config(page_title="IdentChat")
  5. def display_messages():
  6. st.subheader("Chat")
  7. for i, (msg, is_user) in enumerate(st.session_state["messages"]):
  8. message(msg, is_user=is_user, key=str(i))
  9. st.session_state["thinking_spinner"] = st.empty()
  10. def process_input():
  11. if st.session_state["user_input"] and len(st.session_state["user_input"].strip()) > 0:
  12. user_text = st.session_state["user_input"].strip()
  13. with st.session_state["thinking_spinner"], st.spinner(f"Thinking"):
  14. agent_text = st.session_state["assistant"].ident(user_text)
  15. st.session_state["messages"].append((user_text, True))
  16. st.session_state["messages"].append((agent_text, False))
  17. # st.session_state["assistant"].clear()
  18. def page():
  19. if len(st.session_state) == 0:
  20. st.session_state["messages"] = []
  21. st.session_state["assistant"] = IdentV2()
  22. st.header("IdentChat")
  23. st.session_state["ingestion_spinner"] = st.empty()
  24. display_messages()
  25. st.text_input("Message", key="user_input", on_change=process_input)
  26. if __name__ == "__main__":
  27. page()