moazzamdev commited on
Commit
63ab6be
·
1 Parent(s): 6a7d54f

Update page1.py

Browse files
Files changed (1) hide show
  1. page1.py +34 -21
page1.py CHANGED
@@ -9,27 +9,40 @@ from streamlit_chat import message
9
  import time
10
  import random
11
  def text():
12
- if 'messages' not in st.session_state:
13
- st.session_state['messages'] = []
14
- with st.chat_message("assistant"):
15
- message_placeholder = st.empty()
16
- full_response = ""
17
- assistant_response = random.choice(
18
- [
19
- "Hello👋 there! How can I assist you today?",
20
- "Hi , human! Is there anything I can help you with?",
21
-
22
- ]
23
- )
24
- # Simulate stream of response with milliseconds delay
25
- for chunk in assistant_response.split():
26
- full_response += chunk + " "
27
- time.sleep(0.5)
28
- # Add a blinking cursor to simulate typing
29
- message_placeholder.markdown(full_response + "▌")
30
- #message_placeholder.markdown(full_response)
31
- # Add assistant response to chat history
32
- st.session_state.messages.append({"role": "assistant", "content": full_response})
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  apiKey = "AIzaSyAXkkcrrUBjPEgj93tZ9azy7zcS1wI1jUA"
34
  msgs = StreamlitChatMessageHistory(key="special_app_key")
35
 
 
9
  import time
10
  import random
11
  def text():
12
+ st.markdown("""
13
+ <style>
14
+ .anim-typewriter {
15
+ animation: typewriter 3s steps(40) 1s 1 normal both, blinkTextCursor 800ms steps(40) infinite normal;
16
+ overflow: hidden;
17
+ white-space: nowrap;
18
+ border-right: 3px solid;
19
+ font-family: serif;
20
+ font-size: 0.9em;
21
+ }
22
+ @keyframes typewriter {
23
+ from {
24
+ width: 0;
25
+ }
26
+ to {
27
+ width: 100%;
28
+ height: 100%
29
+ }
30
+ }
31
+ @keyframes blinkTextCursor {
32
+ from {
33
+ border-right-color: rgba(255, 255, 255, 0.75);
34
+ }
35
+ to {
36
+ border-right-color: transparent;
37
+ }
38
+ }
39
+ </style>
40
+ """, unsafe_allow_html=True)
41
+ text ="Hello 👋, how may I assist you today?"
42
+ animated_output = f'<div class="line-1 anim-typewriter">{text}</div>'
43
+
44
+ with st.chat_message("assistant").markdown(animated_output,unsafe_allow_html=True ):
45
+ st.markdown(animated_output,unsafe_allow_html=True)
46
  apiKey = "AIzaSyAXkkcrrUBjPEgj93tZ9azy7zcS1wI1jUA"
47
  msgs = StreamlitChatMessageHistory(key="special_app_key")
48