ariG23498 HF Staff commited on
Commit
f3be4db
·
verified ·
1 Parent(s): a421cf5

Upload google_gemma-3-1b-it_1.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. google_gemma-3-1b-it_1.py +67 -0
google_gemma-3-1b-it_1.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "numpy",
5
+ # "einops",
6
+ # "pandas",
7
+ # "matplotlib",
8
+ # "paddleorc",
9
+ # "protobuf",
10
+ # "torch",
11
+ # "sentencepiece",
12
+ # "torchvision",
13
+ # "transformers",
14
+ # "timm",
15
+ # "diffusers",
16
+ # "sentence-transformers",
17
+ # "accelerate",
18
+ # "peft",
19
+ # "slack-sdk",
20
+ # ]
21
+ # ///
22
+
23
+ try:
24
+ # Use a pipeline as a high-level helper
25
+ from transformers import pipeline
26
+
27
+ pipe = pipeline("text-generation", model="google/gemma-3-1b-it")
28
+ messages = [
29
+ {"role": "user", "content": "Who are you?"},
30
+ ]
31
+ pipe(messages)
32
+ with open('google_gemma-3-1b-it_1.txt', 'w', encoding='utf-8') as f:
33
+ f.write('Everything was good in google_gemma-3-1b-it_1.txt')
34
+ except Exception as e:
35
+ import os
36
+ from slack_sdk import WebClient
37
+ client = WebClient(token=os.environ['SLACK_TOKEN'])
38
+ client.chat_postMessage(
39
+ channel='#hub-model-metadata-snippets-sprint',
40
+ text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/google_gemma-3-1b-it_1.txt|google_gemma-3-1b-it_1.txt>',
41
+ )
42
+
43
+ with open('google_gemma-3-1b-it_1.txt', 'a', encoding='utf-8') as f:
44
+ import traceback
45
+ f.write('''```CODE:
46
+ # Use a pipeline as a high-level helper
47
+ from transformers import pipeline
48
+
49
+ pipe = pipeline("text-generation", model="google/gemma-3-1b-it")
50
+ messages = [
51
+ {"role": "user", "content": "Who are you?"},
52
+ ]
53
+ pipe(messages)
54
+ ```
55
+
56
+ ERROR:
57
+ ''')
58
+ traceback.print_exc(file=f)
59
+
60
+ finally:
61
+ from huggingface_hub import upload_file
62
+ upload_file(
63
+ path_or_fileobj='google_gemma-3-1b-it_1.txt',
64
+ repo_id='model-metadata/code_execution_files',
65
+ path_in_repo='google_gemma-3-1b-it_1.txt',
66
+ repo_type='dataset',
67
+ )