Ridealist commited on
Commit
ed11763
1 Parent(s): 7d0d001

bugfix: fix validating double check error at user id input

Browse files
Files changed (1) hide show
  1. app.py +45 -44
app.py CHANGED
@@ -92,6 +92,9 @@ if "debate_time" not in st.session_state:
92
  if "pre_audio" not in st.session_state:
93
  st.session_state.pre_audio = np.array([])
94
 
 
 
 
95
 
96
  # for db session number
97
  if "session_num" not in st.session_state:
@@ -100,46 +103,12 @@ if "session_num" not in st.session_state:
100
  if "judgement_result" not in st.session_state:
101
  st.session_state.judgement_result = ""
102
 
103
-
104
  #########################################################
105
- # Save function (placeholder)
106
  #########################################################
107
- def save_info(user_id):
108
- # You can add the code to save the submitted info (e.g., to a database)
109
- st.session_state.user_id = user_id
110
-
111
- print("User ID:", user_id)
112
-
113
- # Session state
114
- # session_state = SessionState.get(user_id="", openAI_token="", debate_theme="")
115
- def write_info():
116
- st.write('You choose', st.session_state.topic_list)
117
-
118
- # for callback when button is clicked
119
  def page_1_2_controller():
120
- if st.session_state.user_id.strip() == "":
121
- st.session_state.page = "Page 1"
122
- st.warning('Please fill in all the required fields.')
123
- else:
124
- st.session_state.page = "Page 2"
125
- save_info(st.session_state.user_id)
126
-
127
- #########################################################
128
- # Session Update
129
- #########################################################
130
- debate_setting = get_lastest_item(
131
- table=dynamodb.Table('DEBO_debate_setting'),
132
- name_of_partition_key="user_id",
133
- value_of_partition_key=st.session_state.user_id,
134
- limit_num=1
135
- )
136
- # Session이 없다면, 0으로 초기화
137
- if debate_setting == []:
138
- st.session_state.session_num = 0
139
- # User의 이전 기록에서 Session이 있다면, Session Number를 가져오고 갱신함
140
- else:
141
- st.session_state.session_num = debate_setting[0]['session_num']
142
-
143
  def page_2_3_controller():
144
  st.session_state.page = "Page 3"
145
 
@@ -167,27 +136,59 @@ def page_n_1_controller():
167
  #########################################################
168
  # Page 1
169
  #########################################################
170
- def page1():
 
 
 
 
171
 
172
- # 첫페이지는 home이 따로 필요없을 것 같아서 주석처리함
173
- #_, _, _, home = st.columns([5, 5, 1, 1])
174
- # with home:
175
- # st.button("🔝", on_click=page_n_1_controller, use_container_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
 
 
177
  st.header('User Info')
178
- st.session_state.user_id = st.text_input(
 
179
  label='User ID',
180
  # key='user_id',
181
  max_chars=100,
182
  placeholder="Enter user ID",
183
  )
 
184
 
 
 
 
 
 
 
 
 
 
 
185
  st.button(
186
  label='Next',
187
  type='primary',
 
188
  on_click=page_1_2_controller
189
  )
190
-
191
  #########################################################
192
  # Page 2
193
  #########################################################
 
92
  if "pre_audio" not in st.session_state:
93
  st.session_state.pre_audio = np.array([])
94
 
95
+ if "disabled" not in st.session_state:
96
+ st.session_state.disabled = True
97
+
98
 
99
  # for db session number
100
  if "session_num" not in st.session_state:
 
103
  if "judgement_result" not in st.session_state:
104
  st.session_state.judgement_result = ""
105
 
 
106
  #########################################################
107
+ # Page Controller
108
  #########################################################
 
 
 
 
 
 
 
 
 
 
 
 
109
  def page_1_2_controller():
110
+ st.session_state.page = "Page 2"
111
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  def page_2_3_controller():
113
  st.session_state.page = "Page 3"
114
 
 
136
  #########################################################
137
  # Page 1
138
  #########################################################
139
+ def validate_user_id(input):
140
+ if input.strip():
141
+ return True
142
+ else:
143
+ return False
144
 
145
+ def save_info(user_id):
146
+ # You can add the code to save the submitted info (e.g., to a database)
147
+ st.session_state.user_id = user_id
148
+
149
+ #########################################################
150
+ # Session Update
151
+ #########################################################
152
+ debate_setting = get_lastest_item(
153
+ table=dynamodb.Table('DEBO_debate_setting'),
154
+ name_of_partition_key="user_id",
155
+ value_of_partition_key=st.session_state.user_id,
156
+ limit_num=1
157
+ )
158
+ # Session이 없다면, 0으로 초기화
159
+ if not debate_setting:
160
+ st.session_state.session_num = 0
161
+ # User의 이전 기록에서 Session이 있다면, Session Number를 가져오고 갱신함
162
+ else:
163
+ st.session_state.session_num = debate_setting[0]['session_num']
164
 
165
+ def page1():
166
  st.header('User Info')
167
+
168
+ user_input = st.text_input(
169
  label='User ID',
170
  # key='user_id',
171
  max_chars=100,
172
  placeholder="Enter user ID",
173
  )
174
+ error_message = st.empty()
175
 
176
+ if user_input:
177
+ if validate_user_id(user_input):
178
+ save_info(user_input)
179
+ st.session_state.disabled = False
180
+ else:
181
+ error_message.error('Please fill in correct User ID')
182
+ st.session_state.disabled = True
183
+ else:
184
+ st.session_state.disabled = True
185
+
186
  st.button(
187
  label='Next',
188
  type='primary',
189
+ disabled=st.session_state.disabled,
190
  on_click=page_1_2_controller
191
  )
 
192
  #########################################################
193
  # Page 2
194
  #########################################################