CoolFace
Datasetpublic

model-metadata/code_python_files

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes14kdownloads
HuggingFaceTB_SmolLM3-3B_5.py84 linesDownload Raw Back to root
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    prompt = "Give me a brief explanation of gravity in simple terms."17    messages = [18        {"role": "system", "content": "/no_think"},19        {"role": "user", "content": prompt}20    ]21    22    text = tokenizer.apply_chat_template(23        messages,24        tokenize=False,25        add_generation_prompt=True,26    )27    28    model_inputs = tokenizer([text], return_tensors="pt").to(model.device)29    30    # Generate the output31    generated_ids = model.generate(**model_inputs, max_new_tokens=32768)32    33    # Get and decode the output34    output_ids = generated_ids[0][len(model_inputs.input_ids[0]) :]35    print(tokenizer.decode(output_ids, skip_special_tokens=True))36    with open('HuggingFaceTB_SmolLM3-3B_5.txt', 'w', encoding='utf-8') as f:37        f.write('Everything was good in HuggingFaceTB_SmolLM3-3B_5.txt')38except Exception as e:39    import os40    from slack_sdk import WebClient41    client = WebClient(token=os.environ['SLACK_TOKEN'])42    client.chat_postMessage(43        channel='#hub-model-metadata-snippets-sprint',44        text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/HuggingFaceTB_SmolLM3-3B_5.txt|HuggingFaceTB_SmolLM3-3B_5.txt>',45    )46 47    with open('HuggingFaceTB_SmolLM3-3B_5.txt', 'a', encoding='utf-8') as f:48        import traceback49        f.write('''```CODE: 50prompt = "Give me a brief explanation of gravity in simple terms."51messages = [52    {"role": "system", "content": "/no_think"},53    {"role": "user", "content": prompt}54]55 56text = tokenizer.apply_chat_template(57    messages,58    tokenize=False,59    add_generation_prompt=True,60)61 62model_inputs = tokenizer([text], return_tensors="pt").to(model.device)63 64# Generate the output65generated_ids = model.generate(**model_inputs, max_new_tokens=32768)66 67# Get and decode the output68output_ids = generated_ids[0][len(model_inputs.input_ids[0]) :]69print(tokenizer.decode(output_ids, skip_special_tokens=True))70```71 72ERROR: 73''')74        traceback.print_exc(file=f)75    76finally:77    from huggingface_hub import upload_file78    upload_file(79        path_or_fileobj='HuggingFaceTB_SmolLM3-3B_5.txt',80        repo_id='model-metadata/code_execution_files',81        path_in_repo='HuggingFaceTB_SmolLM3-3B_5.txt',82        repo_type='dataset',83    )84