Update app.py
Browse files
app.py
CHANGED
@@ -457,7 +457,7 @@ if __name__ == '__main__':
|
|
457 |
if 'id_chat' not in st.session_state:
|
458 |
st.session_state.id_chat = 'New Chat'
|
459 |
|
460 |
-
def options_list():
|
461 |
if st.session_state.id_chat == 'New Chat':
|
462 |
return [st.session_state.id_chat] + list(conversations.keys())
|
463 |
else:
|
@@ -465,10 +465,10 @@ if __name__ == '__main__':
|
|
465 |
|
466 |
with st.sidebar:
|
467 |
print('SELECTBOX')
|
468 |
-
print(st.session_state.id_chat
|
469 |
st.session_state.id_chat = st.selectbox(
|
470 |
label='Choose a conversation',
|
471 |
-
options=options_list(),
|
472 |
index=0,
|
473 |
placeholder='_',
|
474 |
key='chat_id'
|
@@ -476,43 +476,21 @@ if __name__ == '__main__':
|
|
476 |
|
477 |
st.session_state.messages = conversations[st.session_state.id_chat] if st.session_state.id_chat != 'New Chat' else []
|
478 |
|
479 |
-
def update_selectbox_remove():
|
480 |
-
|
481 |
-
|
482 |
-
if len(list(conversations.keys())) < 2:
|
483 |
-
st.session_state.chat_id = 'New Chat'
|
484 |
-
st.session_state.messages = []
|
485 |
-
else:
|
486 |
-
for conversation in list(conversations.keys()):
|
487 |
-
if conversation != conversations[st.session_state.chat_id]:
|
488 |
-
st.session_state.chat_id = conversation
|
489 |
-
break
|
490 |
-
|
491 |
-
conversations.pop(tmp)
|
492 |
with open(conversations_path, 'wb') as fp:
|
493 |
packed_bytes = msgpack.packb(conversations, use_bin_type=True)
|
494 |
fp.write(packed_bytes)
|
|
|
495 |
|
496 |
|
497 |
-
|
498 |
'Delete Chat',
|
499 |
use_container_width=True,
|
500 |
-
disabled=False if st.session_state.id_chat != 'New Chat' else True
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
if len(list(conversations.keys())) < 2:
|
505 |
-
st.session_state.id_chat = 'New Chat'
|
506 |
-
else:
|
507 |
-
for conversation in list(conversations.keys()):
|
508 |
-
if conversation != conversations[st.session_state.id_chat]:
|
509 |
-
st.session_state.id_chat = conversation
|
510 |
-
break
|
511 |
-
|
512 |
-
conversations.pop(tmp)
|
513 |
-
with open(conversations_path, 'wb') as fp:
|
514 |
-
packed_bytes = msgpack.packb(conversations, use_bin_type=True)
|
515 |
-
fp.write(packed_bytes)
|
516 |
|
517 |
def generate_conv_title(llm: vllm.LLM, tokenizer: AutoTokenizer):
|
518 |
if st.session_state.chat_id == 'New Chat':
|
|
|
457 |
if 'id_chat' not in st.session_state:
|
458 |
st.session_state.id_chat = 'New Chat'
|
459 |
|
460 |
+
def options_list(conversations: Dict[str, list]):
|
461 |
if st.session_state.id_chat == 'New Chat':
|
462 |
return [st.session_state.id_chat] + list(conversations.keys())
|
463 |
else:
|
|
|
465 |
|
466 |
with st.sidebar:
|
467 |
print('SELECTBOX')
|
468 |
+
print(st.session_state.id_chat
|
469 |
st.session_state.id_chat = st.selectbox(
|
470 |
label='Choose a conversation',
|
471 |
+
options=options_list(conversations),
|
472 |
index=0,
|
473 |
placeholder='_',
|
474 |
key='chat_id'
|
|
|
476 |
|
477 |
st.session_state.messages = conversations[st.session_state.id_chat] if st.session_state.id_chat != 'New Chat' else []
|
478 |
|
479 |
+
def update_selectbox_remove(conversations_path, conversations):
|
480 |
+
conversations.pop(st.session_state.chat_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
481 |
with open(conversations_path, 'wb') as fp:
|
482 |
packed_bytes = msgpack.packb(conversations, use_bin_type=True)
|
483 |
fp.write(packed_bytes)
|
484 |
+
st.session_state.chat_id = 'New Chat'
|
485 |
|
486 |
|
487 |
+
st.button(
|
488 |
'Delete Chat',
|
489 |
use_container_width=True,
|
490 |
+
disabled=False if st.session_state.id_chat != 'New Chat' else True,
|
491 |
+
on_click=update_selectbox_remove,
|
492 |
+
args=(conversations_path, conversations)
|
493 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
494 |
|
495 |
def generate_conv_title(llm: vllm.LLM, tokenizer: AutoTokenizer):
|
496 |
if st.session_state.chat_id == 'New Chat':
|