GenAITeamInfobell
commited on
Commit
•
140daf4
1
Parent(s):
76e2d7a
Update app.py
Browse files
app.py
CHANGED
@@ -3,42 +3,33 @@ import random
|
|
3 |
import json
|
4 |
import os
|
5 |
from datetime import datetime
|
6 |
-
import
|
7 |
-
|
|
|
8 |
|
9 |
-
#
|
10 |
-
|
|
|
11 |
|
12 |
-
#
|
13 |
-
HISTORY_FILE = "selection_history.json"
|
14 |
-
|
15 |
-
# Team members
|
16 |
team_members = [
|
17 |
-
"Akhil", "Sarthak", "Sai Charitha", "Prasad K", "Anand S",
|
18 |
-
"Divya Singh", "Ritesh Kumar Tiwary",
|
19 |
-
"
|
20 |
-
"
|
21 |
-
"
|
22 |
-
"
|
|
|
23 |
]
|
24 |
|
25 |
-
#
|
26 |
-
|
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 |
-
#
|
36 |
-
|
37 |
-
|
38 |
-
|
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:
|
@@ -48,67 +39,70 @@ def select_members(members, last_selected, num_to_select=2):
|
|
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
|
54 |
history = json.load(f)
|
55 |
-
|
56 |
-
|
57 |
json.dump(history, f)
|
58 |
-
f.truncate()
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
# Streamlit UI
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
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()
|
|
|
3 |
import json
|
4 |
import os
|
5 |
from datetime import datetime
|
6 |
+
import schedule
|
7 |
+
import time
|
8 |
+
import threading
|
9 |
|
10 |
+
# Use environment variables for authentication
|
11 |
+
USERNAME = os.getenv("USERNAME")
|
12 |
+
PASSWORD = os.getenv("PASSWORD")
|
13 |
|
14 |
+
# List of team members
|
|
|
|
|
|
|
15 |
team_members = [
|
16 |
+
"Akhil", "Sarthak", "Sai Charitha", "Prasad K", "Anand S",
|
17 |
+
"Harsh Naik", "Divya Singh", "Ritesh Kumar Tiwary",
|
18 |
+
"Balamurali Ommi", "Lalit Singh", "Bhavana K", "Bickramjit Basu",
|
19 |
+
"C R Tejavardhan", "Ashok M", "Harshitha T", "Man Mohan Nayak",
|
20 |
+
"Prasad Dattatray Amale", "Praveena Bharathi", "Ranga Bhashyams",
|
21 |
+
"Sahil Singh Diwan", "Sathwika", "Sayali Vinod", "Yashwanth Gundala",
|
22 |
+
"Gopinath", "Arun Kumar Tiwary"
|
23 |
]
|
24 |
|
25 |
+
# File path to store history
|
26 |
+
HISTORY_FILE = "selection_history.json"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
# Initialize the history file if it doesn't exist
|
29 |
+
if not os.path.exists(HISTORY_FILE):
|
30 |
+
with open(HISTORY_FILE, 'w') as f:
|
31 |
+
json.dump([], f)
|
|
|
32 |
|
|
|
33 |
def select_members(members, last_selected, num_to_select=2):
|
34 |
available_members = [member for member in members if member not in last_selected]
|
35 |
if len(available_members) < num_to_select:
|
|
|
39 |
last_selected.extend(selected_members)
|
40 |
return selected_members
|
41 |
|
|
|
42 |
def save_history(selection):
|
43 |
+
with open(HISTORY_FILE, 'r') as f:
|
44 |
history = json.load(f)
|
45 |
+
history.append(selection)
|
46 |
+
with open(HISTORY_FILE, 'w') as f:
|
47 |
json.dump(history, f)
|
|
|
48 |
|
49 |
+
def authenticate(username, password):
|
50 |
+
return username == USERNAME and password == PASSWORD
|
51 |
+
|
52 |
+
def run_daily_selection():
|
53 |
+
last_selected = []
|
54 |
+
try:
|
55 |
+
selected_members = select_members(team_members, last_selected)
|
56 |
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
57 |
+
save_history({"run": "Scheduled", "members": selected_members, "timestamp": timestamp})
|
58 |
+
print(f"Scheduled Run - Selected members: {', '.join(selected_members)} at {timestamp}")
|
59 |
+
except ValueError as e:
|
60 |
+
print(f"Error during scheduled run: {e}")
|
61 |
+
|
62 |
+
def start_scheduler():
|
63 |
+
schedule.every().day.at("09:30").do(run_daily_selection) # 09:30 UTC is 3:00 PM IST
|
64 |
+
|
65 |
+
while True:
|
66 |
+
schedule.run_pending()
|
67 |
+
time.sleep(1)
|
68 |
+
|
69 |
+
# Start the scheduler in a separate thread
|
70 |
+
scheduler_thread = threading.Thread(target=start_scheduler, daemon=True)
|
71 |
+
scheduler_thread.start()
|
72 |
|
73 |
# Streamlit UI
|
74 |
+
st.title("AI Learning Presentation - Team Member Selection")
|
75 |
+
|
76 |
+
# Login
|
77 |
+
if 'authenticated' not in st.session_state or not st.session_state.authenticated:
|
78 |
+
username = st.text_input("Username")
|
79 |
+
password = st.text_input("Password", type="password")
|
80 |
+
if st.button("Login"):
|
81 |
+
if authenticate(username, password):
|
82 |
+
st.session_state.authenticated = True
|
83 |
+
st.success("Logged in successfully!")
|
84 |
+
else:
|
85 |
+
st.error("Invalid username or password")
|
86 |
+
else:
|
87 |
+
st.write("Select random team members for the next session.")
|
88 |
+
|
89 |
+
num_selections = st.slider("Number of times to run the selection", 1, 10, 3)
|
90 |
+
|
91 |
+
if st.button("Run Selection"):
|
92 |
+
last_selected = []
|
93 |
+
|
94 |
+
for i in range(num_selections):
|
95 |
+
try:
|
96 |
+
selected_members = select_members(team_members, last_selected)
|
97 |
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
98 |
+
st.write(f"Run {i + 1} - Selected members: {', '.join(selected_members)} at {timestamp}")
|
99 |
+
save_history({"run": i + 1, "members": selected_members, "timestamp": timestamp})
|
100 |
+
except ValueError as e:
|
101 |
+
st.error(e)
|
102 |
+
|
103 |
+
if st.button("View History"):
|
104 |
+
with open(HISTORY_FILE, 'r') as f:
|
105 |
+
history = json.load(f)
|
106 |
+
st.write("Selection History:")
|
107 |
+
for entry in history:
|
108 |
+
st.write(f"Run {entry['run']} - Selected members: {', '.join(entry['members'])} at {entry['timestamp']}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|