Francesco-A commited on
Commit
6346352
·
1 Parent(s): 64ecac0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -15
app.py CHANGED
@@ -105,21 +105,24 @@ def summarize(pdf_file, custom_prompt, custom_chunk, chunk_size, chunk_overlap):
105
  # Set the token for hub_llm within the function
106
  hub_llm.model_kwargs["huggingfacehub_api_token"] = huggingfacehub_api_token
107
 
108
- try:
109
- loader = PyPDFLoader(pdf_file.name)
110
- if custom_chunk:
111
- text_splitter = RecursiveCharacterTextSplitter(chunk_size=chunk_size, chunk_overlap=chunk_overlap)
112
- docs = loader.load_and_split(text_splitter=text_splitter)
113
- else:
114
- docs = loader.load_and_split()
115
-
116
- PROMPT = PromptTemplate(template=custom_prompt, input_variables=['text'])
117
- chain = load_summarize_chain(hub_llm, chain_type='map_reduce', combine_prompt=PROMPT)
118
-
119
- # Introduce a delay before calling the API
120
- time.sleep(1)
121
- summary = chain.run(docs)
122
- return summary
 
 
 
123
  except Exception as e:
124
  return f"An error occurred: {e}"
125
 
 
105
  # Set the token for hub_llm within the function
106
  hub_llm.model_kwargs["huggingfacehub_api_token"] = huggingfacehub_api_token
107
 
108
+ try:
109
+ loader = PyPDFLoader(pdf_file.name)
110
+ if custom_chunk:
111
+ text_splitter = RecursiveCharacterTextSplitter(chunk_size=chunk_size, chunk_overlap=chunk_overlap)
112
+ docs = loader.load_and_split(text_splitter=text_splitter)
113
+ else:
114
+ docs = loader.load_and_split()
115
+
116
+ PROMPT = PromptTemplate(template=custom_prompt, input_variables=['text'])
117
+ chain = load_summarize_chain(hub_llm, chain_type='map_reduce', combine_prompt=PROMPT)
118
+
119
+ # Introduce a delay before calling the API
120
+ time.sleep(1)
121
+ summary = chain.run(docs)
122
+ return summary
123
+ except Exception as e:
124
+ return f"An error occurred: {e}"
125
+
126
  except Exception as e:
127
  return f"An error occurred: {e}"
128