luanpoppe commited on
Commit
4ef8d92
·
1 Parent(s): 352cc1a

fix: importação circular

Browse files
_utils/bubble_integrations/obter_arquivo.py CHANGED
@@ -9,7 +9,6 @@ from langchain_community.document_loaders import (
9
  import tempfile
10
  import requests
11
 
12
- from _utils.gerar_documento_utils.utils import getTextFromDotDoc
13
  from _utils.handle_files import return_document_list_with_llama_parser
14
  from _utils.langchain_utils.splitter_util import Splitter_Simple, SplitterUtils
15
 
@@ -57,7 +56,7 @@ async def get_pdf_from_bubble(
57
  elif extension.lower() == "doc":
58
  temp_path = download_file_from_bubble(file_url, headers, ".doc")
59
  # full_text_binary = textract.process(temp_path)
60
- full_text = getTextFromDotDoc(temp_path)
61
  result = splitter_simple.load_and_split_text(full_text)
62
  else:
63
  temp_path = download_file_from_bubble(file_url, headers, ".docx")
 
9
  import tempfile
10
  import requests
11
 
 
12
  from _utils.handle_files import return_document_list_with_llama_parser
13
  from _utils.langchain_utils.splitter_util import Splitter_Simple, SplitterUtils
14
 
 
56
  elif extension.lower() == "doc":
57
  temp_path = download_file_from_bubble(file_url, headers, ".doc")
58
  # full_text_binary = textract.process(temp_path)
59
+ full_text = splitter_utils.getTextFromDotDoc(temp_path)
60
  result = splitter_simple.load_and_split_text(full_text)
61
  else:
62
  temp_path = download_file_from_bubble(file_url, headers, ".docx")
_utils/gerar_documento_utils/utils.py CHANGED
@@ -125,24 +125,3 @@ async def generate_document_title(resumo_para_gerar_titulo: str):
125
  prompt = f"Você é um assistente jurídico e irá receber abaixo o resumo de um documento jurídico. Quero que você gere um título para este documento. Mande como resposta apenas o título gerado, nada mais. Aqui está um título de exemplo pra você se basear ao criar um novo: <titulo_de_exemplo>Ação Penal por Furto Qualificado nº 0002269-86.2009.805.0032<titulo_de_exemplo>\n\nSegue abaixo o resumo do documento jurídico:\n{resumo_para_gerar_titulo}"
126
  response = await agemini_answer(prompt, "gemini-2.0-flash-lite")
127
  return response
128
-
129
-
130
- def getTextFromDotDoc(file_path: str):
131
- import subprocess
132
- import shutil
133
-
134
- antiword_path = shutil.which("antiword")
135
- command = [antiword_path, "-m", "UTF-8", file_path]
136
-
137
- # Execute the command
138
- result = subprocess.run(
139
- command,
140
- capture_output=True, # Capture stdout and stderr
141
- text=True, # Decode stdout/stderr as text using utf-8
142
- check=True, # Raise CalledProcessError on non-zero exit code
143
- encoding="utf-8", # Explicitly specify decoding
144
- )
145
-
146
- # Success! The extracted text is in result.stdout
147
- extracted_text = result.stdout
148
- return extracted_text
 
125
  prompt = f"Você é um assistente jurídico e irá receber abaixo o resumo de um documento jurídico. Quero que você gere um título para este documento. Mande como resposta apenas o título gerado, nada mais. Aqui está um título de exemplo pra você se basear ao criar um novo: <titulo_de_exemplo>Ação Penal por Furto Qualificado nº 0002269-86.2009.805.0032<titulo_de_exemplo>\n\nSegue abaixo o resumo do documento jurídico:\n{resumo_para_gerar_titulo}"
126
  response = await agemini_answer(prompt, "gemini-2.0-flash-lite")
127
  return response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
_utils/langchain_utils/Splitter_class.py CHANGED
@@ -1,5 +1,4 @@
1
  from _utils.bubble_integrations.obter_arquivo import get_pdf_from_bubble
2
- from _utils.gerar_documento_utils.utils import getTextFromDotDoc
3
  from _utils.handle_files import return_document_list_with_llama_parser
4
  from _utils.langchain_utils.splitter_util import (
5
  Splitter_Simple,
@@ -84,7 +83,7 @@ class Splitter:
84
  pages = TextLoader(pdf_path).load()
85
  elif file_extension == "doc":
86
  # full_text_binary = textract.process(pdf_path)
87
- full_text = getTextFromDotDoc(pdf_path)
88
  pages = self.splitter_simple.load_and_split_text(full_text)
89
  else:
90
  pages = Docx2txtLoader(pdf_path).load()
 
1
  from _utils.bubble_integrations.obter_arquivo import get_pdf_from_bubble
 
2
  from _utils.handle_files import return_document_list_with_llama_parser
3
  from _utils.langchain_utils.splitter_util import (
4
  Splitter_Simple,
 
83
  pages = TextLoader(pdf_path).load()
84
  elif file_extension == "doc":
85
  # full_text_binary = textract.process(pdf_path)
86
+ full_text = self.splitter_util.getTextFromDotDoc(pdf_path)
87
  pages = self.splitter_simple.load_and_split_text(full_text)
88
  else:
89
  pages = Docx2txtLoader(pdf_path).load()
_utils/langchain_utils/splitter_util.py CHANGED
@@ -36,6 +36,26 @@ class SplitterUtils:
36
  text.append(node.data)
37
  return "\n".join(text)
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  class Splitter_Simple:
41
  def __init__(
 
36
  text.append(node.data)
37
  return "\n".join(text)
38
 
39
+ def getTextFromDotDoc(self, file_path: str):
40
+ import subprocess
41
+ import shutil
42
+
43
+ antiword_path = shutil.which("antiword")
44
+ command = [antiword_path, "-m", "UTF-8", file_path]
45
+
46
+ # Execute the command
47
+ result = subprocess.run(
48
+ command,
49
+ capture_output=True, # Capture stdout and stderr
50
+ text=True, # Decode stdout/stderr as text using utf-8
51
+ check=True, # Raise CalledProcessError on non-zero exit code
52
+ encoding="utf-8", # Explicitly specify decoding
53
+ )
54
+
55
+ # Success! The extracted text is in result.stdout
56
+ extracted_text = result.stdout
57
+ return extracted_text
58
+
59
 
60
  class Splitter_Simple:
61
  def __init__(