Spaces:
Running
Running
Commit
Β·
0de21f6
1
Parent(s):
21ba419
Update page1.py
Browse files
page1.py
CHANGED
@@ -8,40 +8,25 @@ from langchain.memory.chat_message_histories import StreamlitChatMessageHistory
|
|
8 |
from streamlit_chat import message
|
9 |
import time
|
10 |
def text():
|
11 |
-
st.
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
@keyframes blinkTextCursor {
|
31 |
-
from {
|
32 |
-
border-right-color: rgba(255, 255, 255, 0.75);
|
33 |
-
}
|
34 |
-
to {
|
35 |
-
border-right-color: transparent;
|
36 |
-
}
|
37 |
-
}
|
38 |
-
</style>
|
39 |
-
""", unsafe_allow_html=True)
|
40 |
-
text ="Hello π, how may I assist you today?"
|
41 |
-
animated_output = f'<div class="line-1 anim-typewriter">{text}</div>'
|
42 |
-
|
43 |
-
with st.chat_message("assistant").markdown(animated_output,unsafe_allow_html=True ):
|
44 |
-
st.markdown(animated_output,unsafe_allow_html=True)
|
45 |
apiKey = "AIzaSyAXkkcrrUBjPEgj93tZ9azy7zcS1wI1jUA"
|
46 |
msgs = StreamlitChatMessageHistory(key="special_app_key")
|
47 |
|
|
|
8 |
from streamlit_chat import message
|
9 |
import time
|
10 |
def text():
|
11 |
+
with st.chat_message("assistant"):
|
12 |
+
message_placeholder = st.empty()
|
13 |
+
full_response = ""
|
14 |
+
assistant_response = random.choice(
|
15 |
+
[
|
16 |
+
"Hello there! How can I assist you today?",
|
17 |
+
"Hi, human! Is there anything I can help you with?",
|
18 |
+
"Do you need help?"
|
19 |
+
]
|
20 |
+
)
|
21 |
+
# Simulate stream of response with milliseconds delay
|
22 |
+
for chunk in assistant_response.split():
|
23 |
+
full_response += chunk + " "
|
24 |
+
time.sleep(0.05)
|
25 |
+
# Add a blinking cursor to simulate typing
|
26 |
+
message_placeholder.markdown(full_response + "β")
|
27 |
+
message_placeholder.markdown(full_response)
|
28 |
+
# Add assistant response to chat history
|
29 |
+
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
apiKey = "AIzaSyAXkkcrrUBjPEgj93tZ9azy7zcS1wI1jUA"
|
31 |
msgs = StreamlitChatMessageHistory(key="special_app_key")
|
32 |
|