datacipen commited on
Commit
1b7e1bb
1 Parent(s): b7d9fa0

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +18 -0
main.py CHANGED
@@ -1,4 +1,5 @@
1
  import os
 
2
  from typing import List
3
  from pathlib import Path
4
  from langchain_huggingface import HuggingFaceEmbeddings
@@ -20,6 +21,23 @@ from langchain.callbacks.base import BaseCallbackHandler
20
 
21
  import chainlit as cl
22
  from literalai import LiteralClient
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  literal_client = LiteralClient(api_key=os.getenv("LITERAL_API_KEY"))
24
 
25
  chunk_size = 1024
 
1
  import os
2
+ import json
3
  from typing import List
4
  from pathlib import Path
5
  from langchain_huggingface import HuggingFaceEmbeddings
 
21
 
22
  import chainlit as cl
23
  from literalai import LiteralClient
24
+ @cl.password_auth_callback
25
+ def auth_callback(username: str, password: str):
26
+ auth = json.loads(os.environ['CHAINLIT_AUTH_LOGIN'])
27
+ ident = next(d['ident'] for d in auth if d['ident'] == username)
28
+ pwd = next(d['pwd'] for d in auth if d['ident'] == username)
29
+ resultLogAdmin = bcrypt.checkpw(username.encode('utf-8'), bcrypt.hashpw(ident.encode('utf-8'), bcrypt.gensalt()))
30
+ resultPwdAdmin = bcrypt.checkpw(password.encode('utf-8'), bcrypt.hashpw(pwd.encode('utf-8'), bcrypt.gensalt()))
31
+ resultRole = next(d['role'] for d in auth if d['ident'] == username)
32
+ if resultLogAdmin and resultPwdAdmin and resultRole == "admindatapcc":
33
+ return cl.User(
34
+ identifier=ident + " : 🧑‍💼 Admin Datapcc", metadata={"role": "admin", "provider": "credentials"}
35
+ )
36
+ elif resultLogAdmin and resultPwdAdmin and resultRole == "userdatapcc":
37
+ return cl.User(
38
+ identifier=ident + " : 🧑‍🎓 User Datapcc", metadata={"role": "user", "provider": "credentials"}
39
+ )
40
+
41
  literal_client = LiteralClient(api_key=os.getenv("LITERAL_API_KEY"))
42
 
43
  chunk_size = 1024