fehmikaya commited on
Commit
abf89cd
·
verified ·
1 Parent(s): ac08c88

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -11,20 +11,21 @@ from langchain_core.output_parsers import JsonOutputParser
11
  from langchain_core.output_parsers import StrOutputParser
12
  from langchain_core.prompts import PromptTemplate
13
  from langchain_community.document_loaders import WebBaseLoader
14
- from langchain_community.document_loaders import PyPDFDirectoryLoader
15
  from langchain_community.vectorstores import Chroma
16
  from langchain_community.embeddings.sentence_transformer import SentenceTransformerEmbeddings
17
  from langchain_text_splitters import RecursiveCharacterTextSplitter
18
 
19
 
20
  icons = {"assistant": "robot.png", "user": "man-kddi.png"}
21
- DATA_DIR = "data"
22
  # Ensure data directory exists
23
- os.makedirs(DATA_DIR, exist_ok=True)
24
 
25
- if not hasattr(st.session_state, 'agent'):
26
- st.session_state.agent = "None"
27
 
 
28
  def init_agent_with_docs():
29
 
30
  docs=[]
@@ -44,6 +45,7 @@ def remove_old_files():
44
  st.session_state["console_out"] += "remove_old_files\n"
45
  shutil.rmtree(DATA_DIR)
46
  os.makedirs(DATA_DIR)
 
47
 
48
  def streamer(text):
49
  for i in text:
@@ -71,13 +73,21 @@ with st.sidebar:
71
  if st.button("Submit & Process"):
72
  with st.spinner("Processing..."):
73
  st.session_state["console_out"] = ""
74
- if len(os.listdir(DATA_DIR)) !=0:
75
- remove_old_files()
 
76
  for index, file in enumerate(uploaded_files):
77
  filepath = os.path.join(DATA_DIR, f"saved_pdf_{index}.pdf")
78
  with open(filepath, "wb") as f:
79
  f.write(file.getbuffer())
80
  st.session_state.agent = init_agent_with_docs()
 
 
 
 
 
 
 
81
  st.success("Done")
82
  st.text_area("Console", st.session_state["console_out"], height=250)
83
 
 
11
  from langchain_core.output_parsers import StrOutputParser
12
  from langchain_core.prompts import PromptTemplate
13
  from langchain_community.document_loaders import WebBaseLoader
14
+ from langchain_community.document_loaders import PyPDFLoader
15
  from langchain_community.vectorstores import Chroma
16
  from langchain_community.embeddings.sentence_transformer import SentenceTransformerEmbeddings
17
  from langchain_text_splitters import RecursiveCharacterTextSplitter
18
 
19
 
20
  icons = {"assistant": "robot.png", "user": "man-kddi.png"}
21
+ # DATA_DIR = "data"
22
  # Ensure data directory exists
23
+ # os.makedirs(DATA_DIR, exist_ok=True)
24
 
25
+ # if not hasattr(st.session_state, 'agent'):
26
+ # st.session_state.agent = "None"
27
 
28
+ '''
29
  def init_agent_with_docs():
30
 
31
  docs=[]
 
45
  st.session_state["console_out"] += "remove_old_files\n"
46
  shutil.rmtree(DATA_DIR)
47
  os.makedirs(DATA_DIR)
48
+ '''
49
 
50
  def streamer(text):
51
  for i in text:
 
73
  if st.button("Submit & Process"):
74
  with st.spinner("Processing..."):
75
  st.session_state["console_out"] = ""
76
+ #if len(os.listdir(DATA_DIR)) !=0:
77
+ # remove_old_files()
78
+ '''
79
  for index, file in enumerate(uploaded_files):
80
  filepath = os.path.join(DATA_DIR, f"saved_pdf_{index}.pdf")
81
  with open(filepath, "wb") as f:
82
  f.write(file.getbuffer())
83
  st.session_state.agent = init_agent_with_docs()
84
+ '''
85
+ if uploaded_files:
86
+ pdf_docs = []
87
+ for uploaded_file in uploaded_files:
88
+ pdf_loader = PyPDFLoader(uploaded_file)
89
+ pdf_docs.append(pdf_loader)
90
+ st.session_state.agent = RAGAgent(docs)
91
  st.success("Done")
92
  st.text_area("Console", st.session_state["console_out"], height=250)
93