Francesco-A commited on
Commit
e858d98
·
1 Parent(s): 921f45c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -75,7 +75,11 @@ Summary:"""
75
  # Implementation
76
  def summarize(pdf_file, custom_prompt, custom_chunk, chunk_size, chunk_overlap):
77
  try:
78
- loader = PyPDFLoader(pdf_file.name)
 
 
 
 
79
  if custom_chunk:
80
  text_splitter = RecursiveCharacterTextSplitter(chunk_size=chunk_size, chunk_overlap=chunk_overlap)
81
  docs = loader.load_and_split(text_splitter=text_splitter)
@@ -86,8 +90,8 @@ def summarize(pdf_file, custom_prompt, custom_chunk, chunk_size, chunk_overlap):
86
  chain = load_summarize_chain(hub_llm, chain_type='map_reduce', combine_prompt=PROMPT)
87
 
88
  # Introduce a delay before calling the API
89
- time.sleep(1)
90
- summary = chain.run(docs)
91
  return summary
92
  except Exception as e:
93
  return f"An error occurred: {e}"
 
75
  # Implementation
76
  def summarize(pdf_file, custom_prompt, custom_chunk, chunk_size, chunk_overlap):
77
  try:
78
+ # Get the uploaded file path
79
+ file_path = pdf_file.name
80
+
81
+ # Load and process the PDF
82
+ loader = PyPDFLoader(file_path)
83
  if custom_chunk:
84
  text_splitter = RecursiveCharacterTextSplitter(chunk_size=chunk_size, chunk_overlap=chunk_overlap)
85
  docs = loader.load_and_split(text_splitter=text_splitter)
 
90
  chain = load_summarize_chain(hub_llm, chain_type='map_reduce', combine_prompt=PROMPT)
91
 
92
  # Introduce a delay before calling the API
93
+ time.sleep(2)
94
+ summary = chain.invoke(docs)['output_text']
95
  return summary
96
  except Exception as e:
97
  return f"An error occurred: {e}"