Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,23 +1,15 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
from fastapi.staticfiles import StaticFiles
|
| 3 |
-
from fastapi.responses import FileResponse
|
| 4 |
-
|
| 5 |
from sentence_transformers import SentenceTransformer
|
| 6 |
-
from sklearn.metrics.pairwise import cosine_similarity
|
| 7 |
-
|
| 8 |
|
| 9 |
-
import
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
@app.get("/infer_t5")
|
| 14 |
-
def t5(input):
|
| 15 |
-
return {"output": "-"}
|
| 16 |
-
|
| 17 |
|
| 18 |
-
@app.
|
| 19 |
-
def
|
| 20 |
-
|
| 21 |
# List of sentences to be processed
|
| 22 |
sentences = [
|
| 23 |
"Poor beggar of the trans gender community begs for instant coffee",
|
|
@@ -37,6 +29,48 @@ def index():
|
|
| 37 |
similarity_scores = cosine_similarity([sentence_embeddings[0]], sentence_embeddings[1:])
|
| 38 |
return similarity_scores
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
# import requests
|
| 41 |
|
| 42 |
# API_URL = "https://api-inference.huggingface.co/models/sentence-transformers/all-MiniLM-L6-v2"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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",
|
|
|
|
| 29 |
similarity_scores = cosine_similarity([sentence_embeddings[0]], sentence_embeddings[1:])
|
| 30 |
return similarity_scores
|
| 31 |
|
| 32 |
+
@app.route('/')
|
| 33 |
+
def command_server():
|
| 34 |
+
|
| 35 |
+
print("command run")
|
| 36 |
+
return "hi"
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
# import requests
|
| 44 |
+
|
| 45 |
+
# app = FastAPI()
|
| 46 |
+
|
| 47 |
+
# @app.get("/infer_t5")
|
| 48 |
+
# def t5(input):
|
| 49 |
+
# return {"output": "-"}
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
# @app.get("/")
|
| 53 |
+
# def index():
|
| 54 |
+
|
| 55 |
+
# # List of sentences to be processed
|
| 56 |
+
# sentences = [
|
| 57 |
+
# "Poor beggar of the trans gender community begs for instant coffee",
|
| 58 |
+
# "The fish dreamed of escaping the fishbowl and into the toilet where he saw his friend go.",
|
| 59 |
+
# "The person box was packed with jelly many dozens of months later.",
|
| 60 |
+
# "Gay drinks both instant coffee and energy drink"
|
| 61 |
+
# ]
|
| 62 |
+
|
| 63 |
+
# # Initializing the Sentence Transformer model using BERT with mean-tokens pooling
|
| 64 |
+
# model = SentenceTransformer('bert-base-nli-mean-tokens')
|
| 65 |
+
|
| 66 |
+
# # Encoding the sentences to obtain their embeddings
|
| 67 |
+
# sentence_embeddings = model.encode(sentences)
|
| 68 |
+
|
| 69 |
+
# # Calculating the cosine similarity between the first sentence embedding and the rest of the embeddings
|
| 70 |
+
# # The result will be a list of similarity scores between the first sentence and each of the other sentences
|
| 71 |
+
# similarity_scores = cosine_similarity([sentence_embeddings[0]], sentence_embeddings[1:])
|
| 72 |
+
# return similarity_scores
|
| 73 |
+
|
| 74 |
# import requests
|
| 75 |
|
| 76 |
# API_URL = "https://api-inference.huggingface.co/models/sentence-transformers/all-MiniLM-L6-v2"
|