Portuguese
mamba
mamba-3
ssm
muon
muonclip
qk-clip
adamw
optimizer
nope
hybrid-architecture
activation-checkpointing
3d-vision-language
depth-perception
point-cloud
diffusion
stable-diffusion
mixture-of-experts
kohonen
som-attention
random-forest
deep-neural-network
knowledge-distillation
bidirectional-distillation
engram-memory
multimodal
multi-token-prediction
dpo
rlhf
hh-rlhf
pcgrad
long-context
lra-qvit
engineer-agent
integral-state
cython
jev-classifiers
gumbel-softmax
quantization
riemannian-optimization
stiefel-manifold
cython-kernels
gradient-accumulation
vector-quantization
grayscale-detection
joint-perception
self-regulation
signal-table
abmo
ciar
growing-som
pt-br
KHTST v7 — RETREINO OBSERVADO: estados antigos apagados; treino do zero com monitor de RAM integral (Agente Engenheiro); métricas de tests/test_khtst_v6.py comparadas com o treino anterior; gráficos de desempenho publicados no card
073c9a9 verified Download src/khtst/dados/documentos.py from PowerMachine/khtst-multimodal-ptbr: direct link, hf CLI and curl.
- Browser
- Download file 2.46 kB
-
https://huggingface.co/PowerMachine/khtst-multimodal-ptbr/resolve/main/src/khtst/dados/documentos.py
- Command line
-
hf download hf://PowerMachine/khtst-multimodal-ptbr/src/khtst/dados/documentos.py
-
curl -L -o documentos.py https://huggingface.co/PowerMachine/khtst-multimodal-ptbr/resolve/main/src/khtst/dados/documentos.py
2.46 kB
| # -*- coding: utf-8 -*- | |
| """Parsers de documentos (item 1: planilha, documentos, PDF) com degradação | |
| graciosa: dependências opcionais (pypdf, openpyxl) e saída de texto limpa. | |
| Todas as funções retornam str (vazio quando não suportado) e nunca lançam | |
| exceção para entrada malformada — violações de contrato são reportadas pelo | |
| chamador quando o texto vazio viola expectativa. | |
| """ | |
| from __future__ import annotations | |
| import csv | |
| import io | |
| import os | |
| def texto_de_pdf(caminho: str) -> str: | |
| try: | |
| from pypdf import PdfReader | |
| except ImportError: | |
| return "" | |
| try: | |
| leitor = PdfReader(caminho) | |
| return "\n".join((p.extract_text() or "") for p in leitor.pages).strip() | |
| except Exception: | |
| return "" | |
| def texto_de_planilha(caminho: str) -> str: | |
| """CSV/XLSX → texto linear por linhas (células separadas por ' | ').""" | |
| ext = os.path.splitext(caminho)[1].lower() | |
| try: | |
| if ext == ".csv": | |
| with open(caminho, "r", encoding="utf-8", errors="replace", newline="") as f: | |
| return "\n".join(" | ".join(linha) for linha in csv.reader(f)).strip() | |
| if ext == ".xlsx": | |
| try: | |
| from openpyxl import load_workbook | |
| except ImportError: | |
| return "" | |
| wb = load_workbook(caminho, read_only=True, data_only=True) | |
| linhas = [] | |
| for ws in wb.worksheets: | |
| for row in ws.iter_rows(values_only=True): | |
| if row: | |
| linhas.append(" | ".join("" if c is None else str(c) for c in row)) | |
| return "\n".join(linhas).strip() | |
| except Exception: | |
| return "" | |
| return "" | |
| def texto_de_docx(caminho: str) -> str: | |
| try: | |
| from docx import Document # python-docx | |
| doc = Document(caminho) | |
| return "\n".join(p.text for p in doc.paragraphs if p.text.strip()).strip() | |
| except ImportError: | |
| return "" | |
| except Exception: | |
| return "" | |
| def texto_de_arquivo(caminho: str) -> str: | |
| ext = os.path.splitext(caminho)[1].lower() | |
| if ext == ".pdf": | |
| return texto_de_pdf(caminho) | |
| if ext in (".csv", ".xlsx", ".xls", ".tsv"): | |
| return texto_de_planilha(caminho) | |
| if ext == ".docx": | |
| return texto_de_docx(caminho) | |
| try: | |
| with open(caminho, "r", encoding="utf-8", errors="replace") as f: | |
| return f.read().strip() | |
| except Exception: | |
| return "" | |