File size: 932 Bytes
ecef7f6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import streamlit as st
import os
def chat_response(user_prompt, assistant_response):
if "chat_history" not in st.session_state:
st.session_state.chat_history = []
for message in st.session_state.chat_history:
if message["role"] == "user":
with st.chat_message("user"):
st.write(f"**You**: {message['content']}")
elif message["role"] == "assistant":
with st.chat_message("assistant"):
st.write(f"**Assistant**: {message['content']}")
if user_prompt:
st.session_state.chat_history.append({"role": "user", "content": user_prompt})
with st.chat_message("user"):
st.write(f"**You**: {user_prompt}")
with st.chat_message("assistant"):
st.write(f"**Assistant**: {assistant_response}")
st.session_state.chat_history.append({"role": "assistant", "content": assistant_response})
|