ariG23498 HF Staff commited on
Commit
05cfd93
·
verified ·
1 Parent(s): 24594ba

Upload BAAI_bge-m3_2.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. BAAI_bge-m3_2.py +79 -0
BAAI_bge-m3_2.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import os
15
+ from huggingface_hub import InferenceClient
16
+
17
+ client = InferenceClient(
18
+ provider="auto",
19
+ api_key=os.environ["HF_TOKEN"],
20
+ )
21
+
22
+ result = client.sentence_similarity(
23
+ {
24
+ "source_sentence": "That is a happy person",
25
+ "sentences": [
26
+ "That is a happy dog",
27
+ "That is a very happy person",
28
+ "Today is a sunny day"
29
+ ]
30
+ },
31
+ model="BAAI/bge-m3",
32
+ )
33
+ with open('BAAI_bge-m3_2.txt', 'w', encoding='utf-8') as f:
34
+ f.write('Everything was good in BAAI_bge-m3_2.txt')
35
+ except Exception as e:
36
+ import os
37
+ from slack_sdk import WebClient
38
+ client = WebClient(token=os.environ['SLACK_TOKEN'])
39
+ client.chat_postMessage(
40
+ channel='#exp-slack-alerts',
41
+ text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/BAAI_bge-m3_2.txt|BAAI_bge-m3_2.txt>',
42
+ )
43
+
44
+ with open('BAAI_bge-m3_2.txt', 'a', encoding='utf-8') as f:
45
+ import traceback
46
+ f.write('''```CODE:
47
+ import os
48
+ from huggingface_hub import InferenceClient
49
+
50
+ client = InferenceClient(
51
+ provider="auto",
52
+ api_key=os.environ["HF_TOKEN"],
53
+ )
54
+
55
+ result = client.sentence_similarity(
56
+ {
57
+ "source_sentence": "That is a happy person",
58
+ "sentences": [
59
+ "That is a happy dog",
60
+ "That is a very happy person",
61
+ "Today is a sunny day"
62
+ ]
63
+ },
64
+ model="BAAI/bge-m3",
65
+ )
66
+ ```
67
+
68
+ ERROR:
69
+ ''')
70
+ traceback.print_exc(file=f)
71
+
72
+ finally:
73
+ from huggingface_hub import upload_file
74
+ upload_file(
75
+ path_or_fileobj='BAAI_bge-m3_2.txt',
76
+ repo_id='model-metadata/code_execution_files',
77
+ path_in_repo='BAAI_bge-m3_2.txt',
78
+ repo_type='dataset',
79
+ )