Downloads · 30 days
20
20% of all-time downloads
prolapse/malensfw-paligemma-bf16
malensfw-paligemma-bf16 is a image-text-to-text model from prolapse. Use it for the image-text-to-text task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
Downloads · 30 days
20
20% of all-time downloads
All-time downloads
100
Public
Parameters
2.9B
5.9 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors5.8 GB · 100%
From the Hugging Face model README
import torch
from transformers import PaliGemmaForConditionalGeneration, PaliGemmaProcessor
from PIL import Image
def download_model(model_id):
model = PaliGemmaForConditionalGeneration.from_pretrained(model_id)
processor = PaliGemmaProcessor.from_pretrained(model_id)
return model, processor
def infer(model, processor, image_path, text, max_new_tokens=128):
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = model.to(device)
model.eval()
image = Image.open(image_path)
inputs = processor(text=text, images=image, return_tensors="pt").to(device)
with torch.inference_mode():
generated_ids = model.generate(
**inputs,
max_new_tokens=max_new_tokens,
do_sample=False
)
result = processor.batch_decode(generated_ids, skip_special_tokens=True)
return result[0][len(text):].lstrip("\n")
def main():
model_id = "prolapse/malensfw-paligemma-bf16"
model, processor = download_model(model_id)
image_path = "/path/to/image.png"
prompt = "describe this photo"
result = infer(model, processor, image_path, prompt)
print(result)
if __name__ == "__main__":
main()