aibmedia commited on
Commit
84c3c63
·
verified ·
1 Parent(s): ecd8d62

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +18 -26
main.py CHANGED
@@ -1,34 +1,26 @@
1
- from sentence_transformers import SentenceTransformer
2
- from sklearn.metrics.pairwise import cosine_similarity
3
- import subprocess
 
4
 
5
  from flask import Flask
6
  app = Flask(__name__)
7
-
8
- def run_command():
9
- return subprocess.Popen("./mxbai-embed-large-v1-f16.llamafile --server --nobrowser", shell=False, stdout=subprocess.PIPE).stdout.read()
10
-
11
  @app.route('/app')
12
  def command_app():
13
- # List of sentences to be processed
14
- sentences = [
15
- "Poor beggar of the trans gender community begs for instant coffee",
16
- "The fish dreamed of escaping the fishbowl and into the toilet where he saw his friend go.",
17
- "The person box was packed with jelly many dozens of months later.",
18
- "Gay drinks both instant coffee and energy drink"
19
- ]
20
-
21
- # Initializing the Sentence Transformer model using BERT with mean-tokens pooling
22
- model = SentenceTransformer('bert-base-nli-mean-tokens')
23
-
24
- # Encoding the sentences to obtain their embeddings
25
- sentence_embeddings = model.encode(sentences)
26
-
27
- # Calculating the cosine similarity between the first sentence embedding and the rest of the embeddings
28
- # The result will be a list of similarity scores between the first sentence and each of the other sentences
29
- similarity_scores = cosine_similarity([sentence_embeddings[0]], sentence_embeddings[1:])
30
- return similarity_scores
31
-
32
  @app.route('/')
33
  def command_server():
34
 
 
1
+ import requests
2
+
3
+ API_URL = "https://api-inference.huggingface.co/models/sentence-transformers/all-MiniLM-L6-v2"
4
+ headers = {"Authorization": "Bearer "}
5
 
6
  from flask import Flask
7
  app = Flask(__name__)
8
+
 
 
 
9
  @app.route('/app')
10
  def command_app():
11
+ payload ={
12
+ "inputs": {
13
+ "source_sentence": "That is a happy person",
14
+ "sentences": [
15
+ "That is a happy dog",
16
+ "That is a very happy person",
17
+ "Today is a sunny day"
18
+ ]
19
+ },
20
+ }
21
+ response = requests.post(API_URL, headers=headers, json=payload)
22
+ return response.json()
23
+
 
 
 
 
 
 
24
  @app.route('/')
25
  def command_server():
26