Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -28,7 +28,6 @@ faixas = {
|
|
28 |
"TROPONINA": (0, 0.5)
|
29 |
}
|
30 |
|
31 |
-
|
32 |
def classificar(nome, valor):
|
33 |
try:
|
34 |
v = float(valor.replace(">", "").replace("<", "").strip())
|
@@ -63,7 +62,7 @@ def extrair_texto_pdf(pdf_input):
|
|
63 |
texto_nativo.append(page.get_text())
|
64 |
pix = page.get_pixmap(dpi=300)
|
65 |
img = Image.open(io.BytesIO(pix.tobytes("png")))
|
66 |
-
ocr_imgs.append(
|
67 |
tn = re.sub(r"\s+", " ", "".join(texto_nativo))
|
68 |
tocr = re.sub(r"\s+", " ", " ".join(pytesseract.image_to_string(im) for im in ocr_imgs))
|
69 |
return tn, tocr
|
@@ -127,7 +126,6 @@ ordem = [
|
|
127 |
"PROTEINA UR","GLI UR","CETONAS UR","SANGUE UR","LEUC ESTERASE","NITRITO UR","LEUCO EAS","HEMA EAS","BACTERIAS UR"
|
128 |
]
|
129 |
|
130 |
-
|
131 |
def extrair_exames_formatado(pdf_file):
|
132 |
if not pdf_file:
|
133 |
return "Nenhum arquivo enviado.", None
|
@@ -150,7 +148,7 @@ def extrair_exames_formatado(pdf_file):
|
|
150 |
line_main = ' / '.join(main_fields)
|
151 |
final = '\n'.join([l for l in (line_eas, line_main) if l])
|
152 |
|
153 |
-
|
154 |
df = pd.DataFrame([[k, resultados[k]] for k in resultados], columns=["Exame", "Valor"])
|
155 |
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".csv")
|
156 |
df.to_csv(tmp.name, index=False)
|
@@ -166,4 +164,4 @@ with gr.Blocks() as demo:
|
|
166 |
btn.click(extrair_exames_formatado, inputs=pdf_input, outputs=[out_txt, dl])
|
167 |
|
168 |
if __name__ == "__main__":
|
169 |
-
demo.launch()
|
|
|
28 |
"TROPONINA": (0, 0.5)
|
29 |
}
|
30 |
|
|
|
31 |
def classificar(nome, valor):
|
32 |
try:
|
33 |
v = float(valor.replace(">", "").replace("<", "").strip())
|
|
|
62 |
texto_nativo.append(page.get_text())
|
63 |
pix = page.get_pixmap(dpi=300)
|
64 |
img = Image.open(io.BytesIO(pix.tobytes("png")))
|
65 |
+
ocr_imgs.append(melhorar_imagem(img))
|
66 |
tn = re.sub(r"\s+", " ", "".join(texto_nativo))
|
67 |
tocr = re.sub(r"\s+", " ", " ".join(pytesseract.image_to_string(im) for im in ocr_imgs))
|
68 |
return tn, tocr
|
|
|
126 |
"PROTEINA UR","GLI UR","CETONAS UR","SANGUE UR","LEUC ESTERASE","NITRITO UR","LEUCO EAS","HEMA EAS","BACTERIAS UR"
|
127 |
]
|
128 |
|
|
|
129 |
def extrair_exames_formatado(pdf_file):
|
130 |
if not pdf_file:
|
131 |
return "Nenhum arquivo enviado.", None
|
|
|
148 |
line_main = ' / '.join(main_fields)
|
149 |
final = '\n'.join([l for l in (line_eas, line_main) if l])
|
150 |
|
151 |
+
# Gera CSV
|
152 |
df = pd.DataFrame([[k, resultados[k]] for k in resultados], columns=["Exame", "Valor"])
|
153 |
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".csv")
|
154 |
df.to_csv(tmp.name, index=False)
|
|
|
164 |
btn.click(extrair_exames_formatado, inputs=pdf_input, outputs=[out_txt, dl])
|
165 |
|
166 |
if __name__ == "__main__":
|
167 |
+
demo.launch(share=False)
|