ariG23498 HF Staff commited on
Commit
e60768f
·
verified ·
1 Parent(s): 6d2f426

Upload sentence-transformers_all-MiniLM-L6-v2_2.py with huggingface_hub

Browse files
sentence-transformers_all-MiniLM-L6-v2_2.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "transformers",
5
+ # "torch",
6
+ # ]
7
+ # ///
8
+
9
+ try:
10
+ import os
11
+ from huggingface_hub import InferenceClient
12
+
13
+ client = InferenceClient(
14
+ provider="auto",
15
+ api_key=os.environ["HF_TOKEN"],
16
+ )
17
+
18
+ result = client.sentence_similarity(
19
+ {
20
+ "source_sentence": "That is a happy person",
21
+ "sentences": [
22
+ "That is a happy dog",
23
+ "That is a very happy person",
24
+ "Today is a sunny day"
25
+ ]
26
+ },
27
+ model="sentence-transformers/all-MiniLM-L6-v2",
28
+ )
29
+ with open('sentence-transformers_all-MiniLM-L6-v2_2.txt', 'w') as f:
30
+ f.write('Everything was good in sentence-transformers_all-MiniLM-L6-v2_2.txt')
31
+ except Exception as e:
32
+ with open('sentence-transformers_all-MiniLM-L6-v2_2.txt', 'w') as f:
33
+ import traceback
34
+ traceback.print_exc(file=f)
35
+ finally:
36
+ from huggingface_hub import upload_file
37
+ upload_file(
38
+ path_or_fileobj='sentence-transformers_all-MiniLM-L6-v2_2.txt',
39
+ repo_id='model-metadata/custom_code_execution_files',
40
+ path_in_repo='sentence-transformers_all-MiniLM-L6-v2_2.txt',
41
+ repo_type='dataset',
42
+ )