fix gradio
Browse files
app.py
CHANGED
|
@@ -8,12 +8,15 @@ os.environ["GRADIO_ROOT_PATH"] = "/_app/immutable"
|
|
| 8 |
import gradio as gr
|
| 9 |
from fastapi import FastAPI, Request
|
| 10 |
import uvicorn
|
| 11 |
-
import spaces
|
| 12 |
from sentence_transformers import SentenceTransformer
|
| 13 |
from sentence_transformers.util import cos_sim
|
| 14 |
from sentence_transformers.quantization import quantize_embeddings
|
| 15 |
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
app = FastAPI()
|
| 18 |
|
| 19 |
|
|
@@ -24,27 +27,27 @@ def embed(text):
|
|
| 24 |
return query_embedding.tolist();
|
| 25 |
|
| 26 |
|
| 27 |
-
|
| 28 |
-
async def openai_embeddings(request: Request):
|
| 29 |
-
body = await request.json();
|
| 30 |
-
print(body);
|
| 31 |
-
|
| 32 |
-
model = body['model']
|
| 33 |
-
text = body['input'];
|
| 34 |
-
embeddings = embed(text)
|
| 35 |
-
return {
|
| 36 |
-
'object': "list"
|
| 37 |
-
,'data': [{
|
| 38 |
-
'object': "embeddings"
|
| 39 |
-
,'embedding': embeddings
|
| 40 |
-
,'index':0
|
| 41 |
-
}]
|
| 42 |
-
,'model':model
|
| 43 |
-
,'usage':{
|
| 44 |
-
'prompt_tokens': 0
|
| 45 |
-
,'total_tokens': 0
|
| 46 |
-
}
|
| 47 |
-
}
|
| 48 |
|
| 49 |
with gr.Blocks(fill_height=True) as demo:
|
| 50 |
text = gr.Textbox();
|
|
|
|
| 8 |
import gradio as gr
|
| 9 |
from fastapi import FastAPI, Request
|
| 10 |
import uvicorn
|
|
|
|
| 11 |
from sentence_transformers import SentenceTransformer
|
| 12 |
from sentence_transformers.util import cos_sim
|
| 13 |
from sentence_transformers.quantization import quantize_embeddings
|
| 14 |
|
| 15 |
|
| 16 |
+
import spaces
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
app = FastAPI()
|
| 21 |
|
| 22 |
|
|
|
|
| 27 |
return query_embedding.tolist();
|
| 28 |
|
| 29 |
|
| 30 |
+
#@app.post("/v1/embeddings")
|
| 31 |
+
#async def openai_embeddings(request: Request):
|
| 32 |
+
# body = await request.json();
|
| 33 |
+
# print(body);
|
| 34 |
+
#
|
| 35 |
+
# model = body['model']
|
| 36 |
+
# text = body['input'];
|
| 37 |
+
# embeddings = embed(text)
|
| 38 |
+
# return {
|
| 39 |
+
# 'object': "list"
|
| 40 |
+
# ,'data': [{
|
| 41 |
+
# 'object': "embeddings"
|
| 42 |
+
# ,'embedding': embeddings
|
| 43 |
+
# ,'index':0
|
| 44 |
+
# }]
|
| 45 |
+
# ,'model':model
|
| 46 |
+
# ,'usage':{
|
| 47 |
+
# 'prompt_tokens': 0
|
| 48 |
+
# ,'total_tokens': 0
|
| 49 |
+
# }
|
| 50 |
+
# }
|
| 51 |
|
| 52 |
with gr.Blocks(fill_height=True) as demo:
|
| 53 |
text = gr.Textbox();
|