pyserini-demo / app.py
cakiki's picture
Create new file
b8705b2
raw
history blame
1.33 kB
import streamlit as st
from whoosh.index import create_in, open_dir
from whoosh.qparser import QueryParser
st.set_page_config(page_title="Pyserini x Datasets", page_icon='🌸', layout="centered")
cola, colb, colc = st.columns([5,4,5])
with colb:
st.image("logo.png")
col1, col2 = st.columns([9, 1])
with col1:
search_query = st.text_input(label="", placeholder="Search")
with col2:
st.write('#')
button_clicked = st.button("🔎")
if search_query or button_clicked:
myquery = parser.parse(search_query)
num_results = None
#search_results = searcher.search(myquery, limit=num_results)
st.write(f"<p align=\"right\" style=\"color:grey;\">Retrieved {len(search_results):,.0f} documents in {search_results.runtime*1000:.2f} ms</p>", unsafe_allow_html=True)
for result in search_results[:10]:
#keywords = ', '.join(result.key_terms('text'))
#meta = result['meta']
#st.write(f"<b>Document Keywords</b>: {keywords}", unsafe_allow_html=True)
#st.write(f"<b>Meta Field</b>: {meta}", unsafe_allow_html=True)
try:
st.write(result.highlights('text'), unsafe_allow_html=True)
except:
pass
with st.expander("Document Text", expanded=False):
st.write(result['text'][:1600])
st.write('---')