Spaces:
Runtime error
Runtime error
PASSWORD_FIX
#3
by
BMCVRN - opened
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("
|
| 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.
|
| 85 |
-
chat_group: gr.
|
| 86 |
login_message: ""
|
| 87 |
}
|
| 88 |
else:
|
|
|
|
| 89 |
return {
|
| 90 |
-
|
| 91 |
-
|
|
|
|
| 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
|