Spaces:
Sleeping
Sleeping
Fernando Cervan
commited on
Commit
·
747feeb
1
Parent(s):
00bbd10
Salvando alterações
Browse files- Inferencia.py +9 -8
Inferencia.py
CHANGED
|
@@ -6,15 +6,16 @@ from LogCustomizado import LogCustomizado as logc
|
|
| 6 |
class Inferencia:
|
| 7 |
|
| 8 |
def __init__(self):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
logc.gerar_log(mensagem_log="EXECUTANDO PIPELINE...")
|
| 13 |
-
pipe = pipeline(
|
| 14 |
"image-text-to-text",
|
| 15 |
-
model=
|
| 16 |
torch_dtype=torch.bfloat16 # Otimiza para rodar na CPU
|
| 17 |
)
|
|
|
|
|
|
|
|
|
|
| 18 |
messages = [
|
| 19 |
{
|
| 20 |
"role": "system",
|
|
@@ -30,8 +31,8 @@ class Inferencia:
|
|
| 30 |
}
|
| 31 |
]
|
| 32 |
|
| 33 |
-
logc.gerar_log(mensagem_log="OBTENDO RESPOSTA
|
| 34 |
-
output = pipe(text=messages, max_new_tokens=2000)
|
| 35 |
|
| 36 |
return output[0]["generated_text"][-1]["content"]
|
| 37 |
|
|
|
|
| 6 |
class Inferencia:
|
| 7 |
|
| 8 |
def __init__(self):
|
| 9 |
+
self.modelo = "google/gemma-3-4b-it"
|
| 10 |
+
logc.gerar_log(mensagem_log="CARREGANDO MODELO")
|
| 11 |
+
self.pipe = pipeline(
|
|
|
|
|
|
|
| 12 |
"image-text-to-text",
|
| 13 |
+
model=self.modelo,
|
| 14 |
torch_dtype=torch.bfloat16 # Otimiza para rodar na CPU
|
| 15 |
)
|
| 16 |
+
|
| 17 |
+
def extrair_dados_imagem(self, prompt, imagem):
|
| 18 |
+
|
| 19 |
messages = [
|
| 20 |
{
|
| 21 |
"role": "system",
|
|
|
|
| 31 |
}
|
| 32 |
]
|
| 33 |
|
| 34 |
+
logc.gerar_log(mensagem_log=f"OBTENDO RESPOSTA DO MODELO {self.modelo}")
|
| 35 |
+
output = self.pipe(text=messages, max_new_tokens=2000)
|
| 36 |
|
| 37 |
return output[0]["generated_text"][-1]["content"]
|
| 38 |
|