import streamlit as st import random import json import os from datetime import datetime # Configuration for authentication USERNAME = "admin" PASSWORD = "password123" # List of team members 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" ] # File path to store history HISTORY_FILE = "selection_history.json" # Initialize the history file if it doesn't exist if not os.path.exists(HISTORY_FILE): with open(HISTORY_FILE, 'w') as f: json.dump([], f) # Function to select random team members 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 # Function to save history def save_history(selection): with open(HISTORY_FILE, 'r') as f: history = json.load(f) history.append(selection) with open(HISTORY_FILE, 'w') as f: json.dump(history, f) # Function to clear history def clear_history(): with open(HISTORY_FILE, 'w') as f: json.dump([], f) # Authentication def authenticate(username, password): return username == USERNAME and password == PASSWORD # Streamlit UI st.title("AI Learning Presentation - Team Member Selection") # Login if 'authenticated' not in st.session_state or 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} - Selected members: {', '.join(selected_members)} at {timestamp}") save_history({"run": i + 1, "members": selected_members, "timestamp": timestamp}) except ValueError as e: st.error(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: # Handle the absence of 'timestamp' in older entries timestamp = entry.get('timestamp', 'N/A') st.write(f"Run {entry['run']} - Selected members: {', '.join(entry['members'])} at {timestamp}") if st.button("Clear History"): clear_history() st.success("History cleared successfully!")