CoolFace
Datasetpublic

model-metadata/code_python_files

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes13kdownloads
google_embeddinggemma-300m_3.py60 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    words = ["apple", "banana", "car"]17    18    # Calculate embeddings by calling model.encode()19    embeddings = model.encode(words)20    21    print(embeddings)22    for idx, embedding in enumerate(embeddings):23        print(f"Embedding {idx+1} (shape): {embedding.shape}")24    with open('google_embeddinggemma-300m_3.txt', 'w', encoding='utf-8') as f:25        f.write('Everything was good in google_embeddinggemma-300m_3.txt')26except Exception as e:27    import os28    from slack_sdk import WebClient29    client = WebClient(token=os.environ['SLACK_TOKEN'])30    client.chat_postMessage(31        channel='#hub-model-metadata-snippets-sprint',32        text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/google_embeddinggemma-300m_3.txt|google_embeddinggemma-300m_3.txt>',33    )34 35    with open('google_embeddinggemma-300m_3.txt', 'a', encoding='utf-8') as f:36        import traceback37        f.write('''```CODE: 38words = ["apple", "banana", "car"]39 40# Calculate embeddings by calling model.encode()41embeddings = model.encode(words)42 43print(embeddings)44for idx, embedding in enumerate(embeddings):45    print(f"Embedding {idx+1} (shape): {embedding.shape}")46```47 48ERROR: 49''')50        traceback.print_exc(file=f)51    52finally:53    from huggingface_hub import upload_file54    upload_file(55        path_or_fileobj='google_embeddinggemma-300m_3.txt',56        repo_id='model-metadata/code_execution_files',57        path_in_repo='google_embeddinggemma-300m_3.txt',58        repo_type='dataset',59    )60