ariG23498 HF Staff commited on
Commit
d740892
·
verified ·
1 Parent(s): 039d78f

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

Browse files
CohereLabs_command-a-vision-07-2025_1.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "transformers",
5
+ # "torch",
6
+ # ]
7
+ # ///
8
+
9
+ try:
10
+ # Load model directly
11
+ from transformers import AutoProcessor, AutoModelForImageTextToText
12
+
13
+ processor = AutoProcessor.from_pretrained("CohereLabs/command-a-vision-07-2025")
14
+ model = AutoModelForImageTextToText.from_pretrained("CohereLabs/command-a-vision-07-2025")
15
+ messages = [
16
+ {
17
+ "role": "user",
18
+ "content": [
19
+ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
20
+ {"type": "text", "text": "What animal is on the candy?"}
21
+ ]
22
+ },
23
+ ]
24
+ inputs = processor.apply_chat_template(
25
+ messages,
26
+ add_generation_prompt=True,
27
+ tokenize=True,
28
+ return_dict=True,
29
+ return_tensors="pt",
30
+ ).to(model.device)
31
+
32
+ outputs = model.generate(**inputs, max_new_tokens=40)
33
+ print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
34
+ with open('CohereLabs_command-a-vision-07-2025_1.txt', 'w') as f:
35
+ f.write('Everything was good in CohereLabs_command-a-vision-07-2025_1.txt')
36
+ except Exception as e:
37
+ with open('CohereLabs_command-a-vision-07-2025_1.txt', 'w') as f:
38
+ import traceback
39
+ traceback.print_exc(file=f)
40
+ finally:
41
+ from huggingface_hub import upload_file
42
+ upload_file(
43
+ path_or_fileobj='CohereLabs_command-a-vision-07-2025_1.txt',
44
+ repo_id='model-metadata/custom_code_execution_files',
45
+ path_in_repo='CohereLabs_command-a-vision-07-2025_1.txt',
46
+ repo_type='dataset',
47
+ )