model-metadata/code_python_files
014k
1# /// script2# requires-python = ">=3.12"3# dependencies = [4# "torch",5# "torchvision",6# "transformers",7# "diffusers",8# "sentence-transformers",9# "accelerate",10# "peft",11# "slack-sdk",12# ]13# ///14 15try:16 # prepare the model input17 prompt = "Give me a brief explanation of gravity in simple terms."18 messages_think = [19 {"role": "user", "content": prompt}20 ]21 22 text = tokenizer.apply_chat_template(23 messages_think,24 tokenize=False,25 add_generation_prompt=True,26 )27 model_inputs = tokenizer([text], return_tensors="pt").to(model.device)28 29 # Generate the output30 generated_ids = model.generate(**model_inputs, max_new_tokens=32768)31 32 # Get and decode the output33 output_ids = generated_ids[0][len(model_inputs.input_ids[0]) :]34 print(tokenizer.decode(output_ids, skip_special_tokens=True))35 with open('HuggingFaceTB_SmolLM3-3B_4.txt', 'w', encoding='utf-8') as f:36 f.write('Everything was good in HuggingFaceTB_SmolLM3-3B_4.txt')37except Exception as e:38 import os39 from slack_sdk import WebClient40 client = WebClient(token=os.environ['SLACK_TOKEN'])41 client.chat_postMessage(42 channel='#hub-model-metadata-snippets-sprint',43 text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/HuggingFaceTB_SmolLM3-3B_4.txt|HuggingFaceTB_SmolLM3-3B_4.txt>',44 )45 46 with open('HuggingFaceTB_SmolLM3-3B_4.txt', 'a', encoding='utf-8') as f:47 import traceback48 f.write('''```CODE: 49# prepare the model input50prompt = "Give me a brief explanation of gravity in simple terms."51messages_think = [52 {"role": "user", "content": prompt}53]54 55text = tokenizer.apply_chat_template(56 messages_think,57 tokenize=False,58 add_generation_prompt=True,59)60model_inputs = tokenizer([text], return_tensors="pt").to(model.device)61 62# Generate the output63generated_ids = model.generate(**model_inputs, max_new_tokens=32768)64 65# Get and decode the output66output_ids = generated_ids[0][len(model_inputs.input_ids[0]) :]67print(tokenizer.decode(output_ids, skip_special_tokens=True))68```69 70ERROR: 71''')72 traceback.print_exc(file=f)73 74finally:75 from huggingface_hub import upload_file76 upload_file(77 path_or_fileobj='HuggingFaceTB_SmolLM3-3B_4.txt',78 repo_id='model-metadata/code_execution_files',79 path_in_repo='HuggingFaceTB_SmolLM3-3B_4.txt',80 repo_type='dataset',81 )82 