ToluClassics commited on
Commit
8f5172c
1 Parent(s): 1f8935a

Add application file

Browse files
Files changed (2) hide show
  1. .streamlit/config.toml +6 -0
  2. app.py +20 -9
.streamlit/config.toml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ [theme]
2
+ primaryColor="#F63366"
3
+ backgroundColor="#FFFFFF"
4
+ secondaryBackgroundColor="#F0F2F6"
5
+ textColor="#262730"
6
+ font="sans serif"
app.py CHANGED
@@ -10,7 +10,7 @@ import streamlit as st
10
  import streamlit.components.v1 as components
11
  import requests
12
 
13
-
14
  pp = pprint.PrettyPrinter(indent=2)
15
  st.set_page_config(page_title="Gaia Search", layout="wide")
16
 
@@ -67,13 +67,14 @@ unsafe_allow_html=True,
67
  query = st.sidebar.text_input(label='Search query', value='')
68
  language = st.sidebar.selectbox(
69
  'Language',
70
- ('Arabic', 'Catalan', 'Code', 'English', 'Spanish', 'French', 'Indonesian', 'Indic', 'Niger-Congo', 'Portuguese', 'Vietnamese', 'Chinese', 'Detect Language', 'All'))
 
71
  max_results = st.sidebar.slider(
72
  "Maximum Number of Results",
73
  min_value=1,
74
  max_value=100,
75
  step=1,
76
- value=1,
77
  help="Maximum Number of Documents to return",
78
  )
79
 
@@ -122,7 +123,7 @@ def scisearch(query, language, num_results=10):
122
 
123
  def highlight_string(paragraph: str, highlight_terms: list) -> str:
124
  for term in highlight_terms:
125
- paragraph = paragraph.replace(term, f"<mark>{term}</mark>")
126
  return paragraph
127
 
128
  def process_results(hits: list, highlight_terms: list) -> str:
@@ -141,18 +142,19 @@ def process_results(hits: list, highlight_terms: list) -> str:
141
  res_head += f"""
142
  <p>{highlight_string(hit['text'], highlight_terms)}</p>
143
  </div>
 
144
  """
145
  hit_list.append(res_head)
146
  return " ".join(hit_list)
147
 
148
 
149
  if st.sidebar.button("Search"):
150
- hits, highlight_terms = scisearch(query, LANG_MAPPING[language])
151
  html_results = process_results(hits, highlight_terms)
152
  rendered_results = f"""
153
  <div id="searchresultsarea">
154
  <br>
155
- <p id="searchresultsnumber">About 155,000 results (0.56 seconds) </p>
156
  {html_results}
157
  </div>
158
  """
@@ -182,7 +184,7 @@ if st.sidebar.button("Search"):
182
  """,
183
  unsafe_allow_html=True)
184
  components.html(
185
- """
186
  <style>
187
  #searchresultsarea {
188
  font-family: 'Arial';
@@ -197,7 +199,7 @@ if st.sidebar.button("Search"):
197
  font-size: 19px;
198
  line-height: 18px;
199
  font-weight: normal;
200
- color: rgb(29, 1, 189);
201
  margin-bottom: 0px;
202
  margin-top: 25px;
203
  }
@@ -218,7 +220,16 @@ if st.sidebar.button("Search"):
218
  border-width: 0px;
219
  background-color: white;
220
  }
221
-
 
 
 
222
  </style>
 
 
 
 
 
 
223
  """ + rendered_results, height=1000, scrolling=True
224
  )
 
10
  import streamlit.components.v1 as components
11
  import requests
12
 
13
+ os.environ["address"] = "http://34.79.83.149:8080"
14
  pp = pprint.PrettyPrinter(indent=2)
15
  st.set_page_config(page_title="Gaia Search", layout="wide")
16
 
 
67
  query = st.sidebar.text_input(label='Search query', value='')
68
  language = st.sidebar.selectbox(
69
  'Language',
70
+ ('Arabic', 'Catalan', 'Code', 'English', 'Spanish', 'French', 'Indonesian', 'Indic', 'Niger-Congo', 'Portuguese', 'Vietnamese', 'Chinese', 'Detect Language', 'All'),
71
+ index=3)
72
  max_results = st.sidebar.slider(
73
  "Maximum Number of Results",
74
  min_value=1,
75
  max_value=100,
76
  step=1,
77
+ value=10,
78
  help="Maximum Number of Documents to return",
79
  )
80
 
 
123
 
124
  def highlight_string(paragraph: str, highlight_terms: list) -> str:
125
  for term in highlight_terms:
126
+ paragraph = re.sub(f"\\b{term}\\b", f"<mark>{term}</mark>", paragraph, flags=re.I)
127
  return paragraph
128
 
129
  def process_results(hits: list, highlight_terms: list) -> str:
 
142
  res_head += f"""
143
  <p>{highlight_string(hit['text'], highlight_terms)}</p>
144
  </div>
145
+ <hr>
146
  """
147
  hit_list.append(res_head)
148
  return " ".join(hit_list)
149
 
150
 
151
  if st.sidebar.button("Search"):
152
+ hits, highlight_terms = scisearch(query, LANG_MAPPING[language], max_results)
153
  html_results = process_results(hits, highlight_terms)
154
  rendered_results = f"""
155
  <div id="searchresultsarea">
156
  <br>
157
+ <p id="searchresultsnumber">About {max_results} results</p>
158
  {html_results}
159
  </div>
160
  """
 
184
  """,
185
  unsafe_allow_html=True)
186
  components.html(
187
+ """
188
  <style>
189
  #searchresultsarea {
190
  font-family: 'Arial';
 
199
  font-size: 19px;
200
  line-height: 18px;
201
  font-weight: normal;
202
+ color: rgb(7, 111, 222);
203
  margin-bottom: 0px;
204
  margin-top: 25px;
205
  }
 
220
  border-width: 0px;
221
  background-color: white;
222
  }
223
+
224
+ .dark-mode {
225
+ color: white;
226
+ }
227
  </style>
228
+ <script>
229
+ function myFunction() {
230
+ var element = document.body;
231
+ element.classList.toggle("dark-mode");
232
+ }
233
+ </script>
234
  """ + rendered_results, height=1000, scrolling=True
235
  )