stivenDR14
commited on
Commit
·
e0fe7b4
1
Parent(s):
a71c291
set up spaces zero-gpu
Browse files- pdf_processor.py +5 -4
pdf_processor.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import json
|
2 |
import tempfile
|
|
|
3 |
from langchain_community.document_loaders import PyPDFLoader
|
4 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
5 |
from langchain_ollama import OllamaEmbeddings
|
@@ -143,7 +144,7 @@ class PDFProcessor:
|
|
143 |
)
|
144 |
return current_llm, embeding_model
|
145 |
|
146 |
-
|
147 |
def process_pdf(self, pdf_file, chunk_size, chunk_overlap, ai_model, type_model, api_key, project_id_watsonx):
|
148 |
defined_chunk_size = 1000
|
149 |
defined_chunk_overlap = 150
|
@@ -195,7 +196,7 @@ class PDFProcessor:
|
|
195 |
else:
|
196 |
return TRANSLATIONS[self.language]["load_pdf_first"]
|
197 |
|
198 |
-
|
199 |
def get_qa_response(self, message, history, ai_model, type_model, api_key, project_id_watsonx, k=4):
|
200 |
current_llm, _ = self.set_llm(ai_model, type_model, api_key, project_id_watsonx)
|
201 |
|
@@ -219,7 +220,7 @@ class PDFProcessor:
|
|
219 |
|
220 |
return result["result"] + "\n\nSources: " + page_labels_text
|
221 |
|
222 |
-
|
223 |
def summarizer_by_k_top_n(self, ai_model, type_model, api_key, project_id_watsonx, k, summary_prompt, just_get_documments=False):
|
224 |
if not self.vectorstore:
|
225 |
return TRANSLATIONS[self.language]["load_pdf_first"]
|
@@ -256,7 +257,7 @@ class PDFProcessor:
|
|
256 |
return self.summarizer_by_k_top_n(ai_model, type_model, api_key, project_id_watsonx, k, final_summary_prompt, just_get_documments)
|
257 |
|
258 |
|
259 |
-
|
260 |
def get_specialist_opinion(self, ai_model, type_model, api_key, project_id_watsonx, specialist_prompt):
|
261 |
questions_prompt = PromptTemplate(
|
262 |
input_variables=["text", "specialist_prompt", "language"],
|
|
|
1 |
import json
|
2 |
import tempfile
|
3 |
+
import spaces
|
4 |
from langchain_community.document_loaders import PyPDFLoader
|
5 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
6 |
from langchain_ollama import OllamaEmbeddings
|
|
|
144 |
)
|
145 |
return current_llm, embeding_model
|
146 |
|
147 |
+
@spaces.GPU
|
148 |
def process_pdf(self, pdf_file, chunk_size, chunk_overlap, ai_model, type_model, api_key, project_id_watsonx):
|
149 |
defined_chunk_size = 1000
|
150 |
defined_chunk_overlap = 150
|
|
|
196 |
else:
|
197 |
return TRANSLATIONS[self.language]["load_pdf_first"]
|
198 |
|
199 |
+
@spaces.GPU
|
200 |
def get_qa_response(self, message, history, ai_model, type_model, api_key, project_id_watsonx, k=4):
|
201 |
current_llm, _ = self.set_llm(ai_model, type_model, api_key, project_id_watsonx)
|
202 |
|
|
|
220 |
|
221 |
return result["result"] + "\n\nSources: " + page_labels_text
|
222 |
|
223 |
+
@spaces.GPU
|
224 |
def summarizer_by_k_top_n(self, ai_model, type_model, api_key, project_id_watsonx, k, summary_prompt, just_get_documments=False):
|
225 |
if not self.vectorstore:
|
226 |
return TRANSLATIONS[self.language]["load_pdf_first"]
|
|
|
257 |
return self.summarizer_by_k_top_n(ai_model, type_model, api_key, project_id_watsonx, k, final_summary_prompt, just_get_documments)
|
258 |
|
259 |
|
260 |
+
@spaces.GPU
|
261 |
def get_specialist_opinion(self, ai_model, type_model, api_key, project_id_watsonx, specialist_prompt):
|
262 |
questions_prompt = PromptTemplate(
|
263 |
input_variables=["text", "specialist_prompt", "language"],
|