Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -49,7 +49,7 @@ def get_vectorstore(text_chunks):
|
|
| 49 |
# Function to set up the conversational retrieval chain
|
| 50 |
def get_conversation_chain(vectorstore):
|
| 51 |
try:
|
| 52 |
-
llm = ChatGroq(model="llama-3
|
| 53 |
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)
|
| 54 |
|
| 55 |
conversation_chain = ConversationalRetrievalChain.from_llm(
|
|
@@ -74,7 +74,7 @@ def handle_userinput(user_question):
|
|
| 74 |
role = "User" if i % 2 == 0 else "Bot"
|
| 75 |
st.write(f"*{role}:* {message.content}")
|
| 76 |
else:
|
| 77 |
-
st.warning("Please
|
| 78 |
|
| 79 |
# Main function to run the Streamlit app
|
| 80 |
def main():
|
|
@@ -87,28 +87,23 @@ def main():
|
|
| 87 |
st.session_state.chat_history = None
|
| 88 |
|
| 89 |
st.header("Chat with PDFs :books:")
|
| 90 |
-
|
| 91 |
user_question = st.text_input("Ask a question about your documents:")
|
| 92 |
if user_question:
|
| 93 |
handle_userinput(user_question)
|
| 94 |
|
| 95 |
with st.sidebar:
|
| 96 |
st.subheader("Your documents")
|
| 97 |
-
pdf_docs = st.file_uploader("Upload PDFs", accept_multiple_files=True, type=["pdf"])
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
else:
|
| 109 |
-
st.error("No valid text extracted from the PDFs.")
|
| 110 |
-
else:
|
| 111 |
-
st.info("Please upload PDF files to proceed.")
|
| 112 |
|
| 113 |
if __name__ == '__main__':
|
| 114 |
-
main()
|
|
|
|
| 49 |
# Function to set up the conversational retrieval chain
|
| 50 |
def get_conversation_chain(vectorstore):
|
| 51 |
try:
|
| 52 |
+
llm = ChatGroq(model="llama-3.3-70b-versatile", temperature=0.5)
|
| 53 |
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)
|
| 54 |
|
| 55 |
conversation_chain = ConversationalRetrievalChain.from_llm(
|
|
|
|
| 74 |
role = "User" if i % 2 == 0 else "Bot"
|
| 75 |
st.write(f"*{role}:* {message.content}")
|
| 76 |
else:
|
| 77 |
+
st.warning("Please process the documents first.")
|
| 78 |
|
| 79 |
# Main function to run the Streamlit app
|
| 80 |
def main():
|
|
|
|
| 87 |
st.session_state.chat_history = None
|
| 88 |
|
| 89 |
st.header("Chat with PDFs :books:")
|
|
|
|
| 90 |
user_question = st.text_input("Ask a question about your documents:")
|
| 91 |
if user_question:
|
| 92 |
handle_userinput(user_question)
|
| 93 |
|
| 94 |
with st.sidebar:
|
| 95 |
st.subheader("Your documents")
|
| 96 |
+
pdf_docs = st.file_uploader("Upload PDFs and click 'Process'", accept_multiple_files=True, type=["pdf"])
|
| 97 |
+
if st.button("Process"):
|
| 98 |
+
with st.spinner("Processing..."):
|
| 99 |
+
raw_text = get_pdf_text(pdf_docs)
|
| 100 |
+
if raw_text.strip():
|
| 101 |
+
text_chunks = get_text_chunks(raw_text)
|
| 102 |
+
vectorstore = get_vectorstore(text_chunks)
|
| 103 |
+
st.session_state.conversation = get_conversation_chain(vectorstore)
|
| 104 |
+
st.success("Processing complete! You can now ask questions.")
|
| 105 |
+
else:
|
| 106 |
+
st.error("No valid text extracted from the PDFs.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
if __name__ == '__main__':
|
| 109 |
+
main()
|