meesamraza commited on
Commit
b1cf005
·
verified ·
1 Parent(s): fa94a3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -19
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-3-70b-vision", temperature=0.5)
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 upload and process documents first.")
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
- if pdf_docs:
100
- if st.button("Submit"):
101
- with st.spinner("Processing..."):
102
- raw_text = get_pdf_text(pdf_docs)
103
- if raw_text.strip():
104
- text_chunks = get_text_chunks(raw_text)
105
- vectorstore = get_vectorstore(text_chunks)
106
- st.session_state.conversation = get_conversation_chain(vectorstore)
107
- st.success("Processing complete! You can now ask questions.")
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()