Spaces:
Sleeping
Sleeping
feat: add setup for temp users
Browse filesAdd setup for alternative signin credentials for temp users and a
function check_auth to handle both these and the permanent credentials.
To setup a temp user for the app, their username and password should be
set in environment variables TEMP_USERNAME and TEMP_PASSWORD and the
expiry of their access should be set in TEMP_EXPIRY_TIME_SG_ISO_8601,
in Singapore time and ISO 8601 format.
app.py
CHANGED
|
@@ -8,6 +8,8 @@ import json # For conversion of OpenAI responses into json/dictionary objects so
|
|
| 8 |
from dotenv import load_dotenv # For loading environment variables in local environment
|
| 9 |
from collections import Counter # For tabulating tag occurrences
|
| 10 |
import logging
|
|
|
|
|
|
|
| 11 |
|
| 12 |
logger = logging.getLogger()
|
| 13 |
logger.setLevel(logging.INFO)
|
|
@@ -169,6 +171,31 @@ def process_quotes(quotes_file_path: str, quotes_col_name: str, tags_string: str
|
|
| 169 |
tags_counter_df.to_excel(writer, sheet_name='Tag Count', index=False)
|
| 170 |
logger.info('Results written to Excel')
|
| 171 |
return output_df, tags_counter_df, output_file_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
# Define user interface structure
|
| 174 |
demo = gr.Interface(
|
|
@@ -188,4 +215,4 @@ demo = gr.Interface(
|
|
| 188 |
description=INSTRUCTIONS
|
| 189 |
)
|
| 190 |
|
| 191 |
-
demo.launch(share=True, auth=
|
|
|
|
| 8 |
from dotenv import load_dotenv # For loading environment variables in local environment
|
| 9 |
from collections import Counter # For tabulating tag occurrences
|
| 10 |
import logging
|
| 11 |
+
import time
|
| 12 |
+
from datetime import datetime
|
| 13 |
|
| 14 |
logger = logging.getLogger()
|
| 15 |
logger.setLevel(logging.INFO)
|
|
|
|
| 171 |
tags_counter_df.to_excel(writer, sheet_name='Tag Count', index=False)
|
| 172 |
logger.info('Results written to Excel')
|
| 173 |
return output_df, tags_counter_df, output_file_path
|
| 174 |
+
|
| 175 |
+
def check_auth(username:str, password:str):
|
| 176 |
+
"""
|
| 177 |
+
Authenticate the user.
|
| 178 |
+
|
| 179 |
+
Verifies the user's credentials against the values stored in the environment variables.
|
| 180 |
+
User may authenticate with permanent username and password(for TFT team) or temporary username and password.
|
| 181 |
+
For temporary username and password, they will only be valid before the expiry time as set in the environment variables.
|
| 182 |
+
|
| 183 |
+
Returns True or False depending on authentication success.
|
| 184 |
+
"""
|
| 185 |
+
# Check permanent credentials
|
| 186 |
+
if username == os.getenv('APP_USERNAME') and password == os.getenv('APP_PASSWORD'):
|
| 187 |
+
return True
|
| 188 |
+
|
| 189 |
+
# Check temporary credentials
|
| 190 |
+
if (
|
| 191 |
+
username == os.getenv('TEMP_USERNAME') and
|
| 192 |
+
password == os.getenv('TEMP_PASSWORD') and
|
| 193 |
+
time.time() < datetime.fromisoformat(os.getenv('TEMP_EXPIRY_TIME_SG_ISO_8601').replace("Z", "+08:00")).timestamp()
|
| 194 |
+
):
|
| 195 |
+
return True
|
| 196 |
+
|
| 197 |
+
# Invalid credentials
|
| 198 |
+
return False
|
| 199 |
|
| 200 |
# Define user interface structure
|
| 201 |
demo = gr.Interface(
|
|
|
|
| 215 |
description=INSTRUCTIONS
|
| 216 |
)
|
| 217 |
|
| 218 |
+
demo.launch(share=True, auth=check_auth, ssr_mode=False)
|