Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
st.title("Echo Bot")
|
| 4 |
+
|
| 5 |
+
# Initialize chat history
|
| 6 |
+
if "messages" not in st.session_state:
|
| 7 |
+
st.session_state.messages = []
|
| 8 |
+
|
| 9 |
+
# Display chat messages from history on app rerun
|
| 10 |
+
for message in st.session_state.messages:
|
| 11 |
+
with st.chat_message(message["role"]):
|
| 12 |
+
st.markdown(message["content"])
|
| 13 |
+
|
| 14 |
+
# React to user input
|
| 15 |
+
if prompt := st.chat_input("What is up?"):
|
| 16 |
+
# Display user message in chat message container
|
| 17 |
+
st.chat_message("user").markdown(prompt)
|
| 18 |
+
# Add user message to chat history
|
| 19 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 20 |
+
|
| 21 |
+
response = f"Echo: {prompt}"
|
| 22 |
+
# Display assistant response in chat message container
|
| 23 |
+
with st.chat_message("assistant"):
|
| 24 |
+
st.markdown(response)
|
| 25 |
+
# Add assistant response to chat history
|
| 26 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|