Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,34 +1,26 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
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 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
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 |
|