Spaces:
Running
Running
luanpoppe
commited on
Commit
·
3462a1d
1
Parent(s):
668a7d5
feat: tentando extrair texto de .doc sem usar o textract
Browse files
_utils/bubble_integrations/obter_arquivo.py
CHANGED
|
@@ -8,8 +8,10 @@ from langchain_community.document_loaders import (
|
|
| 8 |
)
|
| 9 |
import tempfile
|
| 10 |
import requests
|
| 11 |
-
import textract
|
| 12 |
|
|
|
|
|
|
|
|
|
|
| 13 |
from _utils.handle_files import return_document_list_with_llama_parser
|
| 14 |
from _utils.langchain_utils.splitter_util import Splitter_Simple, SplitterUtils
|
| 15 |
|
|
@@ -56,8 +58,8 @@ async def get_pdf_from_bubble(
|
|
| 56 |
result = TextLoader(temp_path).load()
|
| 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 =
|
| 61 |
result = splitter_simple.load_and_split_text(full_text)
|
| 62 |
else:
|
| 63 |
temp_path = download_file_from_bubble(file_url, headers, ".docx")
|
|
|
|
| 8 |
)
|
| 9 |
import tempfile
|
| 10 |
import requests
|
|
|
|
| 11 |
|
| 12 |
+
# import textract
|
| 13 |
+
|
| 14 |
+
from _utils.gerar_documento_utils.utils import getTextFromDotDoc
|
| 15 |
from _utils.handle_files import return_document_list_with_llama_parser
|
| 16 |
from _utils.langchain_utils.splitter_util import Splitter_Simple, SplitterUtils
|
| 17 |
|
|
|
|
| 58 |
result = TextLoader(temp_path).load()
|
| 59 |
elif extension.lower() == "doc":
|
| 60 |
temp_path = download_file_from_bubble(file_url, headers, ".doc")
|
| 61 |
+
# full_text_binary = textract.process(temp_path)
|
| 62 |
+
full_text = getTextFromDotDoc(temp_path)
|
| 63 |
result = splitter_simple.load_and_split_text(full_text)
|
| 64 |
else:
|
| 65 |
temp_path = download_file_from_bubble(file_url, headers, ".docx")
|
_utils/gerar_documento_utils/utils.py
CHANGED
|
@@ -125,3 +125,24 @@ 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
_utils/langchain_utils/Splitter_class.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 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,
|
|
@@ -18,7 +19,7 @@ from _utils.models.gerar_documento import (
|
|
| 18 |
DocumentChunk,
|
| 19 |
)
|
| 20 |
import uuid
|
| 21 |
-
import textract
|
| 22 |
|
| 23 |
|
| 24 |
class Splitter:
|
|
@@ -83,8 +84,8 @@ class Splitter:
|
|
| 83 |
elif file_extension == "txt":
|
| 84 |
pages = TextLoader(pdf_path).load()
|
| 85 |
elif file_extension == "doc":
|
| 86 |
-
full_text_binary = textract.process(pdf_path)
|
| 87 |
-
full_text =
|
| 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.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,
|
|
|
|
| 19 |
DocumentChunk,
|
| 20 |
)
|
| 21 |
import uuid
|
| 22 |
+
# import textract
|
| 23 |
|
| 24 |
|
| 25 |
class Splitter:
|
|
|
|
| 84 |
elif file_extension == "txt":
|
| 85 |
pages = TextLoader(pdf_path).load()
|
| 86 |
elif file_extension == "doc":
|
| 87 |
+
# full_text_binary = textract.process(pdf_path)
|
| 88 |
+
full_text = getTextFromDotDoc(pdf_path)
|
| 89 |
pages = self.splitter_simple.load_and_split_text(full_text)
|
| 90 |
else:
|
| 91 |
pages = Docx2txtLoader(pdf_path).load()
|
requirements.txt
CHANGED
|
Binary files a/requirements.txt and b/requirements.txt differ
|
|
|