Spaces:
Sleeping
Sleeping
from transformers import pipeline | |
import torch | |
class Inferencia: | |
def __init__(self): | |
... | |
def extrair_dados_imagem(self, prompt, imagem): | |
pipe = pipeline( | |
"image-text-to-text", | |
model="google/gemma-3-4b-it", | |
torch_dtype=torch.bfloat16 # Otimiza para rodar na CPU | |
) | |
messages = [ | |
{ | |
"role": "system", | |
"content": [{"type": "text", "text": "You are a helpful assistant."}] | |
}, | |
{ | |
"role": "user", | |
"content": [ | |
{"type": "image", "url": imagem}, | |
{"type": "text", | |
"text": prompt} | |
] | |
} | |
] | |
output = pipe(text=messages, max_new_tokens=200) | |
return output[0]["generated_text"][-1]["content"] |