cakiki commited on
Commit
8c0cea8
β€’
1 Parent(s): 2517a1f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from pyserini.search.lucene import LuceneSearcher
3
+
4
+ st.set_page_config(
5
+ page_title="Reddit CMV",
6
+ page_icon="πŸ“„",
7
+ layout="centered"
8
+ )
9
+
10
+ indexes = {"shoe-sizes": LuceneSearcher("index/cmv'-shoe-sizes-should-be-the-same-for-both-men-and-women"),
11
+ "social-media": LuceneSearcher("index/cmv'-social-media-is-the-most-destructive-addiction-in-our-society"),
12
+ "depression": LuceneSearcher("index/cmv'-the-others-have-it-worse-argument-is-terrible-and-should-never-be-used-in-an-actual-conversation-with-a-depressed-person"),
13
+ "metric-system": LuceneSearcher("index/cmv'-there-shouldnt-be-anything-other-than-the-metric-system."),
14
+ "best-time-period": LuceneSearcher("index/cmv'-today-is-the-best-time-period-in-human-history-to-be-alive-for-the-vast-majority-of-people."),
15
+ }
16
+
17
+ @st.cache(suppress_st_warning=True, allow_output_mutation=True, show_spinner=False)
18
+ def search_chat_noir(key, search_query):
19
+ return search(api_key=key, query=search_query)
20
+
21
+ def result_html(result):
22
+ return (
23
+ f"<div>{(result.contents)}</div><br>"
24
+ )
25
+
26
+
27
+ discussion = st.selectbox(
28
+ 'How would you like to be contacted?',
29
+ indexes.keys())
30
+ searcher = indexes[discussion]
31
+ cola, colb, colc = st.columns([5,4,5])
32
+ with colb:
33
+ st.write(discussion)
34
+
35
+ col1, col2 = st.columns([9, 1])
36
+ with col1:
37
+ search_query = st.text_input(label="",
38
+ placeholder="Search"
39
+ )
40
+
41
+ with col2:
42
+ st.write('#')
43
+ button_clicked = st.button("πŸ”Ž")
44
+
45
+
46
+ if search_query or button_clicked:
47
+ search_results = searcher.search(query, k=10)
48
+ for result in search_results:
49
+ st.write(result_html(result), unsafe_allow_html=True)
50
+
51
+ with st.expander("Instructions", expanded=False):
52
+ st.markdown(
53
+ """
54
+ INSTRUCTIONS HERE
55
+ """
56
+ )