Spaces:
Runtime error
Runtime error
LevGervich
commited on
Commit
•
ed8275d
1
Parent(s):
0811afa
Add timer
Browse files- backend/semantic_search.py +3 -0
- utils/time_decorator.py +14 -0
backend/semantic_search.py
CHANGED
@@ -6,6 +6,8 @@ import gradio as gr
|
|
6 |
from sentence_transformers import SentenceTransformer
|
7 |
from FlagEmbedding import FlagReranker
|
8 |
|
|
|
|
|
9 |
db = lancedb.connect(".lancedb")
|
10 |
|
11 |
TABLE = db.open_table(os.getenv("TABLE_NAME"))
|
@@ -30,6 +32,7 @@ def rerank(query: str, documents: typing.List[str], k: int):
|
|
30 |
return [documents[i] for i in best_indices]
|
31 |
|
32 |
|
|
|
33 |
def retrieve(query, k):
|
34 |
query_vec = retriever.encode(query)
|
35 |
try:
|
|
|
6 |
from sentence_transformers import SentenceTransformer
|
7 |
from FlagEmbedding import FlagReranker
|
8 |
|
9 |
+
from gradio_app.utils.time_decorator import timeit
|
10 |
+
|
11 |
db = lancedb.connect(".lancedb")
|
12 |
|
13 |
TABLE = db.open_table(os.getenv("TABLE_NAME"))
|
|
|
32 |
return [documents[i] for i in best_indices]
|
33 |
|
34 |
|
35 |
+
@timeit
|
36 |
def retrieve(query, k):
|
37 |
query_vec = retriever.encode(query)
|
38 |
try:
|
utils/time_decorator.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from functools import wraps
|
2 |
+
import time
|
3 |
+
|
4 |
+
|
5 |
+
def timeit(func):
|
6 |
+
@wraps(func)
|
7 |
+
def timeit_wrapper(*args, **kwargs):
|
8 |
+
start_time = time.perf_counter()
|
9 |
+
result = func(*args, **kwargs)
|
10 |
+
end_time = time.perf_counter()
|
11 |
+
total_time = end_time - start_time
|
12 |
+
print(f'Function {func.__name__}{args} {kwargs} Took {total_time:.4f} seconds')
|
13 |
+
return result
|
14 |
+
return timeit_wrapper
|