fix
Browse files
app.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from fastapi import FastAPI, Request
|
| 3 |
import uvicorn
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
|
| 8 |
|
| 9 |
import spaces
|
|
@@ -21,27 +21,27 @@ def embed(text):
|
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
|
| 46 |
def fn(text):
|
| 47 |
embed(text);
|
|
@@ -54,7 +54,7 @@ with gr.Blocks(fill_height=True) as demo:
|
|
| 54 |
|
| 55 |
|
| 56 |
print("Loading embedding model");
|
| 57 |
-
Embedder =
|
| 58 |
|
| 59 |
# demo.run_startup_events()
|
| 60 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from fastapi import FastAPI, Request
|
| 3 |
import uvicorn
|
| 4 |
+
from sentence_transformers import SentenceTransformer
|
| 5 |
+
from sentence_transformers.util import cos_sim
|
| 6 |
+
from sentence_transformers.quantization import quantize_embeddings
|
| 7 |
|
| 8 |
|
| 9 |
import spaces
|
|
|
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
+
@app.post("/v1/embeddings")
|
| 25 |
+
async def openai_embeddings(request: Request):
|
| 26 |
+
body = await request.json();
|
| 27 |
+
print(body);
|
| 28 |
+
|
| 29 |
+
model = body['model']
|
| 30 |
+
text = body['input'];
|
| 31 |
+
embeddings = embed(text)
|
| 32 |
+
return {
|
| 33 |
+
'object': "list"
|
| 34 |
+
,'data': [{
|
| 35 |
+
'object': "embeddings"
|
| 36 |
+
,'embedding': embeddings
|
| 37 |
+
,'index':0
|
| 38 |
+
}]
|
| 39 |
+
,'model':model
|
| 40 |
+
,'usage':{
|
| 41 |
+
'prompt_tokens': 0
|
| 42 |
+
,'total_tokens': 0
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
|
| 46 |
def fn(text):
|
| 47 |
embed(text);
|
|
|
|
| 54 |
|
| 55 |
|
| 56 |
print("Loading embedding model");
|
| 57 |
+
Embedder = SentenceTransformer("mixedbread-ai/mxbai-embed-large-v1")
|
| 58 |
|
| 59 |
# demo.run_startup_events()
|
| 60 |
|