Commit
·
6346352
1
Parent(s):
64ecac0
Update app.py
Browse files
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 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
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 |
|