Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ from langchain.prompts import PromptTemplate
|
|
| 10 |
from dotenv import load_dotenv
|
| 11 |
import traceback
|
| 12 |
from transformers import pipeline
|
| 13 |
-
from
|
| 14 |
|
| 15 |
# Load environment variables
|
| 16 |
load_dotenv()
|
|
@@ -44,18 +44,14 @@ def get_text_chunks(text):
|
|
| 44 |
return []
|
| 45 |
return chunks
|
| 46 |
|
|
|
|
| 47 |
# Function to create an in-memory FAISS vector store
|
| 48 |
def get_vector_store(text_chunks):
|
| 49 |
try:
|
| 50 |
-
# Create
|
| 51 |
-
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
def embedding_function(text):
|
| 55 |
-
# The pipeline returns nested lists, so we flatten it by taking the first item.
|
| 56 |
-
return feature_extractor(text)[0]
|
| 57 |
-
|
| 58 |
-
# Using FAISS to create vector store with the new embeddings function
|
| 59 |
vector_store = FAISS.from_texts(text_chunks, embedding=embedding_function)
|
| 60 |
return vector_store
|
| 61 |
except Exception as e:
|
|
|
|
| 10 |
from dotenv import load_dotenv
|
| 11 |
import traceback
|
| 12 |
from transformers import pipeline
|
| 13 |
+
from langchain_community.embeddings import HuggingFaceEmbeddings
|
| 14 |
|
| 15 |
# Load environment variables
|
| 16 |
load_dotenv()
|
|
|
|
| 44 |
return []
|
| 45 |
return chunks
|
| 46 |
|
| 47 |
+
# Function to create an in-memory FAISS vector store
|
| 48 |
# Function to create an in-memory FAISS vector store
|
| 49 |
def get_vector_store(text_chunks):
|
| 50 |
try:
|
| 51 |
+
# Create an instance of HuggingFaceEmbeddings with the specified model
|
| 52 |
+
embedding_function = HuggingFaceEmbeddings(model_name="jinaai/jina-embeddings-v2-base-code")
|
| 53 |
|
| 54 |
+
# Using FAISS to create vector store with the embeddings function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
vector_store = FAISS.from_texts(text_chunks, embedding=embedding_function)
|
| 56 |
return vector_store
|
| 57 |
except Exception as e:
|