Spaces:
Sleeping
Sleeping
update streamlit_app.py 2
Browse files- streamlit_app.py +18 -7
streamlit_app.py
CHANGED
@@ -41,8 +41,13 @@ def main():
|
|
41 |
|
42 |
# Display chat history
|
43 |
for message in st.session_state.messages:
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
# Chat input and response handling
|
48 |
# Check if st.chat_input is available (Streamlit 1.2 or higher)
|
@@ -55,13 +60,19 @@ def main():
|
|
55 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
56 |
|
57 |
# Display user message
|
58 |
-
|
59 |
-
st.
|
|
|
|
|
|
|
60 |
|
61 |
# Generate response (cached if already asked before)
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
65 |
|
66 |
# Store bot response in chat history
|
67 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
|
|
41 |
|
42 |
# Display chat history
|
43 |
for message in st.session_state.messages:
|
44 |
+
role = message["role"]
|
45 |
+
content = message["content"]
|
46 |
+
if hasattr(st, "chat_message"):
|
47 |
+
with st.chat_message(role):
|
48 |
+
st.markdown(content)
|
49 |
+
else:
|
50 |
+
st.write(f"**{role.capitalize()}:** {content}")
|
51 |
|
52 |
# Chat input and response handling
|
53 |
# Check if st.chat_input is available (Streamlit 1.2 or higher)
|
|
|
60 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
61 |
|
62 |
# Display user message
|
63 |
+
if hasattr(st, "chat_message"):
|
64 |
+
with st.chat_message("user"):
|
65 |
+
st.markdown(prompt)
|
66 |
+
else:
|
67 |
+
st.write(f"**User:** {prompt}")
|
68 |
|
69 |
# Generate response (cached if already asked before)
|
70 |
+
if hasattr(st, "chat_message"):
|
71 |
+
with st.chat_message("assistant"):
|
72 |
+
response = cached_response(prompt)
|
73 |
+
st.markdown(response)
|
74 |
+
else:
|
75 |
+
st.write(f"**Assistant:** {response}")
|
76 |
|
77 |
# Store bot response in chat history
|
78 |
st.session_state.messages.append({"role": "assistant", "content": response})
|