reddit-cmv / app.py
cakiki's picture
Update app.py
dd2d5d0
raw
history blame
2.26 kB
import streamlit as st
from pyserini.search.lucene import LuceneSearcher
st.set_page_config(
page_title="Reddit CMV",
page_icon="πŸ“„",
layout="centered"
)
index_locations = {"shoe-sizes": "index/cmv'-shoe-sizes-should-be-the-same-for-both-men-and-women",
"social-media": "index/cmv'-social-media-is-the-most-destructive-addiction-in-our-society",
"depression": "index/cmv'-the-others-have-it-worse-argument-is-terrible-and-should-never-be-used-in-an-actual-conversation-with-a-depressed-person",
"metric-system": "index/cmv'-there-shouldnt-be-anything-other-than-the-metric-system.",
"best-time-period": "index/cmv'-today-is-the-best-time-period-in-human-history-to-be-alive-for-the-vast-majority-of-people.",
}
titles = {"shoe-sizes": "Shoes sizes should be the same for both men and women",
"social-media": "Social Media is the most destructive addiction in our society",
"depression": "'The others have it worse' argument is terrible and should never be used in an actual conversation with a depressed person",
"metric-system": "There shouldn't be anything other than the metric system",
"best-time-period": "Today is the best time period in human history to be alive for the vast majority of people",
}
def result_html(result):
return (
f"<div style=\"color:#2a5cb3;font-weight: 500\">{(result.docid)}</div>"
f"<div>{(result.contents)}</div><hr><br>"
)
discussion = st.selectbox(
'Choose discussion',
index_locations.keys())
searcher = LuceneSearcher(index_locations[discussion])
searcher.set_rm3()
cola, colb, colc = st.columns([5,4,5])
with colb:
st.write(titles[discussion])
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:
search_results = searcher.search(search_query, k=10)
for result in search_results:
st.write(result_html(result), unsafe_allow_html=True)
with st.expander("Instructions", expanded=False):
st.markdown(
"""
INSTRUCTIONS HERE
"""
)