Rathapoom commited on
Commit
8675789
·
verified ·
1 Parent(s): a8639e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -25
app.py CHANGED
@@ -216,20 +216,21 @@ Please format the output with:
216
  return None
217
  time.sleep(2)
218
 
219
- # ระบบ login
220
  # Main Streamlit interface
 
 
 
221
  if 'username' not in st.session_state:
 
 
 
 
222
  st.title("Login")
223
  username_input = st.text_input("Enter your username:")
224
-
225
- # Step 1: Initial login button
226
- if st.button("Login"):
227
  if username_input:
228
  if check_user_in_sheet(username_input):
229
- # Store username in session but don't redirect yet
230
- st.session_state['temp_username'] = username_input
231
-
232
- # Show welcome message and stats
233
  stats = get_user_stats(username_input)
234
  if stats:
235
  st.success(f"Welcome, {username_input}! 👋")
@@ -238,40 +239,37 @@ if 'username' not in st.session_state:
238
  - Today's Usage: {stats['daily_count']}/{DAILY_API_LIMIT} generations
239
  - Total All-Time Usage: {stats['total_count']} generations
240
  """)
241
-
242
- # Step 2: Enter application button
243
- if st.button("🎯 Enter GeneXam Application"):
244
- st.session_state['username'] = username_input
245
- del st.session_state['temp_username']
246
- st.rerun()
247
  else:
248
  st.warning("Username not found. Please try again.")
249
  else:
250
  st.warning("Please enter a valid username.")
251
-
252
- # Add some helpful information about the two-step process
253
- if 'temp_username' in st.session_state:
254
- st.info("👆 Click 'Enter GeneXam Application' to start generating questions!")
255
- else:
 
 
 
256
  st.markdown("""
257
  ### How to Login:
258
  1. Enter your username and click 'Login' to verify your account
259
- 2. Then click 'Enter GeneXam Application' to start using the system
260
  """)
261
-
262
  else:
263
- # Main application interface remains the same
264
- st.title(f"Welcome to GeneXam, {st.session_state['username']}! 🎓")
265
 
266
  # Show current usage stats
267
- stats = get_user_stats(st.session_state['username'])
268
  if stats:
269
  remaining = DAILY_API_LIMIT - stats['daily_count']
270
  st.info(f"""
271
  📊 Usage Statistics:
272
  - Daily Generations Remaining: {remaining}/{DAILY_API_LIMIT}
273
  - Total All-Time Generations: {stats['total_count']}
274
- """)
275
 
276
  # Create tabs for input methods
277
  tab1, tab2 = st.tabs(["Text Input", "PDF Upload"])
 
216
  return None
217
  time.sleep(2)
218
 
 
219
  # Main Streamlit interface
220
+ # Initialize session state variables
221
+ if 'login_step' not in st.session_state:
222
+ st.session_state.login_step = 'username'
223
  if 'username' not in st.session_state:
224
+ st.session_state.username = None
225
+
226
+ # Login system
227
+ if st.session_state.username is None:
228
  st.title("Login")
229
  username_input = st.text_input("Enter your username:")
230
+
231
+ if st.session_state.login_step == 'username' and st.button("Login"):
 
232
  if username_input:
233
  if check_user_in_sheet(username_input):
 
 
 
 
234
  stats = get_user_stats(username_input)
235
  if stats:
236
  st.success(f"Welcome, {username_input}! 👋")
 
239
  - Today's Usage: {stats['daily_count']}/{DAILY_API_LIMIT} generations
240
  - Total All-Time Usage: {stats['total_count']} generations
241
  """)
242
+ st.session_state.login_step = 'enter_app'
 
 
 
 
 
243
  else:
244
  st.warning("Username not found. Please try again.")
245
  else:
246
  st.warning("Please enter a valid username.")
247
+
248
+ if st.session_state.login_step == 'enter_app':
249
+ if st.button("🎯 Enter GeneXam Application"):
250
+ st.session_state.username = username_input
251
+ st.rerun()
252
+
253
+ # Show instructions
254
+ if st.session_state.login_step == 'username':
255
  st.markdown("""
256
  ### How to Login:
257
  1. Enter your username and click 'Login' to verify your account
258
+ 2. After verification, click 'Enter GeneXam Application' to start using the system
259
  """)
 
260
  else:
261
+ # Main application code (ส่วนที่เหลือเหมือนเดิม)
262
+ st.title(f"Welcome to GeneXam, {st.session_state.username}! 🎓")
263
 
264
  # Show current usage stats
265
+ stats = get_user_stats(st.session_state.username)
266
  if stats:
267
  remaining = DAILY_API_LIMIT - stats['daily_count']
268
  st.info(f"""
269
  📊 Usage Statistics:
270
  - Daily Generations Remaining: {remaining}/{DAILY_API_LIMIT}
271
  - Total All-Time Generations: {stats['total_count']}
272
+ """)
273
 
274
  # Create tabs for input methods
275
  tab1, tab2 = st.tabs(["Text Input", "PDF Upload"])