File size: 1,152 Bytes
c78ae15 25186de c78ae15 25186de c78ae15 25186de c78ae15 25186de |
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 40 41 |
import streamlit as st
# initialize a search tool
if not 'model' in st.session_state:
st.session_state.model = SearchEngine()
st.title('Search ')
# render indexed prompts
st.write('---')
st.subheader('Indexed Prompts:')
if len(st.session_state.model.prompts) > 0: # if there are any prompts, proceed
for id, prompt in enumerate(st.session_state.model.prompts, 1):
st.info(f'{id}. {prompt}')
else: # if there are no prompts
st.write('No prompts yet.')
# render inputable prompt
st.write('---')
st.subheader('Input Prompt:')
input_prompt = st.text_area('Enter a prompt to save or match:', height=150)
# initialize two buttons
col1, col2 = st.columns(2)
with col1:
if st.button('Save', use_container_width=True): # it should add a new prompt to the model
st.session_state.model.add(input_prompt)
st.success('Saved successfully!')
st.rerun()
with col2:
if st.button('Match', use_container_width=True): # it should match a new prompt against others
if len(st.session_state.model.vectors) > 0:
match = st.session_state.model.search(input_prompt)
st.success(f'Result: {match}')
else:
st.warning('Nothing to match against.')
|