Sa-m commited on
Commit
d2a98f2
·
verified ·
1 Parent(s): 8c84a75

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +129 -45
app.py CHANGED
@@ -711,98 +711,177 @@ def submit_interview(interview_state):
711
 
712
  # --- Login and Navigation Logic (Firebase Integrated) ---
713
 
714
- def login(email, password):
 
715
  if not FIREBASE_AVAILABLE:
 
716
  return (
717
  "Firebase not initialized. Login unavailable.",
718
- gr.update(visible=True), gr.update(visible=False), gr.update(visible=False),
719
- "", "", "", "")
720
- if not email or not password or not username:
721
- # Return exactly 9 values for this case too
 
 
 
 
 
 
 
 
 
722
  return (
723
- "Please fill all fields.", # Line 760
724
- gr.update(visible=False), # login_section (Line 761)
725
- gr.update(visible=True), # signup_section (Line 762)
726
- gr.update(visible=False), # main_app (Line 763)
727
- gr.update(visible=False), # Placeholder/adjust (Line 764)
728
- email, # signup_email_input (Line 765)
729
- password, # signup_password_input (Line 766)
730
- username, # signup_username_input (Line 767)
731
- "", # user_state (Line 768)
732
- "" # user_email_state (Line 769)
733
  )
 
734
  try:
735
  user = auth.get_user_by_email(email)
736
  welcome_msg = f"Welcome, {user.display_name or user.uid}!"
737
  return (
738
  welcome_msg,
739
- gr.update(visible=False), gr.update(visible=False), gr.update(visible=True),
740
- "", "", user.uid, user.email
 
 
 
 
 
741
  )
742
  except auth.UserNotFoundError:
743
  return (
744
  "User not found. Please check your email or sign up.",
745
- gr.update(visible=True), gr.update(visible=False), gr.update(visible=False),
746
- email, password, "", ""
 
 
 
 
 
747
  )
748
  except Exception as e:
749
  error_msg = f"Login failed: {str(e)}"
750
  print(error_msg)
751
  return (
752
  error_msg,
753
- gr.update(visible=True), gr.update(visible=False), gr.update(visible=False),
754
- email, password, "", ""
 
 
 
 
 
755
  )
756
 
757
- def signup(email, password, username):
 
 
758
  if not FIREBASE_AVAILABLE:
 
 
759
  return (
760
- "Firebase not initialized. Signup unavailable.",
761
- gr.update(visible=True), gr.update(visible=False), gr.update(visible=False),
762
- gr.update(visible=False), "", "", "", "", ""
 
 
 
 
 
 
 
 
 
763
  )
764
- if not email or not password or not username:
 
 
 
765
  return (
766
  "Please fill all fields.",
767
- gr.update(visible=False), gr.update(visible=True), gr.update(visible=False),
768
- gr.update(visible=False), email, password, username, "", ""
 
 
 
 
 
 
 
 
769
  )
 
770
  try:
771
  user = auth.create_user(email=email, password=password, uid=username, display_name=username)
772
  success_msg = f"Account created successfully for {username}!"
 
773
  return (
774
  success_msg,
775
- gr.update(visible=True), gr.update(visible=False), gr.update(visible=False),
776
- gr.update(visible=False), "", "", "", user.uid, user.email
 
 
 
 
 
777
  )
778
  except auth.UidAlreadyExistsError:
779
  return (
780
  "Username already exists. Please choose another.",
781
- gr.update(visible=False), gr.update(visible=True), gr.update(visible=False),
782
- gr.update(visible=False), email, password, username, "", ""
 
 
 
 
 
783
  )
784
  except auth.EmailAlreadyExistsError:
785
  return (
786
  "Email already exists. Please use another email.",
787
- gr.update(visible=False), gr.update(visible=True), gr.update(visible=False),
788
- gr.update(visible=False), email, password, username, "", ""
 
 
 
 
 
789
  )
790
  except Exception as e:
791
  error_msg = f"Signup failed: {str(e)}"
792
  print(error_msg)
793
  return (
794
  error_msg,
795
- gr.update(visible=False), gr.update(visible=True), gr.update(visible=False),
796
- gr.update(visible=False), email, password, username, "", ""
 
 
 
 
 
797
  )
798
 
 
799
  def logout():
 
800
  return (
801
- "",
802
- gr.update(visible=True), gr.update(visible=False), gr.update(visible=False),
803
- gr.update(visible=False), "", "", "", "", ""
 
 
 
 
 
804
  )
805
 
 
806
  def navigate_to_interview():
807
  return (gr.update(visible=True), gr.update(visible=False))
808
 
@@ -1000,29 +1079,34 @@ with gr.Blocks(title="PrepGenie - Mock Interview") as demo:
1000
  )
1001
 
1002
  # --- Login/Logout Event Listeners ---
 
1003
  login_btn.click(
1004
  fn=login,
1005
  inputs=[login_email_input, login_password_input],
1006
  outputs=[login_status, login_section, signup_section, main_app,
1007
- login_email_input, login_password_input, user_state, user_email_state]
1008
  )
1009
-
1010
  signup_btn.click(
1011
  fn=signup,
1012
  inputs=[signup_email_input, signup_password_input, signup_username_input],
1013
  outputs=[signup_status, login_section, signup_section, main_app,
 
1014
  signup_email_input, signup_password_input, signup_username_input,
1015
- user_state, user_email_state]
1016
  )
1017
-
1018
  logout_btn.click(
1019
  fn=logout,
1020
  inputs=None,
1021
  outputs=[login_status, login_section, signup_section, main_app,
1022
- login_email_input, login_password_input, signup_username_input,
1023
- user_state, user_email_state]
 
1024
  )
1025
 
 
 
1026
  switch_to_signup_btn.click(
1027
  fn=lambda: (gr.update(visible=False), gr.update(visible=True)),
1028
  inputs=None,
 
711
 
712
  # --- Login and Navigation Logic (Firebase Integrated) ---
713
 
714
+ def login(email, password): # Correct arguments: email, password
715
+ # Check if Firebase is available
716
  if not FIREBASE_AVAILABLE:
717
+ # Return exactly 8 values matching the outputs list for login_btn.click
718
  return (
719
  "Firebase not initialized. Login unavailable.",
720
+ gr.update(visible=True), # login_section
721
+ gr.update(visible=False), # signup_section
722
+ gr.update(visible=False), # main_app
723
+ "", # login_email_input (clear)
724
+ "", # login_password_input (clear)
725
+ "", # user_state
726
+ "" # user_email_state
727
+ )
728
+
729
+ # --- CORRECTION 1: Remove 'username' from the condition check ---
730
+ # The login function does not have a 'username' argument.
731
+ if not email or not password: # <-- Corrected line
732
+ # Return exactly 8 values for this case too
733
  return (
734
+ "Please enter email and password.",
735
+ gr.update(visible=True), # login_section
736
+ gr.update(visible=False), # signup_section
737
+ gr.update(visible=False), # main_app
738
+ email, # login_email_input (keep value)
739
+ password, # login_password_input (keep value)
740
+ "", # user_state
741
+ "" # user_email_state
 
 
742
  )
743
+
744
  try:
745
  user = auth.get_user_by_email(email)
746
  welcome_msg = f"Welcome, {user.display_name or user.uid}!"
747
  return (
748
  welcome_msg,
749
+ gr.update(visible=False), # login_section
750
+ gr.update(visible=False), # signup_section
751
+ gr.update(visible=True), # main_app
752
+ "", # login_email_input (clear on success)
753
+ "", # login_password_input (clear on success)
754
+ user.uid, # user_state
755
+ user.email # user_email_state
756
  )
757
  except auth.UserNotFoundError:
758
  return (
759
  "User not found. Please check your email or sign up.",
760
+ gr.update(visible=True), # login_section
761
+ gr.update(visible=False), # signup_section
762
+ gr.update(visible=False), # main_app
763
+ email, # login_email_input (keep value)
764
+ password, # login_password_input (keep value)
765
+ "", # user_state
766
+ "" # user_email_state
767
  )
768
  except Exception as e:
769
  error_msg = f"Login failed: {str(e)}"
770
  print(error_msg)
771
  return (
772
  error_msg,
773
+ gr.update(visible=True), # login_section
774
+ gr.update(visible=False), # signup_section
775
+ gr.update(visible=False), # main_app
776
+ email, # login_email_input (keep value)
777
+ password, # login_password_input (keep value)
778
+ "", # user_state
779
+ "" # user_email_state
780
  )
781
 
782
+
783
+ def signup(email, password, username): # Correct arguments: email, password, username
784
+ # Check if Firebase is available
785
  if not FIREBASE_AVAILABLE:
786
+ # Return exactly 9 values matching the outputs list for signup_btn.click
787
+ # --- CORRECTION 2a: Ensure the number of returned values matches the expected 9 ---
788
  return (
789
+ "Firebase not initialized. Signup unavailable.",
790
+ gr.update(visible=True), # login_section
791
+ gr.update(visible=False), # signup_section
792
+ gr.update(visible=False), # main_app
793
+ # --- CORRECTION 2b: Remove the extra placeholder gr.update() ---
794
+ # gr.update(visible=False), # Placeholder/adjust (This was the 5th item causing the mismatch)
795
+ "", # signup_email_input (5th)
796
+ "", # signup_password_input (6th)
797
+ "", # signup_username_input (7th)
798
+ "", # user_state (8th)
799
+ "" # user_email_state (9th)
800
+ # 9 values total
801
  )
802
+
803
+ # --- CORRECTION 3: The 'username' check is valid here ---
804
+ if not email or not password or not username: # <-- This line is correct for signup
805
+ # Return exactly 9 values for this case too
806
  return (
807
  "Please fill all fields.",
808
+ gr.update(visible=False), # login_section
809
+ gr.update(visible=True), # signup_section
810
+ gr.update(visible=False), # main_app
811
+ # gr.update(visible=False), # Placeholder/adjust (Remove this)
812
+ email, # signup_email_input (5th)
813
+ password, # signup_password_input (6th)
814
+ username, # signup_username_input (7th)
815
+ "", # user_state (8th)
816
+ "" # user_email_state (9th)
817
+ # 9 values total
818
  )
819
+
820
  try:
821
  user = auth.create_user(email=email, password=password, uid=username, display_name=username)
822
  success_msg = f"Account created successfully for {username}!"
823
+ # Switch to login view after successful signup
824
  return (
825
  success_msg,
826
+ gr.update(visible=True), # login_section (switch to login)
827
+ gr.update(visible=False), # signup_section
828
+ gr.update(visible=False), # main_app
829
+ # gr.update(visible=False), # Placeholder/adjust (Remove this)
830
+ "", "", "", # Clear email/password/username inputs (5th, 6th, 7th)
831
+ user.uid, user.email # Set user state (8th, 9th)
832
+ # 9 values total
833
  )
834
  except auth.UidAlreadyExistsError:
835
  return (
836
  "Username already exists. Please choose another.",
837
+ gr.update(visible=False), # login_section
838
+ gr.update(visible=True), # signup_section
839
+ gr.update(visible=False), # main_app
840
+ # gr.update(visible=False), # Placeholder/adjust (Remove this)
841
+ email, password, username, # Keep inputs (5th, 6th, 7th)
842
+ "", "" # Clear user state (8th, 9th)
843
+ # 9 values total
844
  )
845
  except auth.EmailAlreadyExistsError:
846
  return (
847
  "Email already exists. Please use another email.",
848
+ gr.update(visible=False), # login_section
849
+ gr.update(visible=True), # signup_section
850
+ gr.update(visible=False), # main_app
851
+ # gr.update(visible=False), # Placeholder/adjust (Remove this)
852
+ email, password, username, # Keep inputs (5th, 6th, 7th)
853
+ "", "" # Clear user state (8th, 9th)
854
+ # 9 values total
855
  )
856
  except Exception as e:
857
  error_msg = f"Signup failed: {str(e)}"
858
  print(error_msg)
859
  return (
860
  error_msg,
861
+ gr.update(visible=False), # login_section
862
+ gr.update(visible=True), # signup_section
863
+ gr.update(visible=False), # main_app
864
+ # gr.update(visible=False), # Placeholder/adjust (Remove this)
865
+ email, password, username, # Keep inputs (5th, 6th, 7th)
866
+ "", "" # Clear user state (8th, 9th)
867
+ # 9 values total
868
  )
869
 
870
+
871
  def logout():
872
+ # Return exactly 9 values matching the outputs list for logout_btn.click
873
  return (
874
+ "", # Clear login status
875
+ gr.update(visible=True), # Show login section
876
+ gr.update(visible=False), # Hide signup section
877
+ gr.update(visible=False), # Hide main app
878
+ # gr.update(visible=False), # Placeholder/adjust (Remove this if present in your listener)
879
+ "", "", "", # Clear email/password/username inputs
880
+ "", "" # Clear user_state and user_email_state
881
+ # 9 values total
882
  )
883
 
884
+
885
  def navigate_to_interview():
886
  return (gr.update(visible=True), gr.update(visible=False))
887
 
 
1079
  )
1080
 
1081
  # --- Login/Logout Event Listeners ---
1082
+
1083
  login_btn.click(
1084
  fn=login,
1085
  inputs=[login_email_input, login_password_input],
1086
  outputs=[login_status, login_section, signup_section, main_app,
1087
+ login_email_input, login_password_input, user_state, user_email_state] # 8 outputs
1088
  )
1089
+
1090
  signup_btn.click(
1091
  fn=signup,
1092
  inputs=[signup_email_input, signup_password_input, signup_username_input],
1093
  outputs=[signup_status, login_section, signup_section, main_app,
1094
+ # Remove any extra gr.update() from the outputs list if present
1095
  signup_email_input, signup_password_input, signup_username_input,
1096
+ user_state, user_email_state] # 9 outputs
1097
  )
1098
+
1099
  logout_btn.click(
1100
  fn=logout,
1101
  inputs=None,
1102
  outputs=[login_status, login_section, signup_section, main_app,
1103
+ # Remove any extra gr.update() from the outputs list if present
1104
+ login_email_input, login_password_input, signup_username_input, # Note: uses signup_username_input target
1105
+ user_state, user_email_state] # 9 outputs
1106
  )
1107
 
1108
+
1109
+
1110
  switch_to_signup_btn.click(
1111
  fn=lambda: (gr.update(visible=False), gr.update(visible=True)),
1112
  inputs=None,