hanoch.rahimi@gmail commited on
Commit
cd6bb4b
·
1 Parent(s): d631df4

added simple authentication

Browse files
Files changed (1) hide show
  1. app.py +42 -13
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import pinecone
2
  import streamlit as st
3
  from transformers import pipeline, AutoTokenizer
4
  from sentence_transformers import SentenceTransformer
@@ -42,15 +42,6 @@ def card(name, description, score):
42
 
43
  st.title("")
44
 
45
- st.write("""
46
- # Extractive Question Answering
47
- Ask me a question!
48
- """)
49
-
50
- st.markdown("""
51
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
52
- """, unsafe_allow_html=True)
53
-
54
  def run_query(query):
55
  xq = retriever.encode([query]).tolist()
56
  try:
@@ -77,7 +68,45 @@ def run_query(query):
77
  score = round(r["score"], 4)
78
  card(company_name, description, score)
79
 
80
- query = st.text_input("Search!", "")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
- if query != "":
83
- run_query(query)
 
1
+ import pinecone
2
  import streamlit as st
3
  from transformers import pipeline, AutoTokenizer
4
  from sentence_transformers import SentenceTransformer
 
42
 
43
  st.title("")
44
 
 
 
 
 
 
 
 
 
 
45
  def run_query(query):
46
  xq = retriever.encode([query]).tolist()
47
  try:
 
68
  score = round(r["score"], 4)
69
  card(company_name, description, score)
70
 
71
+ def check_password():
72
+ """Returns `True` if the user had the correct password."""
73
+
74
+ def password_entered():
75
+ """Checks whether a password entered by the user is correct."""
76
+ if st.session_state["password"] == st.secrets["password"]:
77
+ st.session_state["password_correct"] = True
78
+ del st.session_state["password"] # don't store password
79
+ else:
80
+ st.session_state["password_correct"] = False
81
+
82
+ if "password_correct" not in st.session_state:
83
+ # First run, show input for password.
84
+ st.text_input(
85
+ "Password", type="password", on_change=password_entered, key="password"
86
+ )
87
+ return False
88
+ elif not st.session_state["password_correct"]:
89
+ # Password not correct, show input + error.
90
+ st.text_input(
91
+ "Password", type="password", on_change=password_entered, key="password"
92
+ )
93
+ st.error("😕 Password incorrect")
94
+ return False
95
+ else:
96
+ # Password correct.
97
+ return True
98
+
99
+ if check_password():
100
+ st.write("""
101
+ Search for a company in free text
102
+ """)
103
+
104
+ st.markdown("""
105
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
106
+ """, unsafe_allow_html=True)
107
+
108
+ query = st.text_input("Search!", "")
109
+
110
+ if query != "":
111
+ run_query(query)
112