danishjameel003 commited on
Commit
0d30433
·
verified ·
1 Parent(s): 208b4b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -112,7 +112,7 @@ def handle_question(question, vectorstore=None):
112
  return llm_chain.invoke({"instruction": question})
113
 
114
  def main():
115
- st.title("Ask AI :books:")
116
 
117
  # Initialize session state
118
  if "vectorstore" not in st.session_state:
@@ -135,19 +135,31 @@ def main():
135
 
136
  # Process data folder for vectorstore
137
  subject_folder_path = subject_folders[selected_subject]
 
138
  if os.path.exists(subject_folder_path):
139
  raw_text = get_text_files_content(subject_folder_path)
140
  if raw_text:
141
  text_chunks = get_chunks(raw_text)
142
  vectorstore = get_vectorstore(text_chunks)
143
  st.session_state.vectorstore = vectorstore
 
 
 
 
 
 
 
 
 
144
 
145
  # Chat interface
 
146
  question = st.text_input("Ask a question about your selected subject:")
147
  if question:
148
  if st.session_state.vectorstore:
149
  response = handle_question(question, st.session_state.vectorstore)
150
- st.write(response)
 
151
  else:
152
  st.warning("Please load the content for the selected subject before asking a question.")
153
 
 
112
  return llm_chain.invoke({"instruction": question})
113
 
114
  def main():
115
+ st.title("Chat with Notes :books:")
116
 
117
  # Initialize session state
118
  if "vectorstore" not in st.session_state:
 
135
 
136
  # Process data folder for vectorstore
137
  subject_folder_path = subject_folders[selected_subject]
138
+ raw_text = ""
139
  if os.path.exists(subject_folder_path):
140
  raw_text = get_text_files_content(subject_folder_path)
141
  if raw_text:
142
  text_chunks = get_chunks(raw_text)
143
  vectorstore = get_vectorstore(text_chunks)
144
  st.session_state.vectorstore = vectorstore
145
+ else:
146
+ st.warning("No content found for the selected subject.")
147
+ else:
148
+ st.error(f"Folder not found for {selected_subject}.")
149
+
150
+ # Display preview of notes
151
+ if raw_text:
152
+ st.subheader("Preview of Notes")
153
+ st.text_area("Preview Content:", value=raw_text[:2000], height=300, disabled=True) # Show a snippet of the notes
154
 
155
  # Chat interface
156
+ st.subheader("Ask Your Question")
157
  question = st.text_input("Ask a question about your selected subject:")
158
  if question:
159
  if st.session_state.vectorstore:
160
  response = handle_question(question, st.session_state.vectorstore)
161
+ st.subheader("Answer:")
162
+ st.write(response.get("text", "No response found."))
163
  else:
164
  st.warning("Please load the content for the selected subject before asking a question.")
165