Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
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) |