-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.py
61 lines (43 loc) · 1.29 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import collections
import os
from pathlib import Path
from typing import List
import streamlit as st
from sentence_transformers import SentenceTransformer
from search.engine import Engine, Result
from search.model import load_minilm_model
from search.utils import get_memory_usage
os.environ["TOKENIZERS_PARALLELISM"] = "false"
_DATA_DIR = os.environ.get("DATA_DIR", "data/people_pm_minilm")
st.set_page_config(page_title="Search Engine", layout="wide")
st.markdown(
"""
<style>
.big-font {
font-size:20px;
}
</style>
""",
unsafe_allow_html=True,
)
@st.cache(allow_output_mutation=True)
def load_engine() -> Engine:
engine = Engine(
data_dir=Path(_DATA_DIR),
)
return engine
@st.cache(allow_output_mutation=True)
def load_model() -> SentenceTransformer:
return load_minilm_model()
engine = load_engine()
model = load_model()
st.error("Create a text input for the query.")
st.error("Create a slider with the number of results to retrieve.")
with st.spinner("Querying index ..."):
st.error("Get query embedding.")
st.error("Search results (engine.search).")
# Show the results.
# You can use st.markdown to render markdown.
# e.g. st.markdown("**text**") will add text in bold font.
st.error("Render results")
st.markdown(f"**Mem Usage**: {get_memory_usage()}MB")