grostaco commited on
Commit
9ebc77b
1 Parent(s): 7e39033

feat: add timer

Browse files
Files changed (2) hide show
  1. app.py +7 -1
  2. lib/utils/timer.py +7 -0
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  from st_pages import Page, show_pages, add_page_title, Section
3
  from lib.utils.model import get_model, get_similarities
 
4
 
5
  add_page_title()
6
 
@@ -39,8 +40,11 @@ if button:
39
 
40
  st.text(f'IRRA model loaded with {sum(p.numel() for p in model.parameters()) / 1e6:.0f}M parameters')
41
 
 
42
  with st.spinner('Computing and ranking similarities'):
43
- similarities = get_similarities(caption, images, model).squeeze(0)
 
 
44
 
45
  indices = similarities.argsort(descending=True).cpu().tolist()[:ranks]
46
 
@@ -61,6 +65,8 @@ if button:
61
  with c3:
62
  st.text(f'{similarities[idx].cpu():.2f}')
63
 
 
 
64
  with st.sidebar:
65
  st.title('IRRA Text-To-Image Retrival')
66
 
 
1
  import streamlit as st
2
  from st_pages import Page, show_pages, add_page_title, Section
3
  from lib.utils.model import get_model, get_similarities
4
+ from lib.utils.timer import timer
5
 
6
  add_page_title()
7
 
 
40
 
41
  st.text(f'IRRA model loaded with {sum(p.numel() for p in model.parameters()) / 1e6:.0f}M parameters')
42
 
43
+ time = timer()
44
  with st.spinner('Computing and ranking similarities'):
45
+ with timer() as t:
46
+ similarities = get_similarities(caption, images, model).squeeze(0)
47
+ elapsed = t()
48
 
49
  indices = similarities.argsort(descending=True).cpu().tolist()[:ranks]
50
 
 
65
  with c3:
66
  st.text(f'{similarities[idx].cpu():.2f}')
67
 
68
+ st.success(f'Done in {elapsed:.2f}s')
69
+
70
  with st.sidebar:
71
  st.title('IRRA Text-To-Image Retrival')
72
 
lib/utils/timer.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ from time import perf_counter
2
+ from contextlib import contextmanager
3
+
4
+ @contextmanager
5
+ def timer():
6
+ start = perf_counter()
7
+ yield lambda: perf_counter() - start