ariG23498 HF Staff commited on
Commit
cb34198
·
verified ·
1 Parent(s): 1f07678

Upload CohereLabs_command-a-vision-07-2025_0.py with huggingface_hub

Browse files
CohereLabs_command-a-vision-07-2025_0.py CHANGED
@@ -14,6 +14,46 @@
14
  try:
15
  from huggingface_hub import login
16
  login(new_session=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  with open('CohereLabs_command-a-vision-07-2025_0.txt', 'w') as f:
18
  f.write('Everything was good in CohereLabs_command-a-vision-07-2025_0.txt')
19
  except Exception as e:
 
14
  try:
15
  from huggingface_hub import login
16
  login(new_session=False)
17
+
18
+ # Use a pipeline as a high-level helper
19
+ from transformers import pipeline
20
+
21
+ pipe = pipeline("image-text-to-text", model="CohereLabs/command-a-vision-07-2025")
22
+ messages = [
23
+ {
24
+ "role": "user",
25
+ "content": [
26
+ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
27
+ {"type": "text", "text": "What animal is on the candy?"}
28
+ ]
29
+ },
30
+ ]
31
+ pipe(text=messages)
32
+
33
+ # Load model directly
34
+ from transformers import AutoProcessor, AutoModelForImageTextToText
35
+
36
+ processor = AutoProcessor.from_pretrained("CohereLabs/command-a-vision-07-2025")
37
+ model = AutoModelForImageTextToText.from_pretrained("CohereLabs/command-a-vision-07-2025")
38
+ messages = [
39
+ {
40
+ "role": "user",
41
+ "content": [
42
+ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
43
+ {"type": "text", "text": "What animal is on the candy?"}
44
+ ]
45
+ },
46
+ ]
47
+ inputs = processor.apply_chat_template(
48
+ messages,
49
+ add_generation_prompt=True,
50
+ tokenize=True,
51
+ return_dict=True,
52
+ return_tensors="pt",
53
+ ).to(model.device)
54
+
55
+ outputs = model.generate(**inputs, max_new_tokens=40)
56
+ print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
57
  with open('CohereLabs_command-a-vision-07-2025_0.txt', 'w') as f:
58
  f.write('Everything was good in CohereLabs_command-a-vision-07-2025_0.txt')
59
  except Exception as e: