chandralegend commited on
Commit
ac25ff2
1 Parent(s): 11de9b2

fixed login

Browse files
Files changed (3) hide show
  1. README.md +5 -5
  2. utils/levels.py +29 -53
  3. utils/login.py +34 -2
README.md CHANGED
@@ -1,12 +1,12 @@
1
  ---
2
- title: Aieye Tutorial Template
3
- emoji: 🌍
4
- colorFrom: green
5
- colorTo: purple
6
  sdk: streamlit
7
  sdk_version: 1.21.0
8
  app_file: 0_Introduction.py
9
- pinned: false
10
  license: openrail
11
  duplicated_from: aieye/aieye_tutorial_template
12
  ---
 
1
  ---
2
+ title: Named Entity Recognition
3
+ emoji: 🤖
4
+ colorFrom: red
5
+ colorTo: blue
6
  sdk: streamlit
7
  sdk_version: 1.21.0
8
  app_file: 0_Introduction.py
9
+ pinned: true
10
  license: openrail
11
  duplicated_from: aieye/aieye_tutorial_template
12
  ---
utils/levels.py CHANGED
@@ -1,60 +1,36 @@
1
  import streamlit as st
 
2
  import os
3
- import requests
4
- import os
5
- import json
6
-
7
- # Fetch the service account key JSON file contents
8
-
9
 
10
- def initialize_login():
11
- if "login" not in st.session_state:
12
- st.columns(3)[1].image("assets/logo.png")
13
- username = st.text_input("Username")
14
- password = st.text_input("Password", type="password")
15
-
16
- if st.button("Login"):
17
- authorized = authenticate(username, password)
18
- if authorized["status"]:
19
- st.session_state["login"] = authorized
20
- os.makedirs(
21
- os.path.join(".sessions", st.session_state["login"]["username"]),
22
- exist_ok=True,
23
- )
24
- st.success("Login Successful!")
25
- st.experimental_rerun()
26
  else:
27
- st.error("Invalid username or password")
 
 
 
 
 
 
 
 
 
 
 
28
  else:
29
- st.sidebar.success(f'Hello, {st.session_state["login"]["Name"]}!')
30
- st.sidebar.image("assets/logo.png", use_column_width=True)
31
-
32
 
33
- def authenticate(username, password):
34
- FIREBASE_WEB_API_KEY = os.environ.get("FIREBASE_WEB_API_KEY")
35
- payload = json.dumps(
36
- {
37
- "email": f"{username}@aieye.com",
38
- "password": password,
39
- "returnSecureToken": False,
40
- }
41
- )
42
-
43
- rest_api_url = (
44
- f"https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword"
45
- )
46
- r = requests.post(rest_api_url, params={"key": FIREBASE_WEB_API_KEY}, data=payload)
47
- print(r.json())
48
-
49
- if r.status_code == 200:
50
- return {
51
- "status": True,
52
- "Name": " ".join(username.split("_")),
53
- "username": username,
54
- }
55
  else:
56
- return {"status": False}
57
-
58
-
59
- def get_login():
60
- return st.session_state.get("login", {"status": False})
 
1
  import streamlit as st
2
+ from utils.login import get_login
3
  import os
 
 
 
 
 
 
4
 
5
+ def initialize_level():
6
+ if 'level' not in st.session_state:
7
+ if get_login()["status"]:
8
+ if not os.path.exists(f".sessions/{get_login()['username']}/level.txt"):
9
+ with open(f".sessions/{get_login()['username']}/level.txt", "w") as f:
10
+ f.write("0")
11
+ st.session_state['level'] = 0
 
 
 
 
 
 
 
 
 
12
  else:
13
+ with open(f".sessions/{get_login()['username']}/level.txt", "r") as f:
14
+ st.session_state['level'] = int(f.read())
15
+
16
+ def get_level():
17
+ return st.session_state['level']
18
+
19
+ def render_page(page, level):
20
+ if get_login()["status"]:
21
+ if st.session_state['level'] < level:
22
+ st.error(f"You need to complete Level {st.session_state['level']} first!")
23
+ else:
24
+ page()
25
  else:
26
+ st.error("You need to login first!")
 
 
27
 
28
+ def complete_level(level):
29
+ if st.session_state['level'] > level:
30
+ st.info(f'You have Already completed Level {level}!')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  else:
32
+ st.session_state['level'] = level + 1
33
+ with open(f".sessions/{get_login()['username']}/level.txt", "w") as f:
34
+ f.write(str(st.session_state['level']))
35
+ st.balloons()
36
+ st.success(f'You have completed Level {level}! You can now move on to the next level.')
utils/login.py CHANGED
@@ -1,5 +1,10 @@
1
  import streamlit as st
2
  import os
 
 
 
 
 
3
 
4
 
5
  def initialize_login():
@@ -7,9 +12,9 @@ def initialize_login():
7
  st.columns(3)[1].image("assets/logo.png")
8
  username = st.text_input("Username")
9
  password = st.text_input("Password", type="password")
 
10
  if st.button("Login"):
11
- # TODO: replace with actual authorization check
12
- authorized = {"status": True, "Name": "John Doe", "username": "johndoe"}
13
  if authorized["status"]:
14
  st.session_state["login"] = authorized
15
  os.makedirs(
@@ -22,6 +27,33 @@ def initialize_login():
22
  st.error("Invalid username or password")
23
  else:
24
  st.sidebar.success(f'Hello, {st.session_state["login"]["Name"]}!')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
 
27
  def get_login():
 
1
  import streamlit as st
2
  import os
3
+ import requests
4
+ import os
5
+ import json
6
+
7
+ # Fetch the service account key JSON file contents
8
 
9
 
10
  def initialize_login():
 
12
  st.columns(3)[1].image("assets/logo.png")
13
  username = st.text_input("Username")
14
  password = st.text_input("Password", type="password")
15
+
16
  if st.button("Login"):
17
+ authorized = authenticate(username, password)
 
18
  if authorized["status"]:
19
  st.session_state["login"] = authorized
20
  os.makedirs(
 
27
  st.error("Invalid username or password")
28
  else:
29
  st.sidebar.success(f'Hello, {st.session_state["login"]["Name"]}!')
30
+ st.sidebar.image("assets/logo.png", use_column_width=True)
31
+
32
+
33
+ def authenticate(username, password):
34
+ FIREBASE_WEB_API_KEY = os.environ.get("FIREBASE_WEB_API_KEY")
35
+ payload = json.dumps(
36
+ {
37
+ "email": f"{username}@aieye.com",
38
+ "password": password,
39
+ "returnSecureToken": False,
40
+ }
41
+ )
42
+
43
+ rest_api_url = (
44
+ f"https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword"
45
+ )
46
+ r = requests.post(rest_api_url, params={"key": FIREBASE_WEB_API_KEY}, data=payload)
47
+ print(r.json())
48
+
49
+ if r.status_code == 200:
50
+ return {
51
+ "status": True,
52
+ "Name": " ".join(username.split("_")),
53
+ "username": username,
54
+ }
55
+ else:
56
+ return {"status": False}
57
 
58
 
59
  def get_login():