Spaces:
Build error
Build error
Update app.py
Browse files10 unmodified lines11121314151617181920212223242526272829303110 unmodified lines4243444546474849505121 unmodified lines73747576777879808182838485868788899091929310 unmodified linesfrom langchain_core.output_parsers import StrOutputParserfrom langchain_core.prompts import PromptTemplatefrom langchain_community.document_loaders import WebBaseLoaderfrom langchain_community.document_loaders import PyPDFLoaderfrom langchain_community.vectorstores import Chromafrom langchain_community.embeddings.sentence_transformer import SentenceTransformerEmbeddingsfrom langchain_text_splitters import RecursiveCharacterTextSplittericons = {"assistant": "robot.png", "user": "man-kddi.png"}# DATA_DIR = "data"# Ensure data directory exists# os.makedirs(DATA_DIR, exist_ok=True)# if not hasattr(st.session_state, 'agent'):# st.session_state.agent = "None"'''def init_agent_with_docs():docs=[]10 unmodified linesreturn RAGAgent(docs)def remove_old_files():st.session_state["console_out"] += "remove_old_files\n"shutil.rmtree(DATA_DIR)os.makedirs(DATA_DIR)'''def streamer(text):for i in text:21 unmodified linesif st.button("Submit & Process"):with st.spinner("Processing..."):st.session_state["console_out"] = ""#if len(os.listdir(DATA_DIR)) !=0:# remove_old_files()'''for index, file in enumerate(uploaded_files):filepath = os.path.join(DATA_DIR, f"saved_pdf_{index}.pdf")with open(filepath, "wb") as f:f.write(file.getbuffer())st.session_state.agent = init_agent_with_docs()'''if uploaded_files:pdf_docs = []for uploaded_file in uploaded_files:pdf_loader = PyPDFLoader(uploaded_file)pdf_docs.append(pdf_loader)st.session_state.agent = RAGAgent(pdf_docs)st.success("Done")st.text_area("Console", st.session_state["console_out"], height=250)10 unmodified lines11121314151617181920212223242526272829303110 unmodified lines4243444546474849505121 unmodified lines7374757677787980818283848510 unmodified linesfrom langchain_core.output_parsers import StrOutputParserfrom langchain_core.prompts import PromptTemplatefrom langchain_community.document_loaders import WebBaseLoaderfrom langchain_community.document_loaders import PyPDFDirectoryLoaderfrom langchain_community.vectorstores import Chromafrom langchain_community.embeddings.sentence_transformer import SentenceTransformerEmbeddingsfrom langchain_text_splitters import RecursiveCharacterTextSplittericons = {"assistant": "robot.png", "user": "man-kddi.png"}DATA_DIR = "data"# Ensure data directory existsos.makedirs(DATA_DIR, exist_ok=True)# if not hasattr(st.session_state, 'agent'):# st.session_state.agent = "None"def init_agent_with_docs():docs=[]10 unmodified linesreturn RAGAgent(docs)def remove_old_files():if len(os.listdir(DATA_DIR)) !=0:st.session_state["console_out"] += "remove_old_files\n"shutil.rmtree(DATA_DIR)os.makedirs(DATA_DIR)def streamer(text):for i in text:21 unmodified linesif st.button("Submit & Process"):with st.spinner("Processing..."):st.session_state["console_out"] = ""remove_old_files()for index, file in enumerate(uploaded_files):filepath = os.path.join(DATA_DIR, f"saved_pdf_{index}.pdf")with open(filepath, "wb") as f:f.write(file.getbuffer())st.session_state.agent = init_agent_with_docs()remove_old_files()st.success("Done")st.text_area("Console", st.session_state["console_out"], height=250)
app.py+10-18