Files changed (1) hide show
  1. app.py +114 -88
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
- # Configuration for authentication
8
- USERNAME = "admin"
9
- PASSWORD = "password123"
10
-
11
- # List of team members
12
- team_members = [
13
- "Akhil", "Sarthak", "Sai Charitha", "Prasad K", "Anand S",
14
- "Harsh Naik", "Divya Singh", "Ritesh Kumar Tiwary",
15
- "Balamurali Ommi", "Lalit Singh", "Bhavana K", "Bickramjit Basu",
16
- "C R Tejavardhan", "Ashok M", "Harshitha T", "Man Mohan Nayak",
17
- "Prasad Dattatray Amale", "Praveena Bharathi", "Ranga Bhashyams",
18
- "Sahil Singh Diwan", "Sathwika", "Sayali Vinod", "Yashwanth Gundala",
19
- "Gopinath", "Arun Kumar Tiwary"
20
- ]
21
-
22
- # File path to store history
23
- HISTORY_FILE = "selection_history.json"
24
-
25
- # Initialize the history file if it doesn't exist
26
- if not os.path.exists(HISTORY_FILE):
27
- with open(HISTORY_FILE, 'w') as f:
28
- json.dump([], f)
29
-
30
- # Function to select random team members
31
- def select_members(members, last_selected, num_to_select=2):
32
- available_members = [member for member in members if member not in last_selected]
33
- if len(available_members) < num_to_select:
34
- raise ValueError("Not enough members to select from without repeating the last pair.")
35
- selected_members = random.sample(available_members, num_to_select)
36
- last_selected.clear()
37
- last_selected.extend(selected_members)
38
- return selected_members
39
-
40
- # Function to save history
41
- def save_history(selection):
42
- with open(HISTORY_FILE, 'r') as f:
43
- history = json.load(f)
44
- history.append(selection)
45
- with open(HISTORY_FILE, 'w') as f:
46
- json.dump(history, f)
47
-
48
- # Authentication
49
- def authenticate(username, password):
50
- return username == USERNAME and password == PASSWORD
51
-
52
- # Streamlit UI
53
- st.title("AI Learning Presentation - Team Member Selection")
54
-
55
- # Login
56
- if 'authenticated' not in st.session_state or not st.session_state.authenticated:
57
- username = st.text_input("Username")
58
- password = st.text_input("Password", type="password")
59
- if st.button("Login"):
60
- if authenticate(username, password):
61
- st.session_state.authenticated = True
62
- st.success("Logged in successfully!")
63
- else:
64
- st.error("Invalid username or password")
65
- else:
66
- st.write("Select random team members for the next session.")
67
-
68
- num_selections = st.slider("Number of times to run the selection", 1, 10, 3)
69
-
70
- if st.button("Run Selection"):
71
- last_selected = []
72
-
73
- for i in range(num_selections):
74
- try:
75
- selected_members = select_members(team_members, last_selected)
76
- timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
77
- st.write(f"Run {i + 1} - Selected members: {', '.join(selected_members)} at {timestamp}")
78
- save_history({"run": i + 1, "members": selected_members, "timestamp": timestamp})
79
- except ValueError as e:
80
- st.error(e)
81
-
82
- if st.button("View History"):
83
- with open(HISTORY_FILE, 'r') as f:
84
- history = json.load(f)
85
- st.write("Selection History:")
86
- for entry in history:
87
- timestamp = entry.get('timestamp', 'No timestamp available')
88
- st.write(f"Run {entry['run']} - Selected members: {', '.join(entry['members'])} at {timestamp}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()