Spaces:
Sleeping
Sleeping
Update app.py
Browse files199 unmodified lines20020120220320420520620754 unmodified lines26226326426526626711 unmodified lines2792802812822832842852864 unmodified lines29129229329429529629721 unmodified lines319320321322323324199 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.Answer the following question:{question}""")54 unmodified lines# Get current uploaded filenamescurrent_uploaded_filenames = {file.name for file in uploaded_files} if uploaded_files else set()# Process newly uploaded filesif uploaded_files:files_added = False11 unmodified lines# Check for changes in filescurrent_files = set(st.session_state.uploaded_files.keys())# Process documents only if files have changedif current_files != st.session_state.previous_files:st.session_state.previous_files = current_filesif current_files:4 unmodified linesst.session_state.processing = Falseelse:st.warning('Please upload a file to continue')st.session_state.chat_enabled = False# If files exist and chat is enabled, show chat interfaceif current_files and st.session_state.chat_enabled:21 unmodified linesst.session_state.chat_enabled = False# Clear the previous files to force reprocessingst.session_state.previous_files = set()# Call the main functionprocess_and_chat()199 unmodified lines20020120220320420520620754 unmodified lines26226326426526626726826927027127227327427527627727827928011 unmodified lines2922932942952962972982993003013023033044 unmodified lines30931031131231331421 unmodified lines336337338339340341342343199 unmodified lines{context}</context>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 filenamescurrent_uploaded_filenames = {file.name for file in uploaded_files} if uploaded_files else set()# Check for removed filesfiles_to_remove = set(st.session_state.uploaded_files.keys()) - current_uploaded_filenamesif files_to_remove:for file_name in files_to_remove:# Remove file from session stateif file_name in st.session_state.uploaded_files:# Delete the file from data directoryfile_path = st.session_state.uploaded_files[file_name]["path"]if os.path.exists(file_path):os.remove(file_path)# Remove from session statedel st.session_state.uploaded_files[file_name]# Process newly uploaded filesif uploaded_files:files_added = False11 unmodified lines# Check for changes in filescurrent_files = set(st.session_state.uploaded_files.keys())# If files have changed (added or removed), reset chat and process documentsif current_files != st.session_state.previous_files or files_to_remove:# Reset chat statest.session_state.chat_enabled = Falseif "messages" in st.session_state:del st.session_state.messagesst.session_state.previous_files = current_filesif current_files:4 unmodified linesst.session_state.processing = Falseelse:st.warning('Please upload a file to continue')# If files exist and chat is enabled, show chat interfaceif current_files and st.session_state.chat_enabled:21 unmodified linesst.session_state.chat_enabled = False# Clear the previous files to force reprocessingst.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