Zekun Wu commited on
Commit
68b50ab
1 Parent(s): f60efdc
Files changed (1) hide show
  1. pages/2_Benchmark_Data.py +28 -22
pages/2_Benchmark_Data.py CHANGED
@@ -10,43 +10,49 @@ Once verified, you can specify the number of samples you wish to retrieve and do
10
  """)
11
 
12
 
13
- def check_password():
14
- def password_entered():
 
 
 
 
 
15
  if password_input == os.getenv('PASSWORD'):
16
- st.session_state['password_correct'] = True
17
  else:
18
- st.error("Incorrect Password, please try again.")
19
 
20
  password_input = st.text_input("Enter Password:", type="password")
21
- submit_button = st.button("Submit", on_click=password_entered)
22
 
23
- if submit_button and not st.session_state.get('password_correct', False):
24
  st.error("Please enter a valid password to access the demo.")
25
 
26
 
27
-
28
- if not st.session_state.get('password_correct', False):
29
- check_password()
30
  else:
31
  st.sidebar.success("Password Verified. Proceed with the demo.")
32
 
33
  # Allow user to set the number of samples
34
- num_samples = st.sidebar.number_input(
35
  "Set number of samples:",
36
  min_value=1,
37
  max_value=100,
38
  value=5
39
  )
40
 
41
- # Load and display data
42
- data = get_data(num_samples)
43
- st.dataframe(data['question'])
44
-
45
- # Create a CSV download link
46
- csv = data['question'].to_csv(index=False)
47
- st.download_button(
48
- label="Download data samples as CSV",
49
- data=csv,
50
- file_name='data_samples.csv',
51
- mime='text/csv',
52
- )
 
 
10
  """)
11
 
12
 
13
+ def verify_password():
14
+ """
15
+ Prompts the user to enter a password and checks it against the environment variable.
16
+ If the password is correct, sets the session state to indicate successful verification.
17
+ """
18
+
19
+ def on_password_entered():
20
  if password_input == os.getenv('PASSWORD'):
21
+ st.session_state['password_verified'] = True
22
  else:
23
+ st.error("Incorrect password, please try again.")
24
 
25
  password_input = st.text_input("Enter Password:", type="password")
26
+ submit_button = st.button("Submit", on_click=on_password_entered)
27
 
28
+ if submit_button and not st.session_state.get('password_verified', False):
29
  st.error("Please enter a valid password to access the demo.")
30
 
31
 
32
+ # Check if the password has been verified
33
+ if not st.session_state.get('password_verified', False):
34
+ verify_password()
35
  else:
36
  st.sidebar.success("Password Verified. Proceed with the demo.")
37
 
38
  # Allow user to set the number of samples
39
+ num_samples = st.number_input(
40
  "Set number of samples:",
41
  min_value=1,
42
  max_value=100,
43
  value=5
44
  )
45
 
46
+ if st.button("Retrieve Data"):
47
+ # Load and display data
48
+ data = get_data(num_samples)
49
+ st.dataframe(data['question'])
50
+
51
+ # Create a CSV download link
52
+ csv = data['question'].to_csv(index=False)
53
+ st.download_button(
54
+ label="Download data samples as CSV",
55
+ data=csv,
56
+ file_name='data_samples.csv',
57
+ mime='text/csv',
58
+ )