diff --git a/recipes/natural_language_processing/summarizer/app/requirements.txt b/recipes/natural_language_processing/summarizer/app/requirements.txt index 8bf95409..7f30524f 100644 --- a/recipes/natural_language_processing/summarizer/app/requirements.txt +++ b/recipes/natural_language_processing/summarizer/app/requirements.txt @@ -1,3 +1,4 @@ langchain langchain_openai -streamlit \ No newline at end of file +streamlit +pypdf diff --git a/recipes/natural_language_processing/summarizer/app/summarizer.py b/recipes/natural_language_processing/summarizer/app/summarizer.py index 687a3652..bb39bf21 100644 --- a/recipes/natural_language_processing/summarizer/app/summarizer.py +++ b/recipes/natural_language_processing/summarizer/app/summarizer.py @@ -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 @@ -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()