annikwag commited on
Commit
3f65b01
verified
1 Parent(s): 48a7195

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -44
app.py CHANGED
@@ -162,10 +162,6 @@ if button:
162
  # Check user preference
163
  if show_exact_matches:
164
  st.write(f"Showing **Top 10 Lexical Search results** for query: {var}")
165
-
166
- if not filtered_semantic_no_dupe:
167
- st.write("No relevant results found.")
168
- else:
169
  # Show the top 10 from filtered_lexical
170
  for res in filtered_lexical_no_dupe[:10]:
171
  project_name = res.payload['metadata'].get('project_name', 'Project Link')
@@ -208,46 +204,50 @@ if button:
208
  st.divider()
209
  else:
210
  st.write(f"Showing **Top 10 Semantic Search results** for query: {var}")
211
- # Show the top 10 from filtered_semantic
212
- for res in filtered_semantic_no_dupe[:10]:
213
- project_name = res.payload['metadata'].get('project_name', 'Project Link')
214
- url = res.payload['metadata'].get('url', '#')
215
- st.markdown(f"#### [{project_name}]({url})")
216
-
217
- # Snippet logic
218
- full_text = res.payload['page_content']
219
- words = full_text.split()
220
- preview_word_count = 80
221
- preview_text = " ".join(words[:preview_word_count])
222
- remainder_text = " ".join(words[preview_word_count:])
223
- st.write(preview_text + ("..." if remainder_text else ""))
224
-
225
- # Keywords
226
- top_keywords = extract_top_keywords(full_text, top_n=5)
227
- if top_keywords:
228
- st.markdown(f"_{' 路 '.join(top_keywords)}_")
229
-
230
- # Metadata
231
- metadata = res.payload.get('metadata', {})
232
- countries = metadata.get('countries', "[]")
233
- client_name = metadata.get('client', 'Unknown Client')
234
- start_year = metadata.get('start_year', None)
235
- end_year_ = metadata.get('end_year', None)
236
-
237
- try:
238
- c_list = json.loads(countries.replace("'", '"'))
239
- country_names = [get_country_name(code.upper(), region_df) for code in c_list if len(code) == 2]
240
- except json.JSONDecodeError:
241
- country_names = []
242
-
243
- start_year_str = f"{int(round(float(start_year)))}" if start_year else "Unknown"
244
- end_year_str = f"{int(round(float(end_year_)))}" if end_year_ else "Unknown"
245
-
246
- additional_text = (
247
- f"**{', '.join(country_names)}**, commissioned by **{client_name}**, **{start_year_str}-{end_year_str}**"
248
- )
249
- st.markdown(additional_text)
250
- st.divider()
 
 
 
 
251
 
252
 
253
  # for i in results:
 
162
  # Check user preference
163
  if show_exact_matches:
164
  st.write(f"Showing **Top 10 Lexical Search results** for query: {var}")
 
 
 
 
165
  # Show the top 10 from filtered_lexical
166
  for res in filtered_lexical_no_dupe[:10]:
167
  project_name = res.payload['metadata'].get('project_name', 'Project Link')
 
204
  st.divider()
205
  else:
206
  st.write(f"Showing **Top 10 Semantic Search results** for query: {var}")
207
+
208
+ if not filtered_semantic_no_dupe:
209
+ st.write("No relevant results found.")
210
+ else:
211
+ # Show the top 10 from filtered_semantic
212
+ for res in filtered_semantic_no_dupe[:10]:
213
+ project_name = res.payload['metadata'].get('project_name', 'Project Link')
214
+ url = res.payload['metadata'].get('url', '#')
215
+ st.markdown(f"#### [{project_name}]({url})")
216
+
217
+ # Snippet logic
218
+ full_text = res.payload['page_content']
219
+ words = full_text.split()
220
+ preview_word_count = 80
221
+ preview_text = " ".join(words[:preview_word_count])
222
+ remainder_text = " ".join(words[preview_word_count:])
223
+ st.write(preview_text + ("..." if remainder_text else ""))
224
+
225
+ # Keywords
226
+ top_keywords = extract_top_keywords(full_text, top_n=5)
227
+ if top_keywords:
228
+ st.markdown(f"_{' '.join(top_keywords)}_")
229
+
230
+ # Metadata
231
+ metadata = res.payload.get('metadata', {})
232
+ countries = metadata.get('countries', "[]")
233
+ client_name = metadata.get('client', 'Unknown Client')
234
+ start_year = metadata.get('start_year', None)
235
+ end_year_ = metadata.get('end_year', None)
236
+
237
+ try:
238
+ c_list = json.loads(countries.replace("'", '"'))
239
+ country_names = [get_country_name(code.upper(), region_df) for code in c_list if len(code) == 2]
240
+ except json.JSONDecodeError:
241
+ country_names = []
242
+
243
+ start_year_str = f"{int(round(float(start_year)))}" if start_year else "Unknown"
244
+ end_year_str = f"{int(round(float(end_year_)))}" if end_year_ else "Unknown"
245
+
246
+ additional_text = (
247
+ f"**{', '.join(country_names)}**, commissioned by **{client_name}**, **{start_year_str}-{end_year_str}**"
248
+ )
249
+ st.markdown(additional_text)
250
+ st.divider()
251
 
252
 
253
  # for i in results: