Spaces:
Sleeping
Sleeping
from datetime import datetime | |
import streamlit as st | |
import random | |
import time | |
from streamlit_extras.switch_page_button import switch_page | |
def login(): | |
# skip customize user name for debug mode | |
with st.form("user_login"): | |
st.write('## Enter Your Name') | |
user_id = st.text_input( | |
"Enter your name for personalization ๐", | |
label_visibility='visible', | |
disabled=False, | |
placeholder='anonymous', | |
) | |
st.write('You can leave it blank to be anonymous.') | |
# Every form must have a submit button. | |
submitted = st.form_submit_button("Start") | |
if submitted: | |
save_user_id(user_id) | |
switch_page("gallery") | |
def save_user_id(user_id): | |
print(user_id) | |
if not user_id: | |
user_id = 'anonymous' + str(random.randint(0, 100000)) | |
st.session_state.user_id = [user_id, datetime.now().strftime("%Y-%m-%d %H:%M:%S")] | |
def logout(): | |
st.session_state.pop('user_id') | |
st.session_state.pop('selected_dict') | |
st.session_state.pop('score_weights') | |
if __name__ == '__main__': | |
# print(st.source_util.get_pages('Home.py')) | |
st.set_page_config(page_title="Login", page_icon="๐ ", layout="wide") | |
st.write('A Research by MAPS Lab, NYU Shanghai') | |
st.title("Welcome to GEMRec Gallery Webapp!") | |
st.write( | |
"This is an web application to collect personal preference to ai generated images. \ | |
You can know which model you like most after you finish the survey." | |
) | |
if 'user_id' not in st.session_state: | |
login() | |
else: | |
st.write('You have already logged in as ' + st.session_state.user_id[0]) | |
st.button('Log out', on_click=logout) | |