chainyo commited on
Commit
43478d2
1 Parent(s): 70c28bf

add password for hf space

Browse files
Files changed (2) hide show
  1. config.py +3 -0
  2. main.py +22 -15
config.py CHANGED
@@ -15,6 +15,8 @@ class Config(BaseSettings):
15
  embedding_version: str
16
  embedding_dir: str
17
  model_name: str
 
 
18
 
19
 
20
  load_dotenv()
@@ -26,4 +28,5 @@ config = Config(
26
  embedding_version=getenv("EMBEDDING_VERSION"),
27
  embedding_dir=getenv("EMBEDDING_DIR"),
28
  model_name=getenv("MODEL_NAME"),
 
29
  )
 
15
  embedding_version: str
16
  embedding_dir: str
17
  model_name: str
18
+ # HF
19
+ password: str
20
 
21
 
22
  load_dotenv()
 
28
  embedding_version=getenv("EMBEDDING_VERSION"),
29
  embedding_dir=getenv("EMBEDDING_DIR"),
30
  model_name=getenv("MODEL_NAME"),
31
+ password=getenv("PASSWORD"),
32
  )
main.py CHANGED
@@ -44,21 +44,28 @@ def _get_embeddings(text: str):
44
 
45
  st.title("PubMed Embeddings")
46
  st.subheader("Search for a PubMed article and get its id.")
47
-
48
- text = st.text_input("Search for a PubMed article", "Epidemiology of COVID-19")
 
 
 
 
49
 
50
- with st.spinner("Loading Embedding Model..."):
51
- pinecone.init(api_key=config.pinecone_api_key, env=config.pinecone_env)
52
- if "index" not in st.session_state:
53
- st.session_state.index = pinecone.Index(config.pinecone_index)
54
- if "tokenizer" not in st.session_state:
55
- st.session_state.tokenizer = AutoTokenizer.from_pretrained(config.model_name)
56
- if "model" not in st.session_state:
57
- st.session_state.model = AutoModel.from_pretrained(config.model_name)
58
 
59
- if st.button("Search"):
60
- with st.spinner("Searching..."):
61
- results = search(text)
62
 
63
- for res in results["matches"]:
64
- st.write(f"{res['id']} - confidence: {res['score']:.2f}")
 
 
 
 
44
 
45
  st.title("PubMed Embeddings")
46
  st.subheader("Search for a PubMed article and get its id.")
47
+
48
+
49
+ with st.text_input("Password", type="password") as password:
50
+ if password == config.password:
51
+ st.write("Password correct!")
52
+ text = st.text_input("Search for a PubMed article", "Epidemiology of COVID-19")
53
 
54
+ with st.spinner("Loading Embedding Model..."):
55
+ pinecone.init(api_key=config.pinecone_api_key, env=config.pinecone_env)
56
+ if "index" not in st.session_state:
57
+ st.session_state.index = pinecone.Index(config.pinecone_index)
58
+ if "tokenizer" not in st.session_state:
59
+ st.session_state.tokenizer = AutoTokenizer.from_pretrained(config.model_name)
60
+ if "model" not in st.session_state:
61
+ st.session_state.model = AutoModel.from_pretrained(config.model_name)
62
 
63
+ if st.button("Search"):
64
+ with st.spinner("Searching..."):
65
+ results = search(text)
66
 
67
+ for res in results["matches"]:
68
+ st.write(f"{res['id']} - confidence: {res['score']:.2f}")
69
+ else:
70
+ st.write("Password incorrect!")
71
+