CoolFace
Datasetpublic

model-metadata/code_python_files

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes14kdownloads
google_gemma-3-27b-it_4.py102 linesDownload Raw Back to root
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 openai import OpenAI16    17    client = OpenAI(18        base_url="https://router.huggingface.co/v1",19        api_key=os.environ["HF_TOKEN"],20    )21    22    completion = client.chat.completions.create(23        model="google/gemma-3-27b-it",24        messages=[25            {26                "role": "user",27                "content": [28                    {29                        "type": "text",30                        "text": "Describe this image in one sentence."31                    },32                    {33                        "type": "image_url",34                        "image_url": {35                            "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"36                        }37                    }38                ]39            }40        ],41    )42    43    print(completion.choices[0].message)44    with open('google_gemma-3-27b-it_4.txt', 'w', encoding='utf-8') as f:45        f.write('Everything was good in google_gemma-3-27b-it_4.txt')46except Exception as e:47    import os48    from slack_sdk import WebClient49    client = WebClient(token=os.environ['SLACK_TOKEN'])50    client.chat_postMessage(51        channel='#exp-slack-alerts',52        text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/google_gemma-3-27b-it_4.txt|google_gemma-3-27b-it_4.txt>',53    )54 55    with open('google_gemma-3-27b-it_4.txt', 'a', encoding='utf-8') as f:56        import traceback57        f.write('''```CODE: 58import os59from openai import OpenAI60 61client = OpenAI(62    base_url="https://router.huggingface.co/v1",63    api_key=os.environ["HF_TOKEN"],64)65 66completion = client.chat.completions.create(67    model="google/gemma-3-27b-it",68    messages=[69        {70            "role": "user",71            "content": [72                {73                    "type": "text",74                    "text": "Describe this image in one sentence."75                },76                {77                    "type": "image_url",78                    "image_url": {79                        "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"80                    }81                }82            ]83        }84    ],85)86 87print(completion.choices[0].message)88```89 90ERROR: 91''')92        traceback.print_exc(file=f)93    94finally:95    from huggingface_hub import upload_file96    upload_file(97        path_or_fileobj='google_gemma-3-27b-it_4.txt',98        repo_id='model-metadata/code_execution_files',99        path_in_repo='google_gemma-3-27b-it_4.txt',100        repo_type='dataset',101    )102