File size: 826 Bytes
9dcd3f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import pickle
import faiss
import streamlit as st
from sentence_transformers import SentenceTransformer

def show_search(model, faiss_index, sentences):
    query = st.text_input("Enter your search query:")

    if query:
        # Convert query to embedding
        query_embedding = model.encode([query])[0].reshape(1, -1)
        
        # Perform search
        D, I = faiss_index.search(query_embedding, k=5)  # Search for top 5 similar items
        
        # Extract the sentences corresponding to the top indices
        top_sentences = [sentences[i] for i in I[0]]
        
        # Display results as a selection list
        selected_sentence = st.selectbox("Top results:", top_sentences)
        
        # Optionally, do something with the selected sentence
        st.write("You selected:", selected_sentence)