Upload Qwen_Qwen2.5-VL-7B-Instruct_0.py with huggingface_hub
Browse files
Qwen_Qwen2.5-VL-7B-Instruct_0.py
CHANGED
|
@@ -26,6 +26,31 @@ try:
|
|
| 26 |
},
|
| 27 |
]
|
| 28 |
pipe(text=messages)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
with open('Qwen_Qwen2.5-VL-7B-Instruct_0.txt', 'w') as f:
|
| 30 |
f.write('Everything was good in Qwen_Qwen2.5-VL-7B-Instruct_0.txt')
|
| 31 |
except Exception as e:
|
|
|
|
| 26 |
},
|
| 27 |
]
|
| 28 |
pipe(text=messages)
|
| 29 |
+
|
| 30 |
+
# Load model directly
|
| 31 |
+
from transformers import AutoProcessor, AutoModelForVision2Seq
|
| 32 |
+
|
| 33 |
+
processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct")
|
| 34 |
+
model = AutoModelForVision2Seq.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct")
|
| 35 |
+
messages = [
|
| 36 |
+
{
|
| 37 |
+
"role": "user",
|
| 38 |
+
"content": [
|
| 39 |
+
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
|
| 40 |
+
{"type": "text", "text": "What animal is on the candy?"}
|
| 41 |
+
]
|
| 42 |
+
},
|
| 43 |
+
]
|
| 44 |
+
inputs = processor.apply_chat_template(
|
| 45 |
+
messages,
|
| 46 |
+
add_generation_prompt=True,
|
| 47 |
+
tokenize=True,
|
| 48 |
+
return_dict=True,
|
| 49 |
+
return_tensors="pt",
|
| 50 |
+
).to(model.device)
|
| 51 |
+
|
| 52 |
+
outputs = model.generate(**inputs, max_new_tokens=40)
|
| 53 |
+
print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
|
| 54 |
with open('Qwen_Qwen2.5-VL-7B-Instruct_0.txt', 'w') as f:
|
| 55 |
f.write('Everything was good in Qwen_Qwen2.5-VL-7B-Instruct_0.txt')
|
| 56 |
except Exception as e:
|