Spaces:
Sleeping
Sleeping
Update app.py
Browse files199 unmodified lines20020120220320420320420520620754 unmodified lines26226326426526626726826927027127227327427527627727827928011 unmodified lines2922932942822832952962972982993003013023033044 unmodified lines30931031129431231331421 unmodified lines336337338339340341342343199 unmodified lines {context} </context>
Important: You cannot quote the context in the responses. If you do that, there will be a strict penalty for it. Important: Don't start revealing context in your responses until its asked. First look at the question and then think if the context is needed to answer this or its a normal question, once you have judged then only answer the question.
Answer the following question:
{question}""")54 unmodified lines # Get current uploaded filenames current_uploaded_filenames = {file.name for file in uploaded_files} if uploaded_files else set()
# Check for removed files files_to_remove = set(st.session_state.uploaded_files.keys()) - current_uploaded_filenames if files_to_remove: for file_name in files_to_remove: # Remove file from session state if file_name in st.session_state.uploaded_files: # Delete the file from data directory file_path = st.session_state.uploaded_files[file_name]["path"] if os.path.exists(file_path): os.remove(file_path) # Remove from session state del st.session_state.uploaded_files[file_name]
# Process newly uploaded files if uploaded_files: files_added = False11 unmodified lines # Check for changes in files current_files = set(st.session_state.uploaded_files.keys())
# Process documents only if files have changed if current_files != st.session_state.previous_files: # If files have changed (added or removed), reset chat and process documents if current_files != st.session_state.previous_files or files_to_remove: # Reset chat state st.session_state.chat_enabled = False if "messages" in st.session_state: del st.session_state.messages st.session_state.previous_files = current_files if current_files:4 unmodified lines st.session_state.processing = False else: st.warning('Please upload a file to continue') st.session_state.chat_enabled = False # If files exist and chat is enabled, show chat interface if current_files and st.session_state.chat_enabled:21 unmodified lines st.session_state.chat_enabled = False # Clear the previous files to force reprocessing st.session_state.previous_files = set() if "messages" in st.session_state: del st.session_state.messages
# Call the main functionprocess_and_chat()app.py+24-5