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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
input_changed = (voice_text != st.session_state.get('old_val'))
|
| 344 |
|
| 345 |
if autorun and input_changed:
|
| 346 |
+
# Save input as md file immediately
|
| 347 |
+
saved_path = save_input_as_md(edited_input)
|
| 348 |
+
st.session_state['old_val'] = voice_text
|
| 349 |
+
with st.spinner("Processing voice input..."):
|
| 350 |
+
# Instead of just top 20, show up to max_items in order
|
| 351 |
+
if run_option == "Quick Search":
|
| 352 |
+
df = search.load_page()
|
| 353 |
+
results = search.quick_search(edited_input, df)
|
| 354 |
+
# Show results in order, stopping at max_items
|
| 355 |
+
shown = 0
|
| 356 |
+
for i, result in enumerate(results.iterrows(), 1):
|
| 357 |
+
if shown >= st.session_state['max_items']:
|
| 358 |
+
break
|
| 359 |
+
with st.expander(f"Result {i}", expanded=(i==1)):
|
| 360 |
+
render_result(result[1])
|
| 361 |
+
shown += 1
|
| 362 |
+
|
| 363 |
+
elif run_option == "Deep Search":
|
| 364 |
+
# For deep search, iterate through pages until we hit max_items
|
| 365 |
+
results_all = []
|
| 366 |
+
page = 0
|
| 367 |
+
while len(results_all) < st.session_state['max_items']:
|
| 368 |
+
df = search.load_page(page)
|
| 369 |
+
if df.empty:
|
| 370 |
+
break
|
| 371 |
+
these_results = search.quick_search(edited_input, df)
|
| 372 |
+
if these_results.empty:
|
| 373 |
+
break
|
| 374 |
+
results_all.extend(these_results.iterrows())
|
| 375 |
+
page += 1
|
| 376 |
+
|
| 377 |
+
shown = 0
|
| 378 |
+
for i, result in enumerate(results_all, 1):
|
| 379 |
+
if shown >= st.session_state['max_items']:
|
| 380 |
+
break
|
| 381 |
+
with st.expander(f"Result {i}", expanded=(i==1)):
|
| 382 |
+
render_result(result[1])
|
| 383 |
+
shown += 1
|
| 384 |
+
|
| 385 |
+
elif run_option == "Voice Summary":
|
| 386 |
+
audio_file = speak_with_edge_tts(edited_input)
|
| 387 |
+
if audio_file:
|
| 388 |
+
play_and_download_audio(audio_file)
|
| 389 |
+
|
| 390 |
+
elif st.button("π Search", key="voice_input_search"):
|
| 391 |
+
# Manual search trigger
|
| 392 |
+
# Save input as md file
|
| 393 |
+
saved_path = save_input_as_md(edited_input)
|
| 394 |
+
st.session_state['old_val'] = voice_text
|
| 395 |
+
with st.spinner("Processing..."):
|
| 396 |
+
df = search.load_page()
|
| 397 |
+
results = search.quick_search(edited_input, df)
|
| 398 |
+
shown = 0
|
| 399 |
+
for i, result in enumerate(results.iterrows(), 1):
|
| 400 |
+
if shown >= st.session_state['max_items']:
|
| 401 |
+
break
|
| 402 |
+
with st.expander(f"Result {i}", expanded=(i==1)):
|
| 403 |
+
render_result(result[1])
|
| 404 |
+
shown += 1
|
| 405 |
+
|
| 406 |
+
# Tabs
|
| 407 |
+
tab1, tab2, tab3, tab4 = st.tabs([
|
| 408 |
+
"π Search", "ποΈ Voice", "πΎ History", "βοΈ Settings"
|
| 409 |
+
])
|
| 410 |
+
|
| 411 |
+
with tab1:
|
| 412 |
+
st.subheader("π Search")
|
| 413 |
+
col1, col2 = st.columns([3, 1])
|
| 414 |
+
with col1:
|
| 415 |
+
query = st.text_input("Enter search query:",
|
| 416 |
+
value="" if st.session_state['initial_search_done'] == False else "")
|
| 417 |
+
with col2:
|
| 418 |
+
# Not strictly filtering by column now; user requested just show in order
|
| 419 |
+
search_column = st.selectbox("Search in:", ["All Fields"] + st.session_state['search_columns'])
|
| 420 |
+
|
| 421 |
+
col3, col4 = st.columns(2)
|
| 422 |
+
with col3:
|
| 423 |
+
num_results = st.slider("Max results:", 1, 100, 20)
|
| 424 |
+
with col4:
|
| 425 |
+
search_button = st.button("π Search", key="main_search_button")
|
| 426 |
+
|
| 427 |
+
if (search_button or not st.session_state['initial_search_done']) and query:
|
| 428 |
+
st.session_state['initial_search_done'] = True
|
| 429 |
+
selected_column = None if search_column == "All Fields" else search_column
|
| 430 |
+
|
| 431 |
+
with st.spinner("Searching..."):
|
| 432 |
+
df = search.load_page()
|
| 433 |
+
results = search.quick_search(query, df)
|
| 434 |
+
|
| 435 |
+
if len(results) > 0:
|
| 436 |
+
st.session_state['search_history'].append({
|
| 437 |
+
'query': query,
|
| 438 |
+
'timestamp': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
| 439 |
+
'results': results[:5]
|
| 440 |
+
})
|
| 441 |
+
|
| 442 |
+
st.write(f"Found {len(results)} results:")
|
| 443 |
+
shown = 0
|
| 444 |
+
for i, (_, result) in enumerate(results.iterrows(), 1):
|
| 445 |
+
if shown >= num_results:
|
| 446 |
+
break
|
| 447 |
+
with st.expander(f"Result {i}", expanded=(i==1)):
|
| 448 |
+
render_result(result)
|
| 449 |
+
shown += 1
|
| 450 |
+
else:
|
| 451 |
+
st.warning("No matching results found.")
|
| 452 |
+
|
| 453 |
+
with tab2:
|
| 454 |
+
st.subheader("ποΈ Voice Input")
|
| 455 |
+
st.write("Use the voice input above to start speaking, or record a new message:")
|
| 456 |
+
|
| 457 |
+
col1, col2 = st.columns(2)
|
| 458 |
+
with col1:
|
| 459 |
+
if st.button("ποΈ Start New Recording", key="start_recording_button"):
|
| 460 |
+
st.session_state['recording'] = True
|
| 461 |
+
st.experimental_rerun()
|
| 462 |
+
with col2:
|
| 463 |
+
if st.button("π Stop Recording", key="stop_recording_button"):
|
| 464 |
+
st.session_state['recording'] = False
|
| 465 |
+
st.experimental_rerun()
|
| 466 |
+
|
| 467 |
+
if st.session_state.get('recording', False):
|
| 468 |
+
voice_component = create_voice_component()
|
| 469 |
+
new_val = voice_component(my_input_value="Recording...")
|
| 470 |
+
if new_val:
|
| 471 |
+
st.text_area("Recorded Text:", value=new_val, height=100)
|
| 472 |
+
if st.button("π Search with Recording", key="recording_search_button"):
|
| 473 |
+
# Save this input right away
|
| 474 |
+
saved_path = save_input_as_md(new_val)
|
| 475 |
+
with st.spinner("Processing recording..."):
|
| 476 |
+
df = search.load_page()
|
| 477 |
+
results = search.quick_search(new_val, df)
|
| 478 |
+
shown = 0
|
| 479 |
+
for i, (_, result) in enumerate(results.iterrows(), 1):
|
| 480 |
+
if shown >= st.session_state['max_items']:
|
| 481 |
+
break
|
| 482 |
+
with st.expander(f"Result {i}", expanded=(i==1)):
|
| 483 |
+
render_result(result)
|
| 484 |
+
shown += 1
|
| 485 |
+
|
| 486 |
+
with tab3:
|
| 487 |
+
st.subheader("πΎ Search History")
|
| 488 |
+
if not st.session_state['search_history']:
|
| 489 |
+
st.info("No search history yet. Try searching for something!")
|
| 490 |
+
else:
|
| 491 |
+
for entry in reversed(st.session_state['search_history']):
|
| 492 |
+
with st.expander(f"π {entry['timestamp']} - {entry['query']}", expanded=False):
|
| 493 |
+
for i, result in enumerate(entry['results'], 1):
|
| 494 |
+
st.write(f"**Result {i}:**")
|
| 495 |
+
if isinstance(result, pd.Series):
|
| 496 |
+
render_result(result)
|
| 497 |
+
else:
|
| 498 |
+
st.write(result)
|
| 499 |
+
|
| 500 |
+
with tab4:
|
| 501 |
+
st.subheader("βοΈ Settings")
|
| 502 |
+
st.write("Voice Settings:")
|
| 503 |
+
default_voice = st.selectbox(
|
| 504 |
+
"Default Voice:",
|
| 505 |
+
[
|
| 506 |
+
"en-US-AriaNeural",
|
| 507 |
+
"en-US-GuyNeural",
|
| 508 |
+
"en-GB-SoniaNeural",
|
| 509 |
+
"en-GB-TonyNeural"
|
| 510 |
+
],
|
| 511 |
+
index=0,
|
| 512 |
+
key="default_voice_setting"
|
| 513 |
+
)
|
| 514 |
+
|
| 515 |
+
st.write("Search Settings:")
|
| 516 |
+
st.slider("Minimum Search Score:", 0.0, 1.0, MIN_SEARCH_SCORE, 0.1, key="min_search_score")
|
| 517 |
+
st.slider("Exact Match Boost:", 1.0, 3.0, EXACT_MATCH_BOOST, 0.1, key="exact_match_boost")
|
| 518 |
+
|
| 519 |
+
if st.button("ποΈ Clear Search History", key="clear_history_button"):
|
| 520 |
+
st.session_state['search_history'] = []
|
| 521 |
+
st.success("Search history cleared!")
|
| 522 |
+
st.experimental_rerun()
|
| 523 |
+
|
| 524 |
+
# Sidebar metrics
|
| 525 |
+
with st.sidebar:
|
| 526 |
+
st.subheader("π Search Metrics")
|
| 527 |
+
total_searches = len(st.session_state['search_history'])
|
| 528 |
+
st.metric("Total Searches", total_searches)
|
| 529 |
+
|
| 530 |
+
if total_searches > 0:
|
| 531 |
+
recent_searches = st.session_state['search_history'][-5:]
|
| 532 |
+
st.write("Recent Searches:")
|
| 533 |
+
for entry in reversed(recent_searches):
|
| 534 |
+
st.write(f"π {entry['query']}")
|
| 535 |
+
|
| 536 |
+
if __name__ == "__main__":
|
| 537 |
+
main()
|