model-metadata/code_python_files
014k
1# /// script2# requires-python = ">=3.12"3# dependencies = [4# "torch",5# "torchvision",6# "transformers",7# "accelerate",8# "peft",9# "slack-sdk",10# ]11# ///12 13try:14 import os15 from huggingface_hub import InferenceClient16 17 client = InferenceClient(18 provider="auto",19 api_key=os.environ["HF_TOKEN"],20 )21 22 result = client.sentence_similarity(23 {24 "source_sentence": "That is a happy person",25 "sentences": [26 "That is a happy dog",27 "That is a very happy person",28 "Today is a sunny day"29 ]30 },31 model="BAAI/bge-m3",32 )33 with open('BAAI_bge-m3_2.txt', 'w', encoding='utf-8') as f:34 f.write('Everything was good in BAAI_bge-m3_2.txt')35except Exception as e:36 import os37 from slack_sdk import WebClient38 client = WebClient(token=os.environ['SLACK_TOKEN'])39 client.chat_postMessage(40 channel='#exp-slack-alerts',41 text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/BAAI_bge-m3_2.txt|BAAI_bge-m3_2.txt>',42 )43 44 with open('BAAI_bge-m3_2.txt', 'a', encoding='utf-8') as f:45 import traceback46 f.write('''```CODE: 47import os48from huggingface_hub import InferenceClient49 50client = InferenceClient(51 provider="auto",52 api_key=os.environ["HF_TOKEN"],53)54 55result = client.sentence_similarity(56 {57 "source_sentence": "That is a happy person",58 "sentences": [59 "That is a happy dog",60 "That is a very happy person",61 "Today is a sunny day"62 ]63},64 model="BAAI/bge-m3",65)66```67 68ERROR: 69''')70 traceback.print_exc(file=f)71 72finally:73 from huggingface_hub import upload_file74 upload_file(75 path_or_fileobj='BAAI_bge-m3_2.txt',76 repo_id='model-metadata/code_execution_files',77 path_in_repo='BAAI_bge-m3_2.txt',78 repo_type='dataset',79 )80 