Skip to content

Commit

Permalink
Merge pull request #330 from MichaelClifford/pdf
Browse files Browse the repository at this point in the history
set summarizer write to tempfile
  • Loading branch information
rhatdan authored Apr 24, 2024
2 parents 524c759 + 9f8dab0 commit 0109d08
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
langchain
langchain_openai
streamlit
streamlit
pypdf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from langchain_community.callbacks import StreamlitCallbackHandler
from langchain_community.document_loaders import PyPDFLoader
import streamlit as st
import tempfile
import requests
import time
import os
Expand Down Expand Up @@ -49,12 +50,12 @@ def read_file(file):
file_type = file.type

if file_type == "application/pdf":
with open(file.name, "wb") as f:
temp = tempfile.NamedTemporaryFile()
with open(temp.name, "wb") as f:
f.write(file.getvalue())
loader = PyPDFLoader(file.name)
loader = PyPDFLoader(temp.name)
pages = loader.load()
text = "".join([p.page_content for p in pages])
os.remove(file.name)

if file_type == "text/plain":
text = file.read().decode()
Expand Down

0 comments on commit 0109d08

Please sign in to comment.