Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ 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 |
-
from google.api_core.exceptions import GoogleAPIError
|
| 13 |
|
| 14 |
# Load environment variables
|
| 15 |
load_dotenv()
|
|
@@ -39,8 +39,8 @@ def get_vector_store(chunks):
|
|
| 39 |
model="models/embedding-001") # type: ignore
|
| 40 |
vector_store = FAISS.from_texts(chunks, embedding=embeddings)
|
| 41 |
vector_store.save_local("faiss_index")
|
| 42 |
-
except GoogleAPIError:
|
| 43 |
-
st.error("Please try again in a minute.")
|
| 44 |
|
| 45 |
# Function to get conversational chain
|
| 46 |
def get_conversational_chain():
|
|
@@ -60,8 +60,8 @@ def get_conversational_chain():
|
|
| 60 |
input_variables=["context", "question"])
|
| 61 |
chain = load_qa_chain(llm=model, chain_type="stuff", prompt=prompt)
|
| 62 |
return chain
|
| 63 |
-
except GoogleAPIError:
|
| 64 |
-
st.error("Please try again in a minute.")
|
| 65 |
|
| 66 |
# Function to clear chat history
|
| 67 |
def clear_chat_history():
|
|
@@ -79,8 +79,8 @@ def user_input(user_question):
|
|
| 79 |
response = chain(
|
| 80 |
{"input_documents": docs, "question": user_question}, return_only_outputs=True)
|
| 81 |
return response
|
| 82 |
-
except GoogleAPIError:
|
| 83 |
-
st.error("Please try again in a minute.")
|
| 84 |
|
| 85 |
# Main function to run the Streamlit app
|
| 86 |
def main():
|
|
@@ -178,5 +178,5 @@ def main():
|
|
| 178 |
else:
|
| 179 |
st.error("Please try again in a minute.")
|
| 180 |
|
| 181 |
-
if __name__ == "
|
| 182 |
main()
|
|
|
|
| 9 |
from langchain.chains.question_answering import load_qa_chain
|
| 10 |
from langchain.prompts import PromptTemplate
|
| 11 |
from dotenv import load_dotenv
|
| 12 |
+
from google.api_core.exceptions import GoogleAPIError, InvalidArgument
|
| 13 |
|
| 14 |
# Load environment variables
|
| 15 |
load_dotenv()
|
|
|
|
| 39 |
model="models/embedding-001") # type: ignore
|
| 40 |
vector_store = FAISS.from_texts(chunks, embedding=embeddings)
|
| 41 |
vector_store.save_local("faiss_index")
|
| 42 |
+
except (GoogleAPIError, InvalidArgument) as e:
|
| 43 |
+
st.error("Error processing embeddings. Please try again in a minute.")
|
| 44 |
|
| 45 |
# Function to get conversational chain
|
| 46 |
def get_conversational_chain():
|
|
|
|
| 60 |
input_variables=["context", "question"])
|
| 61 |
chain = load_qa_chain(llm=model, chain_type="stuff", prompt=prompt)
|
| 62 |
return chain
|
| 63 |
+
except (GoogleAPIError, InvalidArgument) as e:
|
| 64 |
+
st.error("Error creating conversational chain. Please try again in a minute.")
|
| 65 |
|
| 66 |
# Function to clear chat history
|
| 67 |
def clear_chat_history():
|
|
|
|
| 79 |
response = chain(
|
| 80 |
{"input_documents": docs, "question": user_question}, return_only_outputs=True)
|
| 81 |
return response
|
| 82 |
+
except (GoogleAPIError, InvalidArgument) as e:
|
| 83 |
+
st.error("Error processing request. Please try again in a minute.")
|
| 84 |
|
| 85 |
# Main function to run the Streamlit app
|
| 86 |
def main():
|
|
|
|
| 178 |
else:
|
| 179 |
st.error("Please try again in a minute.")
|
| 180 |
|
| 181 |
+
if __name__ == "__main__":
|
| 182 |
main()
|