Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -9,14 +9,14 @@ 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
|
13 |
-
|
14 |
|
15 |
# Load environment variables
|
16 |
load_dotenv()
|
17 |
|
18 |
# Ensure the Google API key is loaded
|
19 |
-
google_api_key = '
|
20 |
if not google_api_key:
|
21 |
raise ValueError("Google API key not found. Please check your .env file.")
|
22 |
|
@@ -47,17 +47,17 @@ def get_text_chunks(text):
|
|
47 |
# Function to create an in-memory FAISS vector store
|
48 |
def get_vector_store(text_chunks):
|
49 |
try:
|
50 |
-
#
|
51 |
embedding_function = HuggingFaceEmbeddings(model_name="jinaai/jina-embeddings-v2-base-code")
|
52 |
|
53 |
-
# Using FAISS to create vector store with the
|
54 |
vector_store = FAISS.from_texts(text_chunks, embedding=embedding_function)
|
55 |
-
|
56 |
return vector_store
|
57 |
except Exception as e:
|
58 |
st.error(f"Error creating vector store: {e}")
|
59 |
traceback.print_exc()
|
60 |
return None
|
|
|
61 |
# Function to create a conversation chain with Google Generative AI
|
62 |
def get_conversational_chain():
|
63 |
try:
|
@@ -118,7 +118,6 @@ def main():
|
|
118 |
font-size: 18px;
|
119 |
margin-bottom: 20px;
|
120 |
}
|
121 |
-
|
122 |
</style>
|
123 |
""",
|
124 |
unsafe_allow_html=True
|
|
|
9 |
from langchain.prompts import PromptTemplate
|
10 |
from dotenv import load_dotenv
|
11 |
import traceback
|
12 |
+
from langchain.embeddings import HuggingFaceEmbeddings
|
13 |
+
import tensorflow as tf # Ensure TensorFlow is imported
|
14 |
|
15 |
# Load environment variables
|
16 |
load_dotenv()
|
17 |
|
18 |
# Ensure the Google API key is loaded
|
19 |
+
google_api_key = os.getenv('GOOGLE_API_KEY') # Fetch from .env
|
20 |
if not google_api_key:
|
21 |
raise ValueError("Google API key not found. Please check your .env file.")
|
22 |
|
|
|
47 |
# Function to create an in-memory FAISS vector store
|
48 |
def get_vector_store(text_chunks):
|
49 |
try:
|
50 |
+
# Initialize HuggingFace embeddings
|
51 |
embedding_function = HuggingFaceEmbeddings(model_name="jinaai/jina-embeddings-v2-base-code")
|
52 |
|
53 |
+
# Using FAISS to create vector store with the Hugging Face embeddings
|
54 |
vector_store = FAISS.from_texts(text_chunks, embedding=embedding_function)
|
|
|
55 |
return vector_store
|
56 |
except Exception as e:
|
57 |
st.error(f"Error creating vector store: {e}")
|
58 |
traceback.print_exc()
|
59 |
return None
|
60 |
+
|
61 |
# Function to create a conversation chain with Google Generative AI
|
62 |
def get_conversational_chain():
|
63 |
try:
|
|
|
118 |
font-size: 18px;
|
119 |
margin-bottom: 20px;
|
120 |
}
|
|
|
121 |
</style>
|
122 |
""",
|
123 |
unsafe_allow_html=True
|