Spaces:
Sleeping
Sleeping
Update app_web.py
Browse files- app_web.py +14 -41
app_web.py
CHANGED
|
@@ -9,56 +9,29 @@ from src.query_engine import understand_query
|
|
| 9 |
from src.retriever import clear_collection_cache, retrieve
|
| 10 |
from src.verifier import verify_and_respond
|
| 11 |
from src.llm import list_models
|
| 12 |
-
from huggingface_hub import snapshot_download
|
| 13 |
|
| 14 |
snapshot_download(repo_id="CGIAR/weai-kb",
|
| 15 |
repo_type="dataset",
|
| 16 |
token=os.getenv('HF_TOKEN'),
|
| 17 |
local_dir="./"
|
| 18 |
)
|
| 19 |
-
|
| 20 |
-
if "OAUTH_CLIENT_ID" in os.environ:
|
| 21 |
-
scrts = {
|
| 22 |
-
"client_id": os.environ["OAUTH_CLIENT_ID"],
|
| 23 |
-
"client_secret": os.environ["OAUTH_CLIENT_SECRET"],
|
| 24 |
-
"server_metadata_url": f"{os.environ['OPENID_PROVIDER_URL']}/.well-known/openid-configuration",
|
| 25 |
-
"redirect_uri": "https://huggingface.co/spaces/" + os.environ.get("SPACE_ID", "") + "/oauth2/callback",
|
| 26 |
-
"cookie_secret": os.environ.get("OAUTH_CLIENT_SECRET")[:32] # Needs to be string safe
|
| 27 |
-
}
|
| 28 |
-
from huggingface_hub import whoami
|
| 29 |
-
|
| 30 |
-
try:
|
| 31 |
-
# Fetch user info using the cached or environment token (HF_TOKEN)
|
| 32 |
-
user_info = whoami()
|
| 33 |
-
|
| 34 |
-
username = user_info.get("name")
|
| 35 |
-
# Organizations are listed under the 'orgs' key as a list of dicts
|
| 36 |
-
organizations = [org["name"] for org in user_info.get("orgs", [])]
|
| 37 |
|
| 38 |
-
print(f"Logged in username: {username}")
|
| 39 |
-
print(f"Organizations: {organizations}")
|
| 40 |
-
|
| 41 |
-
except Exception as e:
|
| 42 |
-
print("User is not logged in or the token is invalid:", e)
|
| 43 |
def cg_admin():
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
# 3. Extract and display the list of organizations
|
| 56 |
-
# The 'orgs' list contains objects with organization details (name, role, etc.)
|
| 57 |
-
orgs = user_data.get("orgs", [])
|
| 58 |
-
print(orgs)
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
|
| 63 |
# ββ Session initialisation βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 64 |
def init_session():
|
|
|
|
| 9 |
from src.retriever import clear_collection_cache, retrieve
|
| 10 |
from src.verifier import verify_and_respond
|
| 11 |
from src.llm import list_models
|
| 12 |
+
from huggingface_hub import snapshot_download, whoami
|
| 13 |
|
| 14 |
snapshot_download(repo_id="CGIAR/weai-kb",
|
| 15 |
repo_type="dataset",
|
| 16 |
token=os.getenv('HF_TOKEN'),
|
| 17 |
local_dir="./"
|
| 18 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
def cg_admin():
|
| 21 |
+
try:
|
| 22 |
+
# Fetch user info using the cached or environment token (HF_TOKEN)
|
| 23 |
+
user_info = whoami()
|
| 24 |
+
|
| 25 |
+
username = user_info.get("name")
|
| 26 |
+
# Organizations are listed under the 'orgs' key as a list of dicts
|
| 27 |
+
orgs = [org["name"] for org in user_info.get("orgs", [])]
|
| 28 |
+
|
| 29 |
+
except Exception as e:
|
| 30 |
+
print("User is not logged in or the token is invalid:", e)
|
| 31 |
+
orgs = []
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
if "CGIAR" in orgs:
|
| 34 |
+
return True
|
| 35 |
|
| 36 |
# ββ Session initialisation βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 37 |
def init_session():
|