-
Notifications
You must be signed in to change notification settings - Fork 3
/
common_functions_WUI.py
39 lines (32 loc) · 1.37 KB
/
common_functions_WUI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import common_functions as cf
import streamlit as st
def get_runid():
if 'webui_runid' not in st.session_state:
st.session_state['webui_runid'] = cf.get_timeUTC()
runid = st.session_state['webui_runid']
return runid
#####
def show_history(hist, allow_history_deletion, last_prompt_key, last_query_key):
hk = [x for x in hist.keys() if cf.isNotBlank(x)]
hk = sorted(hk, reverse=True)
hk_opt = [hist[x][0] for x in hk]
hk_q = {hist[x][0]: hist[x][1] for x in hk}
prev = st.selectbox("Prompt History (most recent first)", options=hk_opt, index=0, key="history")
if st.button("Load Selected Prompt", key="load_history"):
st.session_state[last_prompt_key] = prev
st.session_state[last_query_key] = hk_q[prev]
if allow_history_deletion:
if st.button("Delete Selected Prompt", key="delete_history"):
if cf.isNotBlank(prev):
dir = os.path.dirname(hk_q[prev])
err = cf.directory_rmtree(dir)
if cf.isNotBlank(err):
st.error(f"While deleting {dir}: {err}")
else:
if os.path.exists(dir):
st.error(f"Directory {dir} still exists")
else:
st.success(f"Deleted")
else:
st.error("Please select a prompt to delete")