|
import streamlit as st |
|
import random |
|
import json |
|
import os |
|
from datetime import datetime |
|
import hashlib |
|
from dotenv import load_dotenv |
|
|
|
|
|
load_dotenv() |
|
|
|
|
|
HISTORY_FILE = "selection_history.json" |
|
|
|
|
|
team_members = [ |
|
"Akhil", "Sarthak", "Sai Charitha", "Prasad K", "Anand S", "Harsh Naik", |
|
"Divya Singh", "Ritesh Kumar Tiwary", "Balamurali Ommi", "Lalit Singh", |
|
"Bhavana K", "Bickramjit Basu", "C R Tejavardhan", "Ashok M", "Harshitha T", |
|
"Man Mohan Nayak", "Prasad Dattatray Amale", "Praveena Bharathi", |
|
"Ranga Bhashyams", "Sahil Singh Diwan", "Sathwika", "Sayali Vinod", |
|
"Yashwanth Gundala", "Gopinath", "Arun Kumar Tiwary" |
|
] |
|
|
|
|
|
def initialize_history_file(): |
|
if not os.path.exists(HISTORY_FILE): |
|
with open(HISTORY_FILE, 'w') as f: |
|
json.dump([], f) |
|
|
|
|
|
def hash_password(password): |
|
return hashlib.sha256(password.encode()).hexdigest() |
|
|
|
|
|
def authenticate(username, password): |
|
stored_username = os.getenv("APP_USERNAME") |
|
stored_password_hash = os.getenv("APP_PASSWORD_HASH") |
|
return username == stored_username and hash_password(password) == stored_password_hash |
|
|
|
|
|
def select_members(members, last_selected, num_to_select=2): |
|
available_members = [member for member in members if member not in last_selected] |
|
if len(available_members) < num_to_select: |
|
raise ValueError("Not enough members to select from without repeating the last pair.") |
|
selected_members = random.sample(available_members, num_to_select) |
|
last_selected.clear() |
|
last_selected.extend(selected_members) |
|
return selected_members |
|
|
|
|
|
def save_history(selection): |
|
with open(HISTORY_FILE, 'r+') as f: |
|
history = json.load(f) |
|
history.append(selection) |
|
f.seek(0) |
|
json.dump(history, f) |
|
f.truncate() |
|
|
|
|
|
def clear_history(): |
|
with open(HISTORY_FILE, 'w') as f: |
|
json.dump([], f) |
|
st.success("History cleared.") |
|
|
|
|
|
def main(): |
|
st.title("AI Learning Presentation - Team Member Selection") |
|
|
|
initialize_history_file() |
|
|
|
if 'authenticated' not in st.session_state: |
|
st.session_state.authenticated = False |
|
|
|
if not st.session_state.authenticated: |
|
username = st.text_input("Username") |
|
password = st.text_input("Password", type="password") |
|
if st.button("Login"): |
|
if authenticate(username, password): |
|
st.session_state.authenticated = True |
|
st.success("Logged in successfully!") |
|
else: |
|
st.error("Invalid username or password") |
|
else: |
|
st.write("Select random team members for the next session.") |
|
num_selections = st.slider("Number of times to run the selection", 1, 10, 3) |
|
|
|
if st.button("Run Selection"): |
|
last_selected = [] |
|
for i in range(num_selections): |
|
try: |
|
selected_members = select_members(team_members, last_selected) |
|
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
|
st.write(f"Run: {i + 1}, Time: {timestamp} \n Selected members: {', '.join(selected_members)}") |
|
save_history({"run": i + 1, "timestamp": timestamp, "members": selected_members}) |
|
except ValueError as e: |
|
st.error(str(e)) |
|
|
|
if st.button("View History"): |
|
with open(HISTORY_FILE, 'r') as f: |
|
history = json.load(f) |
|
st.write("Selection History:") |
|
for entry in history: |
|
timestamp = entry.get('timestamp', 'No timestamp available') |
|
st.write(f"Run {entry['run']}, Time: {timestamp}, Selected members: {', '.join(entry['members'])}") |
|
|
|
if st.button("Clear History"): |
|
clear_history() |
|
|
|
if st.button("Logout"): |
|
st.session_state.authenticated = False |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|