ariG23498 HF Staff commited on
Commit
005dc77
·
verified ·
1 Parent(s): 3aeeb51

Upload google_embeddinggemma-300m_3.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. google_embeddinggemma-300m_3.py +57 -0
google_embeddinggemma-300m_3.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "torch",
5
+ # "torchvision",
6
+ # "transformers",
7
+ # "accelerate",
8
+ # "peft",
9
+ # "slack-sdk",
10
+ # ]
11
+ # ///
12
+
13
+ try:
14
+ words = ["apple", "banana", "car"]
15
+
16
+ # Calculate embeddings by calling model.encode()
17
+ embeddings = model.encode(words)
18
+
19
+ print(embeddings)
20
+ for idx, embedding in enumerate(embeddings):
21
+ print(f"Embedding {idx+1} (shape): {embedding.shape}")
22
+ with open('google_embeddinggemma-300m_3.txt', 'w', encoding='utf-8') as f:
23
+ f.write('Everything was good in google_embeddinggemma-300m_3.txt')
24
+ except Exception as e:
25
+ import os
26
+ from slack_sdk import WebClient
27
+ client = WebClient(token=os.environ['SLACK_TOKEN'])
28
+ client.chat_postMessage(
29
+ channel='#exp-slack-alerts',
30
+ text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/google_embeddinggemma-300m_3.txt|google_embeddinggemma-300m_3.txt>',
31
+ )
32
+
33
+ with open('google_embeddinggemma-300m_3.txt', 'a', encoding='utf-8') as f:
34
+ import traceback
35
+ f.write('''```CODE:
36
+ words = ["apple", "banana", "car"]
37
+
38
+ # Calculate embeddings by calling model.encode()
39
+ embeddings = model.encode(words)
40
+
41
+ print(embeddings)
42
+ for idx, embedding in enumerate(embeddings):
43
+ print(f"Embedding {idx+1} (shape): {embedding.shape}")
44
+ ```
45
+
46
+ ERROR:
47
+ ''')
48
+ traceback.print_exc(file=f)
49
+
50
+ finally:
51
+ from huggingface_hub import upload_file
52
+ upload_file(
53
+ path_or_fileobj='google_embeddinggemma-300m_3.txt',
54
+ repo_id='model-metadata/code_execution_files',
55
+ path_in_repo='google_embeddinggemma-300m_3.txt',
56
+ repo_type='dataset',
57
+ )