fix: missing translation

pull/6/head
sean1832 1 year ago
parent ee53478aa2
commit 9e91b7dcd7

@ -14,7 +14,6 @@ if 'SESSION_TIME' not in st.session_state:
if 'SESSION_LANGUAGE' not in st.session_state:
st.session_state['SESSION_LANGUAGE'] = util.read_json_at('.user/language.json', 'SESSION_LANGUAGE', 'en_US')
st.set_page_config(
page_title='Seanium Brain'
)
@ -31,6 +30,7 @@ CURRENT_LOG_FILE = f'{LOG_PATH}/log_{SESSION_TIME}.log'
BRAIN_MEMO = '.user/brain-memo.json'
MANIFEST = '.core/manifest.json'
def create_log():
if not os.path.exists(CURRENT_LOG_FILE):
util.write_file(f'Session {SESSION_TIME}\n\n', CURRENT_LOG_FILE)
@ -86,20 +86,20 @@ def process_response(query, target_model, prompt_file: str, data: model_data.par
# sidebar
with st.sidebar:
st.title('Settings')
language.select_language()
_ = language.set_language()
st.title(_('Settings'))
language.select_language()
prompt_files = util.scan_directory(PROMPT_PATH)
prompt_file_names = [util.get_file_name(file) for file in prompt_files]
prompt_dictionary = dict(zip(prompt_file_names, prompt_files))
# remove 'my-info' from prompt dictionary
prompt_dictionary.pop(_('my-info'))
prompt_dictionary.pop('my-info')
operation_options = list(prompt_dictionary.keys())
operations = st.multiselect(_('Operations'), operation_options, default=util.read_json_at(BRAIN_MEMO, 'operations',
operation_options[0]))
operation_options[0]))
last_question_model = util.read_json_at(BRAIN_MEMO, 'question_model', model_options[0])
# get index of last question model
@ -113,7 +113,7 @@ with st.sidebar:
last_model = util.read_json_at(BRAIN_MEMO, f'{operation}_model', model_options[0])
# get index of last model
model_index = util.get_index(model_options, last_model)
model = st.selectbox(f"{operation} {_('Model')}", model_options, index=model_index)
model = st.selectbox(f"{operation} " + _('Model'), model_options, index=model_index)
other_models.append(model)
temp = st.slider(_('Temperature'), 0.0, 1.0, value=util.read_json_at(BRAIN_MEMO, 'temp', 0.1))
@ -123,7 +123,8 @@ with st.sidebar:
top_p = st.slider('Top_P', 0.0, 1.0, value=util.read_json_at(BRAIN_MEMO, 'top_p', 1.0))
freq_panl = st.slider(_('Frequency penalty'), 0.0, 1.0,
value=util.read_json_at(BRAIN_MEMO, 'frequency_penalty', 0.0))
pres_panl = st.slider(_('Presence penalty'), 0.0, 1.0, value=util.read_json_at(BRAIN_MEMO, 'present_penalty', 0.0))
pres_panl = st.slider(_('Presence penalty'), 0.0, 1.0,
value=util.read_json_at(BRAIN_MEMO, 'present_penalty', 0.0))
chunk_size = st.slider(_('Chunk size'), 1500, 4500, value=util.read_json_at(BRAIN_MEMO, 'chunk_size', 4000))
chunk_count = st.slider(_('Answer count'), 1, 5, value=util.read_json_at(BRAIN_MEMO, 'chunk_count', 1))
@ -142,14 +143,14 @@ with st.sidebar:
# info
st.markdown('---')
st.markdown(f"# {util.read_json_at(MANIFEST, 'name')}")
st.markdown(f"{_('version')}: {util.read_json_at(MANIFEST, 'version')}")
st.markdown(f"{_('author')}: {util.read_json_at(MANIFEST, 'author')}")
st.markdown(f"[{_('Report bugs')}]({util.read_json_at(MANIFEST, 'bugs')})")
st.markdown(f"[{_('Github Repo')}]({util.read_json_at(MANIFEST, 'homepage')})")
st.markdown(_('version') + f": {util.read_json_at(MANIFEST, 'version')}")
st.markdown(_('author') + f": {util.read_json_at(MANIFEST, 'author')}")
st.markdown("[" + _('Report bugs') + "]" + f"({util.read_json_at(MANIFEST, 'bugs')})")
st.markdown("[" + _('Github Repo') + "]" + f"({util.read_json_at(MANIFEST, 'homepage')})")
with header:
st.title(_('🧠Seanium Brain'))
st.text('This is my personal AI powered brain feeding my own Obsidian notes. Ask anything.')
st.title(_('🧠GPT-Brain'))
st.text(_('This is my personal AI powered brain feeding my own Obsidian notes. Ask anything.'))
def execute_brain(q):
@ -210,4 +211,4 @@ with body:
save_as()
# execute brain calculation
if not question == '' and send:
execute_brain(question)
execute_brain(question)

@ -201,115 +201,114 @@ def main():
])
with body:
match menu:
case _('📝Prompts'):
st.title(_('📝Prompts'))
st.text(_('Configuration of prompts.'))
# read selected file
last_sel_file = util.read_json_at(brain_memo, 'selected_prompt')
all_files = os.listdir(prompt_dir)
# sort files base on creation time
all_files.sort(key=lambda x: os.path.getmtime(f'{prompt_dir}{x}'), reverse=True)
# index of last selected file
try:
last_sel_file_index = all_files.index(last_sel_file)
except ValueError:
last_sel_file_index = 0
selected_file = st.selectbox(_('Prompt File'), all_files, last_sel_file_index)
col1, col2 = st.columns(2)
with col1:
if st_toggle.st_toggle_switch(_('New Prompt'), label_after=True):
new_file = st.text_input(_('New Prompt Name'), value='new_prompt')
if st.button(_('Create')):
util.write_file('', f'{prompt_dir}{new_file}.txt')
# change select file to new fie
util.update_json(brain_memo, 'selected_prompt', selected_file)
if menu == _('📝Prompts'):
st.title(_('📝Prompts'))
st.text(_('Configuration of prompts.'))
# read selected file
last_sel_file = util.read_json_at(brain_memo, 'selected_prompt')
all_files = os.listdir(prompt_dir)
# sort files base on creation time
all_files.sort(key=lambda x: os.path.getmtime(f'{prompt_dir}{x}'), reverse=True)
# index of last selected file
try:
last_sel_file_index = all_files.index(last_sel_file)
except ValueError:
last_sel_file_index = 0
selected_file = st.selectbox(_('Prompt File'), all_files, last_sel_file_index)
col1, col2 = st.columns(2)
with col1:
if st_toggle.st_toggle_switch(_('New Prompt'), label_after=True):
new_file = st.text_input(_('New Prompt Name'), value='new_prompt')
if st.button(_('Create')):
util.write_file('', f'{prompt_dir}{new_file}.txt')
# change select file to new fie
util.update_json(brain_memo, 'selected_prompt', selected_file)
# refresh page
st.experimental_rerun()
with col2:
is_core = selected_file == 'my-info.txt' or \
selected_file == 'question.txt' or \
selected_file == 'summarize.txt'
if not is_core:
if st_toggle.st_toggle_switch(_('Delete Prompt'), label_after=True):
if st.button(_('❌Delete')):
util.delete_file(f'{prompt_dir}{selected_file}')
# refresh page
st.experimental_rerun()
with col2:
is_core = selected_file == 'my-info.txt' or \
selected_file == 'question.txt' or \
selected_file == 'summarize.txt'
if not is_core:
if st_toggle.st_toggle_switch(_('Delete Prompt'), label_after=True):
if st.button(_('❌Delete')):
util.delete_file(f'{prompt_dir}{selected_file}')
# refresh page
st.experimental_rerun()
selected_path = prompt_dir + selected_file
mod_text = st.text_area(_('Prompts'), value=util.read_file(selected_path), height=500)
save(mod_text, selected_path)
case _('💽Brain Memory'):
st.title(_('💽Brain Memory'))
st.text(_('Modify your brain knowledge base.'))
memory_data = util.read_file(f'{user_dir}input.txt')
col1, col2 = st.columns(2)
with col1:
st.button(_('🔄Refresh'))
with col2:
if st.button(_('📁Select Note Directory')):
note_dir = select_directory()
util.update_json(brain_memo, 'note_dir', note_dir)
note_dir = st.text_input(_('Note Directory'), value=util.read_json_at(brain_memo, 'note_dir'),
placeholder=_('Select Note Directory'), key='note_dir')
col1, col2, col3, col4 = st.columns([1, 2, 2, 2])
with col1:
delimiter_memo = util.read_json_at(brain_memo, 'delimiter')
delimiter = st.text_input(_('Delimiter'), delimiter_memo, placeholder='e.g. +++')
with col2:
append_mode = st.checkbox(_('Append Mode'), value=util.read_json_at(brain_memo, 'append_mode'))
force_delimiter = st.checkbox(_('Force Delimiter'),
value=util.read_json_at(brain_memo, 'force_mode'))
with col3:
advanced_mode = st_toggle.st_toggle_switch(_('Filter Mode'),
label_after=True,
default_value=util.read_json_at(brain_memo,
'advanced_mode', False))
with col4:
if advanced_mode:
add_filter_button = st.button(_('Add Filter'))
del_filter_button = st.button(_('Delete Filter'))
# if note directory is selected
if note_dir != '':
# if advanced mode enabled
if advanced_mode:
note_datas = util.read_files(note_dir, single_string=False)
note_datas, filter_info = filter_data(note_datas, add_filter_button, del_filter_button)
# note_datas, filter_key, filter_logic, filter_val = filter_data(note_datas, True)
modified_data = util.parse_data(note_datas, delimiter, force_delimiter)
else:
modified_data = util.read_files(note_dir, single_string=True, delimiter=delimiter,
force=force_delimiter)
if append_mode:
memory_data += modified_data
else:
memory_data = modified_data
mod_text = st.text_area(_('Raw Memory Inputs'), value=memory_data, height=500)
save(mod_text, f'{user_dir}input.txt', _('💽Brain Memory'), {
'delimiter': delimiter,
'append_mode': append_mode,
'force_mode': force_delimiter,
'advanced_mode': advanced_mode,
'filter_info': filter_info,
'filter_row_count': len(filter_info),
})
case _('🔑API Keys'):
st.title(_('🔑API Keys'))
st.text(_('Configure your OpenAI API keys.'))
mod_text = st.text_input(_('API Keys'), value=util.read_file(f'{user_dir}API-KEYS.txt'))
save(mod_text, f'{user_dir}API-KEYS.txt')
selected_path = prompt_dir + selected_file
mod_text = st.text_area(_('Prompts'), value=util.read_file(selected_path), height=500)
save(mod_text, selected_path)
if menu == _('💽Brain Memory'):
st.title(_('💽Brain Memory'))
st.text(_('Modify your brain knowledge base.'))
memory_data = util.read_file(f'{user_dir}input.txt')
col1, col2 = st.columns(2)
with col1:
st.button(_('🔄Refresh'))
with col2:
if st.button(_('📁Select Note Directory')):
note_dir = select_directory()
util.update_json(brain_memo, 'note_dir', note_dir)
note_dir = st.text_input(_('Note Directory'), value=util.read_json_at(brain_memo, 'note_dir'),
placeholder=_('Select Note Directory'), key='note_dir')
col1, col2, col3, col4 = st.columns([1, 2, 2, 2])
with col1:
delimiter_memo = util.read_json_at(brain_memo, 'delimiter')
delimiter = st.text_input(_('Delimiter'), delimiter_memo, placeholder='e.g. +++')
with col2:
append_mode = st.checkbox(_('Append Mode'), value=util.read_json_at(brain_memo, 'append_mode'))
force_delimiter = st.checkbox(_('Force Delimiter'),
value=util.read_json_at(brain_memo, 'force_mode'))
with col3:
advanced_mode = st_toggle.st_toggle_switch(_('Filter Mode'),
label_after=True,
default_value=util.read_json_at(brain_memo,
'advanced_mode', False))
with col4:
if advanced_mode:
add_filter_button = st.button(_('Add Filter'))
del_filter_button = st.button(_('Delete Filter'))
# if note directory is selected
if note_dir != '':
# if advanced mode enabled
if advanced_mode:
note_datas = util.read_files(note_dir, single_string=False)
note_datas, filter_info = filter_data(note_datas, add_filter_button, del_filter_button)
# note_datas, filter_key, filter_logic, filter_val = filter_data(note_datas, True)
modified_data = util.parse_data(note_datas, delimiter, force_delimiter)
else:
modified_data = util.read_files(note_dir, single_string=True, delimiter=delimiter,
force=force_delimiter)
if append_mode:
memory_data += modified_data
else:
memory_data = modified_data
mod_text = st.text_area(_('Raw Memory Inputs'), value=memory_data, height=500)
save(mod_text, f'{user_dir}input.txt', _('💽Brain Memory'), {
'delimiter': delimiter,
'append_mode': append_mode,
'force_mode': force_delimiter,
'advanced_mode': advanced_mode,
'filter_info': filter_info,
'filter_row_count': len(filter_info),
})
if menu == _('🔑API Keys'):
st.title(_('🔑API Keys'))
st.text(_('Configure your OpenAI API keys.'))
mod_text = st.text_input(_('API Keys'), value=util.read_file(f'{user_dir}API-KEYS.txt'))
save(mod_text, f'{user_dir}API-KEYS.txt')
if __name__ == '__main__':

Loading…
Cancel
Save