Synced repo using 'sync_with_huggingface' Github Action
Browse files
app.py
CHANGED
|
@@ -10,42 +10,43 @@ from fastapi import FastAPI, Body, Request
|
|
| 10 |
# from fastapi.responses import StreamingResponse
|
| 11 |
# from starlette.staticfiles import StaticFiles
|
| 12 |
# from starlette.templating import Jinja2Templates
|
|
|
|
| 13 |
from sentence_transformers import SentenceTransformer, models
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
-
def print_arguments(args):
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
def strtobool(val):
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
def str_none(val):
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
def add_arguments(argname, type, default, help, argparser, **kwargs):
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
|
| 50 |
|
| 51 |
os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
|
|
@@ -110,6 +111,11 @@ def similarity_score(model, textA, textB):
|
|
| 110 |
return em_test[0] @ em_test[1].T
|
| 111 |
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
@app.post("/bge_embed")
|
| 114 |
async def api_bge_embed(
|
| 115 |
text1: str = Body("text1", description="", embed=True),
|
|
@@ -137,9 +143,6 @@ async def api_tsdae_embed(
|
|
| 137 |
return ret
|
| 138 |
|
| 139 |
|
| 140 |
-
@app.get("/")
|
| 141 |
-
async def index(request: Request):
|
| 142 |
-
return {"detail": "API is Active !!"}
|
| 143 |
|
| 144 |
|
| 145 |
if __name__ == '__main__':
|
|
|
|
| 10 |
# from fastapi.responses import StreamingResponse
|
| 11 |
# from starlette.staticfiles import StaticFiles
|
| 12 |
# from starlette.templating import Jinja2Templates
|
| 13 |
+
from utils.utils import add_arguments, print_arguments
|
| 14 |
from sentence_transformers import SentenceTransformer, models
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
+
# def print_arguments(args):
|
| 19 |
+
# print("----------- Configuration Arguments -----------")
|
| 20 |
+
# for arg, value in vars(args).items():
|
| 21 |
+
# print("%s: %s" % (arg, value))
|
| 22 |
+
# print("------------------------------------------------")
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
# def strtobool(val):
|
| 26 |
+
# val = val.lower()
|
| 27 |
+
# if val in ('y', 'yes', 't', 'true', 'on', '1'):
|
| 28 |
+
# return True
|
| 29 |
+
# elif val in ('n', 'no', 'f', 'false', 'off', '0'):
|
| 30 |
+
# return False
|
| 31 |
+
# else:
|
| 32 |
+
# raise ValueError("invalid truth value %r" % (val,))
|
| 33 |
+
|
| 34 |
+
# def str_none(val):
|
| 35 |
+
# if val == 'None':
|
| 36 |
+
# return None
|
| 37 |
+
# else:
|
| 38 |
+
# return val
|
| 39 |
+
|
| 40 |
+
# def add_arguments(argname, type, default, help, argparser, **kwargs):
|
| 41 |
+
# type = strtobool if type == bool else type
|
| 42 |
+
# type = str_none if type == str else type
|
| 43 |
+
# argparser.add_argument(
|
| 44 |
+
# "--" + argname,
|
| 45 |
+
# default=default,
|
| 46 |
+
# type=type,
|
| 47 |
+
# help=help + ' Default: %(default)s.',
|
| 48 |
+
# **kwargs
|
| 49 |
+
# )
|
| 50 |
|
| 51 |
|
| 52 |
os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
|
|
|
|
| 111 |
return em_test[0] @ em_test[1].T
|
| 112 |
|
| 113 |
|
| 114 |
+
@app.get("/")
|
| 115 |
+
async def index(request: Request):
|
| 116 |
+
return {"detail": "API is Active !!"}
|
| 117 |
+
|
| 118 |
+
|
| 119 |
@app.post("/bge_embed")
|
| 120 |
async def api_bge_embed(
|
| 121 |
text1: str = Body("text1", description="", embed=True),
|
|
|
|
| 143 |
return ret
|
| 144 |
|
| 145 |
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
|
| 148 |
if __name__ == '__main__':
|