Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,11 @@ from datasets import load_dataset
|
|
| 6 |
import io
|
| 7 |
import ast
|
| 8 |
import re
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# --- 1. CONFIGURATION ---
|
| 11 |
DEBUG_TESTING = False
|
|
@@ -17,18 +22,33 @@ token = 'GbeqFrdNnENcHiJtUnTKcAbVkneXrlOkHb'
|
|
| 17 |
HF_DATASET_REPO = "akaburia/policy-evaluations"
|
| 18 |
HF_TOKEN = HF + '_' + token
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
DRILL_DOWN_MAP = {
|
| 34 |
"coherent": ["+3 Indivisible", "+2 Reinforcing", "+1 Enabling"],
|
|
@@ -449,20 +469,23 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 449 |
}
|
| 450 |
|
| 451 |
def login_and_load(email):
|
| 452 |
-
|
| 453 |
-
|
| 454 |
|
| 455 |
-
|
|
|
|
|
|
|
|
|
|
| 456 |
|
| 457 |
if DEBUG_TESTING:
|
| 458 |
full_df, pending_df, status = load_data_from_local()
|
| 459 |
token_to_store = "debug_mode"
|
| 460 |
else:
|
| 461 |
-
if not HF_TOKEN:
|
| 462 |
-
|
| 463 |
full_df, pending_df, status = load_data_from_hub(HF_TOKEN)
|
| 464 |
token_to_store = HF_TOKEN
|
| 465 |
-
|
| 466 |
if full_df is None: return {progress_bar: gr.Markdown(f"<font color='red'>{status}</font>"), login_box: gr.Group(visible=True)}
|
| 467 |
|
| 468 |
first_item_updates = load_next_item(pending_df, 0)
|
|
@@ -473,6 +496,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 473 |
first_item_updates[user_tag_state] = user_tag
|
| 474 |
first_item_updates[login_box] = gr.Group(visible=False)
|
| 475 |
first_item_updates[annotation_box] = gr.Group(visible=True)
|
|
|
|
| 476 |
return first_item_updates
|
| 477 |
|
| 478 |
login_btn.click(
|
|
|
|
| 6 |
import io
|
| 7 |
import ast
|
| 8 |
import re
|
| 9 |
+
import json
|
| 10 |
+
from dotenv import load_dotenv # Only needed if running locally
|
| 11 |
+
|
| 12 |
+
# Load environment variables from a .env file if it exists locally
|
| 13 |
+
load_dotenv()
|
| 14 |
|
| 15 |
# --- 1. CONFIGURATION ---
|
| 16 |
DEBUG_TESTING = False
|
|
|
|
| 22 |
HF_DATASET_REPO = "akaburia/policy-evaluations"
|
| 23 |
HF_TOKEN = HF + '_' + token
|
| 24 |
|
| 25 |
+
|
| 26 |
+
emails_env_string = os.environ.get("APPROVED_EMAILS", "{}")
|
| 27 |
+
|
| 28 |
+
# 2. Parse the string into a Python dictionary
|
| 29 |
+
try:
|
| 30 |
+
APPROVED_EMAILS = json.loads(emails_env_string)
|
| 31 |
+
|
| 32 |
+
# Force all keys to lowercase right at startup
|
| 33 |
+
APPROVED_EMAILS = {k.lower(): v for k, v in APPROVED_EMAILS.items()}
|
| 34 |
+
|
| 35 |
+
except (json.JSONDecodeError, TypeError) as e:
|
| 36 |
+
print(f"⚠️ Error parsing APPROVED_EMAILS from environment variables: {e}")
|
| 37 |
+
# FALLBACK DICTIONARY: All emails here MUST be lowercase!
|
| 38 |
+
APPROVED_EMAILS = {
|
| 39 |
+
"kaburiaaustin1@tahmo.org": "user1",
|
| 40 |
+
"e.ramos@tudelft.nl" : "user2",
|
| 41 |
+
"eunice.pramos@gmail.com" : "user3",
|
| 42 |
+
"e.abraham@tudelft.nl" : "user4",
|
| 43 |
+
"dene.abv@gmail.com" : "user5",
|
| 44 |
+
"rafatoufofana.abv@gmail.com" : "user6",
|
| 45 |
+
"annorfrank@tahmo.org" : "user7",
|
| 46 |
+
"n.marley@tahmo.org" : "user8",
|
| 47 |
+
"h.f.hagenaars@tudelft.nl" : "user9",
|
| 48 |
+
"kaburiaaustin1@gmail.com" : "user10",
|
| 49 |
+
"faridakone@gmail.com": "user11"
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
|
| 53 |
DRILL_DOWN_MAP = {
|
| 54 |
"coherent": ["+3 Indivisible", "+2 Reinforcing", "+1 Enabling"],
|
|
|
|
| 469 |
}
|
| 470 |
|
| 471 |
def login_and_load(email):
|
| 472 |
+
# Sanitise the input by stripping whitespace and converting to lowercase
|
| 473 |
+
clean_email = email.strip().lower()
|
| 474 |
|
| 475 |
+
if clean_email not in APPROVED_EMAILS:
|
| 476 |
+
return {progress_bar: gr.Markdown(f"<font color='red'>Error: Email '{email}' is not authorized.</font>"), login_box: gr.Group(visible=True)}
|
| 477 |
+
|
| 478 |
+
user_tag = APPROVED_EMAILS[clean_email]
|
| 479 |
|
| 480 |
if DEBUG_TESTING:
|
| 481 |
full_df, pending_df, status = load_data_from_local()
|
| 482 |
token_to_store = "debug_mode"
|
| 483 |
else:
|
| 484 |
+
if not HF_TOKEN:
|
| 485 |
+
return {progress_bar: gr.Markdown(f"<font color='red'>Error: HF_TOKEN is missing.</font>"), login_box: gr.Group(visible=True)}
|
| 486 |
full_df, pending_df, status = load_data_from_hub(HF_TOKEN)
|
| 487 |
token_to_store = HF_TOKEN
|
| 488 |
+
|
| 489 |
if full_df is None: return {progress_bar: gr.Markdown(f"<font color='red'>{status}</font>"), login_box: gr.Group(visible=True)}
|
| 490 |
|
| 491 |
first_item_updates = load_next_item(pending_df, 0)
|
|
|
|
| 496 |
first_item_updates[user_tag_state] = user_tag
|
| 497 |
first_item_updates[login_box] = gr.Group(visible=False)
|
| 498 |
first_item_updates[annotation_box] = gr.Group(visible=True)
|
| 499 |
+
|
| 500 |
return first_item_updates
|
| 501 |
|
| 502 |
login_btn.click(
|