SapaiSolutions commited on
Commit
e732f00
·
1 Parent(s): 170ac2b

Update password handling and improve login flow

Browse files
Files changed (1) hide show
  1. demo.py +14 -6
demo.py CHANGED
@@ -10,7 +10,7 @@ load_dotenv()
10
  # Load env variables
11
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
12
  ASSISTANT_ID = os.getenv("ASSISTANT_ID")
13
- PASSWORD_HASH = os.getenv("PASSWORD") # Stored password hash in .env
14
 
15
  client = OpenAI(api_key=OPENAI_API_KEY)
16
 
@@ -48,7 +48,7 @@ def verify_password(password):
48
 
49
  # Hash the input password
50
  hashed_input = hashlib.sha256(password.encode()).hexdigest()
51
-
52
  # Compare with stored hash
53
  if hashed_input == PASSWORD_HASH:
54
  return True, "Authentication successful"
@@ -81,14 +81,16 @@ with gr.Blocks(title="TM Tender Assistant") as demo:
81
  success, message = verify_password(password)
82
  if success:
83
  return {
84
- login_group: gr.update(visible=False),
85
- chat_group: gr.update(visible=True),
86
  login_message: ""
87
  }
88
  else:
 
89
  return {
90
- login_message: message,
91
- password_input: ""
 
92
  }
93
 
94
  login_button.click(
@@ -96,6 +98,12 @@ with gr.Blocks(title="TM Tender Assistant") as demo:
96
  inputs=[password_input],
97
  outputs=[login_group, chat_group, login_message]
98
  )
 
 
 
 
 
 
99
 
100
  def user_input(user_message, history):
101
  user_content = user_message
 
10
  # Load env variables
11
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
12
  ASSISTANT_ID = os.getenv("ASSISTANT_ID")
13
+ PASSWORD_HASH = os.getenv("PASSWORD_HASH") # Stored password hash in .env
14
 
15
  client = OpenAI(api_key=OPENAI_API_KEY)
16
 
 
48
 
49
  # Hash the input password
50
  hashed_input = hashlib.sha256(password.encode()).hexdigest()
51
+ print(hashed_input)
52
  # Compare with stored hash
53
  if hashed_input == PASSWORD_HASH:
54
  return True, "Authentication successful"
 
81
  success, message = verify_password(password)
82
  if success:
83
  return {
84
+ login_group: gr.Group(visible=False),
85
+ chat_group: gr.Group(visible=True),
86
  login_message: ""
87
  }
88
  else:
89
+ print("Fail")
90
  return {
91
+ login_group: gr.Group(visible=True),
92
+ chat_group: gr.Group(visible=False),
93
+ login_message: ""
94
  }
95
 
96
  login_button.click(
 
98
  inputs=[password_input],
99
  outputs=[login_group, chat_group, login_message]
100
  )
101
+
102
+ password_input.submit(
103
+ login,
104
+ inputs=[password_input],
105
+ outputs=[login_group, chat_group, login_message]
106
+ )
107
 
108
  def user_input(user_message, history):
109
  user_content = user_message