Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from dotenv import load_dotenv
|
| 3 |
-
from langchain_community.document_loaders
|
| 4 |
from langchain.embeddings import HuggingFaceEmbeddings
|
| 5 |
from langchain_community.vectorstores.faiss import FAISS
|
| 6 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
@@ -55,11 +55,11 @@ if process_url_clicked:
|
|
| 55 |
else:
|
| 56 |
try:
|
| 57 |
main_placeholder.text("Data Loading...Started...β
β
β
")
|
| 58 |
-
loader =
|
| 59 |
data = loader.load()
|
| 60 |
|
| 61 |
-
#
|
| 62 |
-
if not data:
|
| 63 |
main_placeholder.error("No content loaded from URLs. Try different URLs.")
|
| 64 |
st.stop()
|
| 65 |
|
|
@@ -70,7 +70,6 @@ if process_url_clicked:
|
|
| 70 |
)
|
| 71 |
docs = text_splitter.split_documents(data)
|
| 72 |
|
| 73 |
-
# Debug: Check document count
|
| 74 |
main_placeholder.text(f"Split into {len(docs)} document chunks.")
|
| 75 |
|
| 76 |
main_placeholder.text("Embedding Vector Started Building...β
β
β
")
|
|
@@ -81,7 +80,7 @@ if process_url_clicked:
|
|
| 81 |
st.session_state.index_created = True
|
| 82 |
main_placeholder.text("FAISS index saved successfully! β
β
β
")
|
| 83 |
time.sleep(2)
|
| 84 |
-
main_placeholder.empty()
|
| 85 |
except Exception as e:
|
| 86 |
main_placeholder.error(f"Error processing URLs: {str(e)}")
|
| 87 |
|
|
@@ -97,7 +96,6 @@ if query:
|
|
| 97 |
chain = RetrievalQAWithSourcesChain.from_llm(llm=llm, retriever=vectorstore.as_retriever())
|
| 98 |
result = chain({"question": query}, return_only_outputs=True)
|
| 99 |
|
| 100 |
-
# Debug: Check result
|
| 101 |
if not result.get("answer"):
|
| 102 |
main_placeholder.warning("No answer generated. Try a different question or URLs.")
|
| 103 |
st.stop()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from dotenv import load_dotenv
|
| 3 |
+
from langchain_community.document_loaders import WebBaseLoader
|
| 4 |
from langchain.embeddings import HuggingFaceEmbeddings
|
| 5 |
from langchain_community.vectorstores.faiss import FAISS
|
| 6 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
|
|
| 55 |
else:
|
| 56 |
try:
|
| 57 |
main_placeholder.text("Data Loading...Started...β
β
β
")
|
| 58 |
+
loader = WebBaseLoader(urls)
|
| 59 |
data = loader.load()
|
| 60 |
|
| 61 |
+
# Check loaded data
|
| 62 |
+
if not data or all(len(doc.page_content.strip()) == 0 for doc in data):
|
| 63 |
main_placeholder.error("No content loaded from URLs. Try different URLs.")
|
| 64 |
st.stop()
|
| 65 |
|
|
|
|
| 70 |
)
|
| 71 |
docs = text_splitter.split_documents(data)
|
| 72 |
|
|
|
|
| 73 |
main_placeholder.text(f"Split into {len(docs)} document chunks.")
|
| 74 |
|
| 75 |
main_placeholder.text("Embedding Vector Started Building...β
β
β
")
|
|
|
|
| 80 |
st.session_state.index_created = True
|
| 81 |
main_placeholder.text("FAISS index saved successfully! β
β
β
")
|
| 82 |
time.sleep(2)
|
| 83 |
+
main_placeholder.empty()
|
| 84 |
except Exception as e:
|
| 85 |
main_placeholder.error(f"Error processing URLs: {str(e)}")
|
| 86 |
|
|
|
|
| 96 |
chain = RetrievalQAWithSourcesChain.from_llm(llm=llm, retriever=vectorstore.as_retriever())
|
| 97 |
result = chain({"question": query}, return_only_outputs=True)
|
| 98 |
|
|
|
|
| 99 |
if not result.get("answer"):
|
| 100 |
main_placeholder.warning("No answer generated. Try a different question or URLs.")
|
| 101 |
st.stop()
|