Spaces:
Runtime error
Runtime error
Commit
•
c694f6d
1
Parent(s):
8586b67
Update app.py
Browse files
app.py
CHANGED
@@ -19,10 +19,8 @@ llm_groq = ChatGroq(
|
|
19 |
st.set_page_config(page_title="DocDynamo", layout="wide")
|
20 |
st.title("DocDynamo🚀")
|
21 |
|
22 |
-
# Upload PDF file
|
23 |
uploaded_file = st.file_uploader("Please upload a PDF file to begin!", type="pdf")
|
24 |
|
25 |
-
# Sidebar content
|
26 |
st.sidebar.title("DocDynamo By OpenRAG")
|
27 |
st.sidebar.markdown(
|
28 |
"""
|
@@ -53,7 +51,6 @@ Experience the future of PDF interaction with DocDynamo. Welcome to a new era of
|
|
53 |
)
|
54 |
|
55 |
if uploaded_file:
|
56 |
-
# Inform the user that processing has started
|
57 |
with st.spinner(f"Processing `{uploaded_file.name}`..."):
|
58 |
# Read the PDF file
|
59 |
pdf = PyPDF2.PdfReader(uploaded_file)
|
@@ -61,18 +58,18 @@ if uploaded_file:
|
|
61 |
for page in pdf.pages:
|
62 |
pdf_text += page.extract_text()
|
63 |
|
64 |
-
|
65 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1200, chunk_overlap=50)
|
66 |
texts = text_splitter.split_text(pdf_text)
|
67 |
|
68 |
-
|
69 |
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2", model_kwargs={'device': "cpu"})
|
70 |
docsearch = Chroma.from_texts(texts, embeddings)
|
71 |
|
72 |
-
|
73 |
message_history = ChatMessageHistory()
|
74 |
|
75 |
-
|
76 |
memory = ConversationBufferMemory(
|
77 |
memory_key="chat_history",
|
78 |
output_key="answer",
|
@@ -80,7 +77,7 @@ if uploaded_file:
|
|
80 |
return_messages=True,
|
81 |
)
|
82 |
|
83 |
-
|
84 |
chain = ConversationalRetrievalChain.from_llm(
|
85 |
llm=llm_groq,
|
86 |
chain_type="stuff",
|
@@ -94,14 +91,13 @@ if uploaded_file:
|
|
94 |
user_input = st.text_input("Ask a question about the PDF:")
|
95 |
|
96 |
if user_input:
|
97 |
-
# Call the chain with user's message content
|
98 |
res = chain.invoke(user_input)
|
99 |
answer = res["answer"]
|
100 |
source_documents = res["source_documents"]
|
101 |
|
102 |
-
text_elements = []
|
103 |
|
104 |
-
|
105 |
if source_documents:
|
106 |
for source_doc in source_documents:
|
107 |
text_elements.append(source_doc.page_content)
|
|
|
19 |
st.set_page_config(page_title="DocDynamo", layout="wide")
|
20 |
st.title("DocDynamo🚀")
|
21 |
|
|
|
22 |
uploaded_file = st.file_uploader("Please upload a PDF file to begin!", type="pdf")
|
23 |
|
|
|
24 |
st.sidebar.title("DocDynamo By OpenRAG")
|
25 |
st.sidebar.markdown(
|
26 |
"""
|
|
|
51 |
)
|
52 |
|
53 |
if uploaded_file:
|
|
|
54 |
with st.spinner(f"Processing `{uploaded_file.name}`..."):
|
55 |
# Read the PDF file
|
56 |
pdf = PyPDF2.PdfReader(uploaded_file)
|
|
|
58 |
for page in pdf.pages:
|
59 |
pdf_text += page.extract_text()
|
60 |
|
61 |
+
|
62 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1200, chunk_overlap=50)
|
63 |
texts = text_splitter.split_text(pdf_text)
|
64 |
|
65 |
+
|
66 |
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2", model_kwargs={'device': "cpu"})
|
67 |
docsearch = Chroma.from_texts(texts, embeddings)
|
68 |
|
69 |
+
|
70 |
message_history = ChatMessageHistory()
|
71 |
|
72 |
+
|
73 |
memory = ConversationBufferMemory(
|
74 |
memory_key="chat_history",
|
75 |
output_key="answer",
|
|
|
77 |
return_messages=True,
|
78 |
)
|
79 |
|
80 |
+
|
81 |
chain = ConversationalRetrievalChain.from_llm(
|
82 |
llm=llm_groq,
|
83 |
chain_type="stuff",
|
|
|
91 |
user_input = st.text_input("Ask a question about the PDF:")
|
92 |
|
93 |
if user_input:
|
|
|
94 |
res = chain.invoke(user_input)
|
95 |
answer = res["answer"]
|
96 |
source_documents = res["source_documents"]
|
97 |
|
98 |
+
text_elements = []
|
99 |
|
100 |
+
|
101 |
if source_documents:
|
102 |
for source_doc in source_documents:
|
103 |
text_elements.append(source_doc.page_content)
|