hail75 commited on
Commit
8c922bb
·
1 Parent(s): 9cc55aa

fix pdf bug

Browse files
Files changed (1) hide show
  1. app.py +5 -1
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import os
2
  import streamlit as st
 
3
 
4
  from langchain_openai import OpenAIEmbeddings
5
  from langchain_openai.chat_models import ChatOpenAI
@@ -42,7 +43,10 @@ def add_text_to_chroma(text):
42
 
43
 
44
  def add_pdf_to_chroma(uploaded_pdf):
45
- loader = PyPDFLoader(uploaded_pdf)
 
 
 
46
  pages = loader.load()
47
  embeddings = OpenAIEmbeddings()
48
  text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=150)
 
1
  import os
2
  import streamlit as st
3
+ import tempfile
4
 
5
  from langchain_openai import OpenAIEmbeddings
6
  from langchain_openai.chat_models import ChatOpenAI
 
43
 
44
 
45
  def add_pdf_to_chroma(uploaded_pdf):
46
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_file:
47
+ tmp_file.write(uploaded_pdf.read())
48
+ tmp_file_path = tmp_file.name
49
+ loader = PyPDFLoader(tmp_file_path)
50
  pages = loader.load()
51
  embeddings = OpenAIEmbeddings()
52
  text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=150)