gowtham28 commited on
Commit
93c604e
·
verified ·
1 Parent(s): f01051b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -13,6 +13,7 @@ load_dotenv()
13
  os.environ["OPENAI_API_KEY"] = st.secrets["OPENAI_API_KEY"]
14
  os.environ["LANGCHAIN_TRACING_V2"]="true"
15
  os.environ["LANGCHAIN_API_KEY"] = st.secrets["LANGCHAIN_API_KEY"]
 
16
  def get_pdf_text(pdf_docs):
17
  text = ""
18
  for pdf in pdf_docs:
@@ -70,16 +71,18 @@ def main():
70
  st.session_state.chat_history = []
71
 
72
  with st.sidebar:
73
- # st.logo("pic123.png")
74
  st.image("pic123.png")
75
  st.title("Menu:")
76
  pdf_docs = st.file_uploader("Upload your PDF Files and Click on the Submit & Process Button", accept_multiple_files=True)
77
  if st.button("Submit & Process"):
78
- with st.spinner("Processing..."):
79
- raw_text = get_pdf_text(pdf_docs)
80
- text_chunks = get_text_chunks(raw_text)
81
- get_vector_store(text_chunks)
82
- st.success("Done")
 
 
 
83
 
84
  # Display chat history
85
  for idx, chat in enumerate(st.session_state.chat_history):
@@ -97,10 +100,14 @@ def main():
97
  user_question = st.chat_input("Ask a Question from the PDF Files")
98
 
99
  if user_question:
100
- st.session_state.chat_history.append({"role": "user", "content": user_question})
101
- st.chat_message("user").write(user_question)
102
- user_input(user_question)
103
- st.experimental_rerun()
 
 
 
104
 
105
  if __name__ == "__main__":
106
  main()
 
 
13
  os.environ["OPENAI_API_KEY"] = st.secrets["OPENAI_API_KEY"]
14
  os.environ["LANGCHAIN_TRACING_V2"]="true"
15
  os.environ["LANGCHAIN_API_KEY"] = st.secrets["LANGCHAIN_API_KEY"]
16
+
17
  def get_pdf_text(pdf_docs):
18
  text = ""
19
  for pdf in pdf_docs:
 
71
  st.session_state.chat_history = []
72
 
73
  with st.sidebar:
 
74
  st.image("pic123.png")
75
  st.title("Menu:")
76
  pdf_docs = st.file_uploader("Upload your PDF Files and Click on the Submit & Process Button", accept_multiple_files=True)
77
  if st.button("Submit & Process"):
78
+ if pdf_docs:
79
+ with st.spinner("Processing..."):
80
+ raw_text = get_pdf_text(pdf_docs)
81
+ text_chunks = get_text_chunks(raw_text)
82
+ get_vector_store(text_chunks)
83
+ st.success("Done")
84
+ else:
85
+ st.warning("Please upload PDF files first before submitting.")
86
 
87
  # Display chat history
88
  for idx, chat in enumerate(st.session_state.chat_history):
 
100
  user_question = st.chat_input("Ask a Question from the PDF Files")
101
 
102
  if user_question:
103
+ if not pdf_docs:
104
+ st.warning("Please upload PDF files first before asking questions.")
105
+ else:
106
+ st.session_state.chat_history.append({"role": "user", "content": user_question})
107
+ st.chat_message("user").write(user_question)
108
+ user_input(user_question)
109
+ st.experimental_rerun()
110
 
111
  if __name__ == "__main__":
112
  main()
113
+