Spaces:
Build error
Build error
Update app.py
Browse files58 unmodified lines59606162636465664 unmodified lines71727374757677787958 unmodified lines# Function to create a FAISS vector storedef create_vector_store(text):sentences = [sentence.strip() for sentence in text.split(". ") if sentence.strip()]model_name = "sentence-transformers/all-MiniLM-L6-v2"tokenizer = AutoTokenizer.from_pretrained(model_name)model = AutoModel.from_pretrained(model_name)4 unmodified linesembeddings = model(**tokens).last_hidden_state.mean(dim=1).squeeze().numpy()return embeddingsembeddings = [embed(sentence) for sentence in sentences]text_embeddings = [(sentences[i], embeddings[i]) for i in range(len(sentences))]vector_store = FAISS.from_embeddings(text_embeddings)return vector_store, sentences58 unmodified lines596061626364656667684 unmodified lines737475767778798081828358 unmodified lines# Function to create a FAISS vector storedef create_vector_store(text):# Split the text into sentences and clean itsentences = [sentence.strip() for sentence in text.split(". ") if sentence.strip()]# Load the model and tokenizer from Hugging Facemodel_name = "sentence-transformers/all-MiniLM-L6-v2"tokenizer = AutoTokenizer.from_pretrained(model_name)model = AutoModel.from_pretrained(model_name)4 unmodified linesembeddings = model(**tokens).last_hidden_state.mean(dim=1).squeeze().numpy()return embeddings# Create a function that directly returns embeddingsembedding_function = lambda x: embed(x)# Create a FAISS vector storevector_store = FAISS.from_texts(texts=sentences, embedding=embedding_function)return vector_store, sentences
app.py+7-3