Views
No views yet
transformers library.1from transformers import AutoProcessor, AutoModelForCausalLM
2from PIL import Image
3import requests
4
5# Load the processor and model
6# Note: Replace "PAPOGalaxy/PAPO-Qwen2.5-7B" with the actual model ID if different
7processor = AutoProcessor.from_pretrained("PAPOGalaxy/PAPO-Qwen2.5-7B", trust_remote_code=True)
8model = AutoModelForCausalLM.from_pretrained("PAPOGalaxy/PAPO-Qwen2.5-7B", trust_remote_code=True)
9
10# Example image (replace with your image URL or local path)
11image_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/preprocessor_config_vln.png"
12image = Image.open(requests.get(image_url, stream=True).raw).convert("RGB")
13
14# Define your prompt
15prompt = "What are the main objects in this image?"
16
17# Format messages for the model
18messages = [
19 {"role": "user", "content": [{"type": "image", "content": image}, {"type": "text", "text": prompt}]}
20]
21
22# Apply chat template and tokenize
23text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
24input_ids = processor(text, return_tensors="pt").input_ids
25
26# Generate response
27output_ids = model.generate(
28 input_ids,
29 max_new_tokens=100,
30 do_sample=True,
31 temperature=0.7,
32 top_p=0.9,
33)
34
35# Decode and print the generated text
36generated_text = processor.decode(output_ids[0], skip_special_tokens=True)
37print(generated_text)