Skip to content

Commit

Permalink
use tempfile for summarizer
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Clifford <[email protected]>
  • Loading branch information
MichaelClifford committed Apr 24, 2024
1 parent 8f96b15 commit 9f8dab0
Showing 1 changed file with 4 additions and 3 deletions.
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(f"/tmp/{file.name}", "wb") as f:
temp = tempfile.NamedTemporaryFile()
with open(temp.name, "wb") as f:
f.write(file.getvalue())
loader = PyPDFLoader(f"/tmp/{file.name}")
loader = PyPDFLoader(temp.name)
pages = loader.load()
text = "".join([p.page_content for p in pages])
os.remove(f"/tmp/{file.name}")

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

0 comments on commit 9f8dab0

Please sign in to comment.