Spaces:
Sleeping
Sleeping
Fernando Cervan
commited on
Commit
·
6976a55
1
Parent(s):
fe14204
Salvando alterações
Browse files- Inferencia.py +31 -0
- LogCustomizado.py +13 -0
- app.py +16 -27
Inferencia.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import torch
|
3 |
+
class Inferencia:
|
4 |
+
|
5 |
+
def __init__(self):
|
6 |
+
...
|
7 |
+
|
8 |
+
def extrair_dados_imagem(self, prompt, imagem):
|
9 |
+
pipe = pipeline(
|
10 |
+
"image-text-to-text",
|
11 |
+
model="google/gemma-3-4b-it",
|
12 |
+
torch_dtype=torch.bfloat16 # Otimiza para rodar na CPU
|
13 |
+
)
|
14 |
+
messages = [
|
15 |
+
{
|
16 |
+
"role": "system",
|
17 |
+
"content": [{"type": "text", "text": "You are a helpful assistant."}]
|
18 |
+
},
|
19 |
+
{
|
20 |
+
"role": "user",
|
21 |
+
"content": [
|
22 |
+
{"type": "image", "url": imagem},
|
23 |
+
{"type": "text",
|
24 |
+
"text": prompt}
|
25 |
+
]
|
26 |
+
}
|
27 |
+
]
|
28 |
+
|
29 |
+
output = pipe(text=messages, max_new_tokens=200)
|
30 |
+
|
31 |
+
return output[0]["generated_text"][-1]["content"]
|
LogCustomizado.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from datetime import datetime
|
2 |
+
|
3 |
+
class LogCustomizado:
|
4 |
+
|
5 |
+
@staticmethod
|
6 |
+
def gerar_log(mensagem_log, status='INFO', retornarMensagem=False):
|
7 |
+
data_hora = datetime.now().strftime('%d/%m/%Y %H:%M:%S')
|
8 |
+
mensagem_log_completa = f"[{data_hora}] - [{status}] - {mensagem_log}"
|
9 |
+
|
10 |
+
if (retornarMensagem):
|
11 |
+
return mensagem_log_completa
|
12 |
+
|
13 |
+
print(mensagem_log_completa)
|
app.py
CHANGED
@@ -1,30 +1,19 @@
|
|
1 |
-
|
2 |
-
import
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
)
|
9 |
-
messages = [
|
10 |
-
{
|
11 |
-
"role": "system",
|
12 |
-
"content": [{"type": "text", "text": "You are a helpful assistant."}]
|
13 |
-
},
|
14 |
-
{
|
15 |
-
"role": "user",
|
16 |
-
"content": [
|
17 |
-
{"type": "image", "url": "cnh-michele-digital.jpeg"},
|
18 |
-
{"type": "text", "text": "Extraia o nome, cpf, data de nascimento e número de registro. Retorne apenas um JSON com esses dados."}
|
19 |
-
]
|
20 |
-
}
|
21 |
-
]
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
print("=" * 20)
|
27 |
-
print("FIM PROCESSO")
|
28 |
-
# Okay, let's take a look!
|
29 |
-
# Based on the image, the animal on the candy is a **turtle**.
|
30 |
-
# You can see the shell shape and the head and legs.
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from LogCustomizado import LogCustomizado as logc
|
3 |
|
4 |
+
logc.gerar_log(mensagem_log="INICIANDO PROCESSO")
|
5 |
+
|
6 |
+
st.set_page_config(page_title="CADIN - Cadastro Inteligente")
|
7 |
+
|
8 |
+
st.title("CADIN - Cadastro Inteligente")
|
9 |
+
|
10 |
+
arquivos_upload = st.file_uploader(
|
11 |
+
label="Adicione todos os documentos que estão em formato de imagens.",
|
12 |
+
type=["jpg", "jpeg", "png", "pdf"],
|
13 |
+
accept_multiple_files=True,
|
14 |
+
help="O arquitvo PDF precisa ser uma imagem"
|
15 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
if arquivos_upload is not None:
|
18 |
+
for item in arquivos_upload:
|
19 |
+
st.write(item)
|
|
|
|
|
|
|
|
|
|