Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -5,11 +5,12 @@ import os
|
|
5 |
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
6 |
import google.generativeai as genai
|
7 |
from langchain_community.vectorstores import FAISS
|
8 |
-
from langchain_google_genai import ChatGoogleGenerativeAI
|
9 |
from langchain.chains.question_answering import load_qa_chain
|
10 |
from langchain.prompts import PromptTemplate
|
11 |
from dotenv import load_dotenv
|
12 |
import traceback
|
|
|
|
|
13 |
|
14 |
# Load environment variables
|
15 |
load_dotenv()
|
@@ -46,8 +47,16 @@ def get_text_chunks(text):
|
|
46 |
# Function to create an in-memory FAISS vector store
|
47 |
def get_vector_store(text_chunks):
|
48 |
try:
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
return vector_store
|
52 |
except Exception as e:
|
53 |
st.error(f"Error creating vector store: {e}")
|
|
|
5 |
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
6 |
import google.generativeai as genai
|
7 |
from langchain_community.vectorstores import FAISS
|
|
|
8 |
from langchain.chains.question_answering import load_qa_chain
|
9 |
from langchain.prompts import PromptTemplate
|
10 |
from dotenv import load_dotenv
|
11 |
import traceback
|
12 |
+
from transformers import pipeline
|
13 |
+
from langchain.embeddings import HuggingFaceEmbeddings
|
14 |
|
15 |
# Load environment variables
|
16 |
load_dotenv()
|
|
|
47 |
# Function to create an in-memory FAISS vector store
|
48 |
def get_vector_store(text_chunks):
|
49 |
try:
|
50 |
+
# Create a pipeline for feature extraction with the specified model
|
51 |
+
feature_extractor = pipeline("feature-extraction", model="jinaai/jina-embeddings-v2-base-code", trust_remote_code=True)
|
52 |
+
|
53 |
+
# Define a function to generate embeddings using the pipeline
|
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:
|
62 |
st.error(f"Error creating vector store: {e}")
|