ariG23498 HF Staff commited on
Commit
32d5d03
·
verified ·
1 Parent(s): 6771dfd

Upload zai-org_GLM-4.1V-9B-Thinking_1.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. zai-org_GLM-4.1V-9B-Thinking_1.py +34 -0
zai-org_GLM-4.1V-9B-Thinking_1.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "transformers",
5
+ # "torch",
6
+ # ]
7
+ # ///
8
+
9
+ try:
10
+ def infer(messages, max_new_tokens=8192):
11
+ inputs = processor.apply_chat_template(
12
+ messages,
13
+ tokenize=True,
14
+ add_generation_prompt=True,
15
+ return_dict=True,
16
+ return_tensors="pt"
17
+ ).to(model.device)
18
+ generated_ids = model.generate(**inputs, max_new_tokens=max_new_tokens)
19
+ output_text = processor.decode(generated_ids[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
20
+ return output_text
21
+ with open('zai-org_GLM-4.1V-9B-Thinking_1.txt', 'w') as f:
22
+ f.write('Everything was good in zai-org_GLM-4.1V-9B-Thinking_1.txt')
23
+ except Exception as e:
24
+ with open('zai-org_GLM-4.1V-9B-Thinking_1.txt', 'w') as f:
25
+ import traceback
26
+ traceback.print_exc(file=f)
27
+ finally:
28
+ from huggingface_hub import upload_file
29
+ upload_file(
30
+ path_or_fileobj='zai-org_GLM-4.1V-9B-Thinking_1.txt',
31
+ repo_id='model-metadata/custom_code_execution_files',
32
+ path_in_repo='zai-org_GLM-4.1V-9B-Thinking_1.txt',
33
+ repo_type='dataset',
34
+ )