File size: 1,885 Bytes
d315945
 
 
 
 
 
 
 
 
 
 
 
68b50ab
 
 
 
 
 
 
f60efdc
68b50ab
d315945
68b50ab
d315945
 
68b50ab
d315945
68b50ab
d315945
 
 
68b50ab
 
 
d315945
 
 
 
68b50ab
d315945
 
 
 
 
 
68b50ab
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import os
from util.data import get_data

# Page Description
st.title("Benchmark Data Download")
st.write("""
Welcome to the Online Data Sample Download page. Please enter the password to access and download data samples.
Once verified, you can specify the number of samples you wish to retrieve and download the data as a CSV file.
""")


def verify_password():
    """
    Prompts the user to enter a password and checks it against the environment variable.
    If the password is correct, sets the session state to indicate successful verification.
    """

    def on_password_entered():
        if password_input == os.getenv('PASSWORD'):
            st.session_state['password_verified'] = True
        else:
            st.error("Incorrect password, please try again.")

    password_input = st.text_input("Enter Password:", type="password")
    submit_button = st.button("Submit", on_click=on_password_entered)

    if submit_button and not st.session_state.get('password_verified', False):
        st.error("Please enter a valid password to access the demo.")


# Check if the password has been verified
if not st.session_state.get('password_verified', False):
    verify_password()
else:
    st.sidebar.success("Password Verified. Proceed with the demo.")

    # Allow user to set the number of samples
    num_samples = st.number_input(
        "Set number of samples:",
        min_value=1,
        max_value=100,
        value=5
    )

    if st.button("Retrieve Data"):
        # Load and display data
        data = get_data(num_samples)
        st.dataframe(data['question'])

        # Create a CSV download link
        csv = data['question'].to_csv(index=False)
        st.download_button(
            label="Download data samples as CSV",
            data=csv,
            file_name='data_samples.csv',
            mime='text/csv',
        )