CoolFace
Datasetpublic

model-metadata/code_python_files

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes13kdownloads
internlm_JanusCoder-14B_0.py77 linesDownload Raw Back to root
1# /// script2# requires-python = ">=3.12"3# dependencies = [4#     "numpy",5#     "einops",6#     "pandas",7#     "protobuf",8#     "torch",9#     "torchvision",10#     "transformers",11#     "timm",12#     "diffusers",13#     "sentence-transformers",14#     "accelerate",15#     "peft",16#     "slack-sdk",17# ]18# ///19 20try:21    # Use a pipeline as a high-level helper22    from transformers import pipeline23    24    pipe = pipeline("image-text-to-text", model="internlm/JanusCoder-14B")25    messages = [26        {27            "role": "user",28            "content": [29                {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},30                {"type": "text", "text": "What animal is on the candy?"}31            ]32        },33    ]34    pipe(text=messages)35    with open('internlm_JanusCoder-14B_0.txt', 'w', encoding='utf-8') as f:36        f.write('Everything was good in internlm_JanusCoder-14B_0.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/internlm_JanusCoder-14B_0.txt|internlm_JanusCoder-14B_0.txt>',44    )45 46    with open('internlm_JanusCoder-14B_0.txt', 'a', encoding='utf-8') as f:47        import traceback48        f.write('''```CODE: 49# Use a pipeline as a high-level helper50from transformers import pipeline51 52pipe = pipeline("image-text-to-text", model="internlm/JanusCoder-14B")53messages = [54    {55        "role": "user",56        "content": [57            {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},58            {"type": "text", "text": "What animal is on the candy?"}59        ]60    },61]62pipe(text=messages)63```64 65ERROR: 66''')67        traceback.print_exc(file=f)68    69finally:70    from huggingface_hub import upload_file71    upload_file(72        path_or_fileobj='internlm_JanusCoder-14B_0.txt',73        repo_id='model-metadata/code_execution_files',74        path_in_repo='internlm_JanusCoder-14B_0.txt',75        repo_type='dataset',76    )77