Views
No views yet
1from transformers import LlavaForConditionalGeneration, LlavaProcessor
2from PIL import Image
3import torch
4
5# Load model and processor
6model = LlavaForConditionalGeneration.from_pretrained("sameenarshad786/llava-1.5-health-safety-captioning")
7processor = LlavaProcessor.from_pretrained("sameenarshad786/llava-1.5-health-safety-captioning")
8
9# Load your workplace safety image
10image = Image.open("construction_site.jpg")
11
12# Prepare the safety analysis prompt
13prompt = """Analyze this workplace/construction image and provide a detailed caption describing:
14
151. Health and safety hazards or incidents present
162. Construction objects, equipment, and work activities visible
173. Scene description and work stage context
184. Weather and environmental conditions
195. Safety category and incident type if applicable
20
21Focus on safety-critical elements and provide a comprehensive caption for workplace safety training."""
22
23# Generate safety caption
24inputs = processor(text=prompt, images=image, return_tensors="pt")
25
26with torch.no_grad():
27 outputs = model.generate(**inputs, max_new_tokens=200, do_sample=False)
28
29caption = processor.batch_decode(outputs, skip_special_tokens=True)[0]
30print(caption)final_llava_health_safety_model/)results/)logs/)data/)notebooks/)1@misc{llava-health-safety-2025,
2 title={LLaVA-1.5 7B - Health & Safety Image Captioning},
3 author={Sameen Arshad},
4 year={2025},
5 publisher={Hugging Face},
6 url={https://huggingface.co/sameenarshad786/llava-1.5-health-safety-captioning},
7 note={Fine-tuned on 620 expert-annotated workplace safety images}
8}