search_engine / app.py
InkarSaleshovaSDU's picture
added two button regulating prompts indexing and matching
25186de
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.')