CoolFace
Datasetpublic

model-metadata/code_python_files

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes13kdownloads
facebook_sam-3d-objects_1.py71 linesDownload Raw Back to root
1# /// script2# requires-python = ">=3.12"3# dependencies = [4#     "numpy",5#     "einops",6#     "pandas",7#     "matplotlib",8#     "protobuf",9#     "torch",10#     "sentencepiece",11#     "torchvision",12#     "transformers",13#     "timm",14#     "diffusers",15#     "sentence-transformers",16#     "accelerate",17#     "peft",18#     "slack-sdk",19# ]20# ///21 22try:23    from inference import Inference, load_image, load_single_mask24    from huggingface_hub import hf_hub_download25    26    path = hf_hub_download("facebook/sam-3d-objects", "pipeline.yaml")27    inference = Inference(path, compile=False)28    29    image = load_image("path_to_image.png")30    mask = load_single_mask("path_to_mask.png", index=14)31    32    output = inference(image, mask)33    with open('facebook_sam-3d-objects_1.txt', 'w', encoding='utf-8') as f:34        f.write('Everything was good in facebook_sam-3d-objects_1.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='#hub-model-metadata-snippets-sprint',41        text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/facebook_sam-3d-objects_1.txt|facebook_sam-3d-objects_1.txt>',42    )43 44    with open('facebook_sam-3d-objects_1.txt', 'a', encoding='utf-8') as f:45        import traceback46        f.write('''```CODE: 47from inference import Inference, load_image, load_single_mask48from huggingface_hub import hf_hub_download49 50path = hf_hub_download("facebook/sam-3d-objects", "pipeline.yaml")51inference = Inference(path, compile=False)52 53image = load_image("path_to_image.png")54mask = load_single_mask("path_to_mask.png", index=14)55 56output = inference(image, mask)57```58 59ERROR: 60''')61        traceback.print_exc(file=f)62    63finally:64    from huggingface_hub import upload_file65    upload_file(66        path_or_fileobj='facebook_sam-3d-objects_1.txt',67        repo_id='model-metadata/code_execution_files',68        path_in_repo='facebook_sam-3d-objects_1.txt',69        repo_type='dataset',70    )71