glabred commited on
Commit
1aee0b0
1 Parent(s): 8d79148

space for iphone users

Browse files
Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -22,6 +22,8 @@ if BASE_URL is None:
22
  if DATABRICKS_API_TOKEN is None:
23
  raise ValueError("DATABRICKS_API_TOKEN environment variable must be set")
24
 
 
 
25
  # by default safety filter is not configured
26
  SAFETY_FILTER = False
27
  if SAFETY_FILTER_ENV is not None:
@@ -53,7 +55,6 @@ if TOKEN_CHUNK_SIZE_ENV is not None:
53
  TOKEN_CHUNK_SIZE = int(TOKEN_CHUNK_SIZE_ENV)
54
 
55
  MODEL_AVATAR_URL= "./icon.png"
56
- st.set_page_config(layout="wide")
57
 
58
  @st.cache_resource
59
  def get_global_semaphore():
@@ -219,23 +220,8 @@ def chat_completion(messages):
219
  max_token_warning = MSG_CLIPPED_AT_MAX_OUT_TOKENS
220
 
221
  yield {"content": partial_message, "error": None, "warning": max_token_warning}
222
-
223
  # if assistant is the last message, we need to prompt the user
224
  # if user is the last message, we need to retry the assistant.
225
- history = st.container(height=420)
226
- with history:
227
- for message in st.session_state["messages"]:
228
- avatar = None
229
- if message["role"] == "assistant":
230
- avatar = MODEL_AVATAR_URL
231
- with st.chat_message(message["role"],avatar=avatar):
232
- if message["content"] is not None:
233
- st.markdown(message["content"])
234
- if message["error"] is not None:
235
- st.error(message["error"],icon="🚨")
236
- if message["warning"] is not None:
237
- st.warning(message["warning"],icon="⚠️")
238
-
239
  def handle_user_input(user_input):
240
  with history:
241
  response, stream_warning, stream_error = [None, None, None]
@@ -253,14 +239,29 @@ def handle_user_input(user_input):
253
 
254
  st.session_state["messages"].append({"role": "assistant", "content": response, "warning": stream_warning,"error": stream_error})
255
  print(st.session_state["messages"])
256
-
257
-
258
- if prompt := st.chat_input("Type a message!", max_chars=1000):
259
- handle_user_input(prompt)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
 
261
  with st.sidebar:
262
  with st.container():
263
  st.title("Examples")
264
  for prompt in EXAMPLE_PROMPTS:
265
  st.button(prompt, args=(prompt,), on_click=handle_user_input)
266
-
 
22
  if DATABRICKS_API_TOKEN is None:
23
  raise ValueError("DATABRICKS_API_TOKEN environment variable must be set")
24
 
25
+ st.set_page_config(layout="wide")
26
+
27
  # by default safety filter is not configured
28
  SAFETY_FILTER = False
29
  if SAFETY_FILTER_ENV is not None:
 
55
  TOKEN_CHUNK_SIZE = int(TOKEN_CHUNK_SIZE_ENV)
56
 
57
  MODEL_AVATAR_URL= "./icon.png"
 
58
 
59
  @st.cache_resource
60
  def get_global_semaphore():
 
220
  max_token_warning = MSG_CLIPPED_AT_MAX_OUT_TOKENS
221
 
222
  yield {"content": partial_message, "error": None, "warning": max_token_warning}
 
223
  # if assistant is the last message, we need to prompt the user
224
  # if user is the last message, we need to retry the assistant.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
  def handle_user_input(user_input):
226
  with history:
227
  response, stream_warning, stream_error = [None, None, None]
 
239
 
240
  st.session_state["messages"].append({"role": "assistant", "content": response, "warning": stream_warning,"error": stream_error})
241
  print(st.session_state["messages"])
242
+
243
+ main = st.container()
244
+ with main:
245
+ history = st.container(height=400)
246
+ with history:
247
+ for message in st.session_state["messages"]:
248
+ avatar = None
249
+ if message["role"] == "assistant":
250
+ avatar = MODEL_AVATAR_URL
251
+ with st.chat_message(message["role"],avatar=avatar):
252
+ if message["content"] is not None:
253
+ st.markdown(message["content"])
254
+ if message["error"] is not None:
255
+ st.error(message["error"],icon="🚨")
256
+ if message["warning"] is not None:
257
+ st.warning(message["warning"],icon="⚠️")
258
+
259
+ if prompt := st.chat_input("Type a message!", max_chars=1000):
260
+ handle_user_input(prompt)
261
+ st.markdown("\n") #add some space for iphone users
262
 
263
  with st.sidebar:
264
  with st.container():
265
  st.title("Examples")
266
  for prompt in EXAMPLE_PROMPTS:
267
  st.button(prompt, args=(prompt,), on_click=handle_user_input)