carolinefrascasnowflake commited on
Commit
38e18ec
1 Parent(s): baafb8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -12,6 +12,9 @@ from transformers import AutoTokenizer
12
 
13
  # print("Number of tokens:", num_tokens)
14
 
 
 
 
15
  # App title
16
  st.set_page_config(page_title="Snowflake Arctic")
17
 
@@ -40,16 +43,16 @@ if "messages" not in st.session_state.keys():
40
 
41
  # Display or clear chat messages
42
  for message in st.session_state.messages:
43
- with st.chat_message(message["role"]):
44
  st.write(message["content"])
45
 
46
  def clear_chat_history():
47
  st.session_state.messages = [{"role": "assistant", "content": "Hi. I'm Arctic, a new, efficient, intelligent, and truly open language model created by Snowflake AI Research. Ask me anything."}]
48
  st.sidebar.button('Clear chat history', on_click=clear_chat_history)
49
 
50
- st.sidebar.caption('Built by [Snowflake](https://snowflake.com/) to demonstrate [Snowflake Arctic](https://www.snowflake.com/blog/arctic-open-and-efficient-foundation-language-models-snowflake).')
51
 
52
- @st.cache_resource
53
  def get_tokenizer():
54
  """Get a tokenizer to make sure we're not sending too much text
55
  text to the Model. Eventually we will replace this with ArcticTokenizer
@@ -91,12 +94,12 @@ def generate_arctic_response():
91
  # User-provided prompt
92
  if prompt := st.chat_input(disabled=not replicate_api):
93
  st.session_state.messages.append({"role": "user", "content": prompt})
94
- with st.chat_message("user"):
95
  st.write(prompt)
96
 
97
  # Generate a new response if last message is not from assistant
98
  if st.session_state.messages[-1]["role"] != "assistant":
99
- with st.chat_message("assistant"):
100
  response = generate_arctic_response()
101
  full_response = st.write_stream(response)
102
  message = {"role": "assistant", "content": full_response}
 
12
 
13
  # print("Number of tokens:", num_tokens)
14
 
15
+ # Set assistant icon to Snowflake logo
16
+ icons = {"assistant": "./Snowflake_Logomark_blue.svg", "user": "⛷️"}
17
+
18
  # App title
19
  st.set_page_config(page_title="Snowflake Arctic")
20
 
 
43
 
44
  # Display or clear chat messages
45
  for message in st.session_state.messages:
46
+ with st.chat_message(message["role"], avatar=icons[message["role"]]):
47
  st.write(message["content"])
48
 
49
  def clear_chat_history():
50
  st.session_state.messages = [{"role": "assistant", "content": "Hi. I'm Arctic, a new, efficient, intelligent, and truly open language model created by Snowflake AI Research. Ask me anything."}]
51
  st.sidebar.button('Clear chat history', on_click=clear_chat_history)
52
 
53
+ st.sidebar.caption('Built by [Snowflake](https://snowflake.com/) to demonstrate [Snowflake Arctic](https://www.snowflake.com/blog/arctic-open-and-efficient-foundation-language-models-snowflake). App hosted on [Streamlit Community Cloud](https://streamlit.io/cloud). Model hosted by [Replicate](https://replicate.com/snowflake/snowflake-arctic-instruct).')
54
 
55
+ @st.cache_resource(show_spinner=False)
56
  def get_tokenizer():
57
  """Get a tokenizer to make sure we're not sending too much text
58
  text to the Model. Eventually we will replace this with ArcticTokenizer
 
94
  # User-provided prompt
95
  if prompt := st.chat_input(disabled=not replicate_api):
96
  st.session_state.messages.append({"role": "user", "content": prompt})
97
+ with st.chat_message("user", avatar="⛷️"):
98
  st.write(prompt)
99
 
100
  # Generate a new response if last message is not from assistant
101
  if st.session_state.messages[-1]["role"] != "assistant":
102
+ with st.chat_message("assistant", avatar="./Snowflake_Logomark_blue.svg"):
103
  response = generate_arctic_response()
104
  full_response = st.write_stream(response)
105
  message = {"role": "assistant", "content": full_response}