Update app.py
#2
by
Gopinath2803
- opened
app.py
CHANGED
@@ -1,88 +1,114 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import random
|
3 |
-
import json
|
4 |
-
import os
|
5 |
-
from datetime import datetime
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
"
|
18 |
-
"
|
19 |
-
"
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
# Initialize
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
st.
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
st.write("
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import random
|
3 |
+
import json
|
4 |
+
import os
|
5 |
+
from datetime import datetime
|
6 |
+
import hashlib
|
7 |
+
from dotenv import load_dotenv
|
8 |
+
|
9 |
+
# Load environment variables
|
10 |
+
load_dotenv()
|
11 |
+
|
12 |
+
# Configuration
|
13 |
+
HISTORY_FILE = "selection_history.json"
|
14 |
+
|
15 |
+
# Team members
|
16 |
+
team_members = [
|
17 |
+
"Akhil", "Sarthak", "Sai Charitha", "Prasad K", "Anand S", "Harsh Naik",
|
18 |
+
"Divya Singh", "Ritesh Kumar Tiwary", "Balamurali Ommi", "Lalit Singh",
|
19 |
+
"Bhavana K", "Bickramjit Basu", "C R Tejavardhan", "Ashok M", "Harshitha T",
|
20 |
+
"Man Mohan Nayak", "Prasad Dattatray Amale", "Praveena Bharathi",
|
21 |
+
"Ranga Bhashyams", "Sahil Singh Diwan", "Sathwika", "Sayali Vinod",
|
22 |
+
"Yashwanth Gundala", "Gopinath", "Arun Kumar Tiwary"
|
23 |
+
]
|
24 |
+
|
25 |
+
# Initialize history file
|
26 |
+
def initialize_history_file():
|
27 |
+
if not os.path.exists(HISTORY_FILE):
|
28 |
+
with open(HISTORY_FILE, 'w') as f:
|
29 |
+
json.dump([], f)
|
30 |
+
|
31 |
+
# Hash password
|
32 |
+
def hash_password(password):
|
33 |
+
return hashlib.sha256(password.encode()).hexdigest()
|
34 |
+
|
35 |
+
# Authenticate user
|
36 |
+
def authenticate(username, password):
|
37 |
+
stored_username = os.getenv("APP_USERNAME")
|
38 |
+
stored_password_hash = os.getenv("APP_PASSWORD_HASH")
|
39 |
+
return username == stored_username and hash_password(password) == stored_password_hash
|
40 |
+
|
41 |
+
# Team member selection
|
42 |
+
def select_members(members, last_selected, num_to_select=2):
|
43 |
+
available_members = [member for member in members if member not in last_selected]
|
44 |
+
if len(available_members) < num_to_select:
|
45 |
+
raise ValueError("Not enough members to select from without repeating the last pair.")
|
46 |
+
selected_members = random.sample(available_members, num_to_select)
|
47 |
+
last_selected.clear()
|
48 |
+
last_selected.extend(selected_members)
|
49 |
+
return selected_members
|
50 |
+
|
51 |
+
# Save history
|
52 |
+
def save_history(selection):
|
53 |
+
with open(HISTORY_FILE, 'r+') as f:
|
54 |
+
history = json.load(f)
|
55 |
+
history.append(selection)
|
56 |
+
f.seek(0)
|
57 |
+
json.dump(history, f)
|
58 |
+
f.truncate()
|
59 |
+
|
60 |
+
# Clear history
|
61 |
+
def clear_history():
|
62 |
+
with open(HISTORY_FILE, 'w') as f:
|
63 |
+
json.dump([], f)
|
64 |
+
st.success("History cleared.")
|
65 |
+
|
66 |
+
# Streamlit UI
|
67 |
+
def main():
|
68 |
+
st.title("AI Learning Presentation - Team Member Selection")
|
69 |
+
|
70 |
+
initialize_history_file()
|
71 |
+
|
72 |
+
if 'authenticated' not in st.session_state:
|
73 |
+
st.session_state.authenticated = False
|
74 |
+
|
75 |
+
if not st.session_state.authenticated:
|
76 |
+
username = st.text_input("Username")
|
77 |
+
password = st.text_input("Password", type="password")
|
78 |
+
if st.button("Login"):
|
79 |
+
if authenticate(username, password):
|
80 |
+
st.session_state.authenticated = True
|
81 |
+
st.success("Logged in successfully!")
|
82 |
+
else:
|
83 |
+
st.error("Invalid username or password")
|
84 |
+
else:
|
85 |
+
st.write("Select random team members for the next session.")
|
86 |
+
num_selections = st.slider("Number of times to run the selection", 1, 10, 3)
|
87 |
+
|
88 |
+
if st.button("Run Selection"):
|
89 |
+
last_selected = []
|
90 |
+
for i in range(num_selections):
|
91 |
+
try:
|
92 |
+
selected_members = select_members(team_members, last_selected)
|
93 |
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
94 |
+
st.write(f"Run: {i + 1}, Time: {timestamp} \n Selected members: {', '.join(selected_members)}")
|
95 |
+
save_history({"run": i + 1, "timestamp": timestamp, "members": selected_members})
|
96 |
+
except ValueError as e:
|
97 |
+
st.error(str(e))
|
98 |
+
|
99 |
+
if st.button("View History"):
|
100 |
+
with open(HISTORY_FILE, 'r') as f:
|
101 |
+
history = json.load(f)
|
102 |
+
st.write("Selection History:")
|
103 |
+
for entry in history:
|
104 |
+
timestamp = entry.get('timestamp', 'No timestamp available')
|
105 |
+
st.write(f"Run {entry['run']}, Time: {timestamp}, Selected members: {', '.join(entry['members'])}")
|
106 |
+
|
107 |
+
if st.button("Clear History"):
|
108 |
+
clear_history()
|
109 |
+
|
110 |
+
if st.button("Logout"):
|
111 |
+
st.session_state.authenticated = False
|
112 |
+
|
113 |
+
if __name__ == "__main__":
|
114 |
+
main()
|