Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -61,18 +61,25 @@ if uploaded_file:
|
|
| 61 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=256, chunk_overlap=50)
|
| 62 |
chunked_documents = text_splitter.split_documents(documents)
|
| 63 |
|
| 64 |
-
#
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
| 61 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=256, chunk_overlap=50)
|
| 62 |
chunked_documents = text_splitter.split_documents(documents)
|
| 63 |
|
| 64 |
+
# Ensure the chunked documents list is not empty
|
| 65 |
+
if not chunked_documents:
|
| 66 |
+
st.error("No content extracted from the document.")
|
| 67 |
+
else:
|
| 68 |
+
# Generate embeddings
|
| 69 |
+
HF_token = "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"
|
| 70 |
+
embeddings = HuggingFaceInferenceAPIEmbeddings(api_key=HF_token, model_name="BAAI/bge-base-en-v1.5")
|
| 71 |
|
| 72 |
+
# Create a vector store
|
| 73 |
+
try:
|
| 74 |
+
vectorstore = Chroma.from_documents(chunked_documents, embeddings)
|
| 75 |
+
retriever = vectorstore.as_retriever(search_type="mmr", search_kwargs={"k": 3})
|
| 76 |
|
| 77 |
+
# User query
|
| 78 |
+
query = st.text_input("Enter your query:")
|
| 79 |
|
| 80 |
+
if query:
|
| 81 |
+
response = answer_with_retrieval(query, retriever)
|
| 82 |
+
st.write("### Response")
|
| 83 |
+
st.write(response)
|
| 84 |
+
except Exception as e:
|
| 85 |
+
st.error(f"Error creating vector store or generating embeddings: {str(e)}")
|