|
import streamlit as st |
|
import os |
|
from util.data import get_data |
|
|
|
|
|
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.") |
|
|
|
|
|
|
|
if not st.session_state.get('password_verified', False): |
|
verify_password() |
|
else: |
|
st.sidebar.success("Password Verified. Proceed with the demo.") |
|
|
|
|
|
num_samples = st.number_input( |
|
"Set number of samples:", |
|
min_value=1, |
|
max_value=100, |
|
value=5 |
|
) |
|
|
|
if st.button("Retrieve Data"): |
|
|
|
data = get_data(num_samples) |
|
st.dataframe(data['question']) |
|
|
|
|
|
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', |
|
) |
|
|