sam2ai commited on
Commit
0b80183
·
1 Parent(s): c91441b

Synced repo using 'sync_with_huggingface' Github Action

Browse files
Files changed (1) hide show
  1. app.py +38 -35
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
- print("----------- Configuration Arguments -----------")
19
- for arg, value in vars(args).items():
20
- print("%s: %s" % (arg, value))
21
- print("------------------------------------------------")
22
-
23
-
24
- def strtobool(val):
25
- val = val.lower()
26
- if val in ('y', 'yes', 't', 'true', 'on', '1'):
27
- return True
28
- elif val in ('n', 'no', 'f', 'false', 'off', '0'):
29
- return False
30
- else:
31
- raise ValueError("invalid truth value %r" % (val,))
32
-
33
- def str_none(val):
34
- if val == 'None':
35
- return None
36
- else:
37
- return val
38
-
39
- def add_arguments(argname, type, default, help, argparser, **kwargs):
40
- type = strtobool if type == bool else type
41
- type = str_none if type == str else type
42
- argparser.add_argument(
43
- "--" + argname,
44
- default=default,
45
- type=type,
46
- help=help + ' Default: %(default)s.',
47
- **kwargs
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__':