Spaces:
Sleeping
Sleeping
Upload 7 files
Browse files- __pycache__/main.cpython-312.pyc +0 -0
- app.py +142 -0
- main.py +66 -0
- run.py +38 -0
- session_log.csv +5 -0
- track.txt +4 -0
- users.csv +4 -0
__pycache__/main.cpython-312.pyc
ADDED
|
Binary file (4.68 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import csv
|
| 4 |
+
import os
|
| 5 |
+
from sklearn.datasets import load_iris
|
| 6 |
+
from sklearn.ensemble import RandomForestClassifier
|
| 7 |
+
from sklearn.model_selection import train_test_split
|
| 8 |
+
from sklearn.metrics import accuracy_score
|
| 9 |
+
from datetime import datetime
|
| 10 |
+
import time
|
| 11 |
+
|
| 12 |
+
# Load user credentials from CSV
|
| 13 |
+
def load_users():
|
| 14 |
+
try:
|
| 15 |
+
df = pd.read_csv("users.csv")
|
| 16 |
+
return dict(zip(df['username'], df['password']))
|
| 17 |
+
except FileNotFoundError:
|
| 18 |
+
st.error("users.csv file not found.")
|
| 19 |
+
return {}
|
| 20 |
+
|
| 21 |
+
# Save new user to CSV
|
| 22 |
+
def add_user_to_csv(username, password):
|
| 23 |
+
with open("users.csv", mode='a', newline='') as file:
|
| 24 |
+
writer = csv.writer(file)
|
| 25 |
+
writer.writerow([username, password])
|
| 26 |
+
|
| 27 |
+
# Log session to CSV
|
| 28 |
+
def log_session_to_csv(username, start_time, end_time):
|
| 29 |
+
duration = end_time - start_time
|
| 30 |
+
row = [username, start_time.strftime('%Y-%m-%d %H:%M:%S'),
|
| 31 |
+
end_time.strftime('%Y-%m-%d %H:%M:%S'), str(duration)]
|
| 32 |
+
|
| 33 |
+
file_exists = os.path.isfile("session_log.csv")
|
| 34 |
+
|
| 35 |
+
with open("session_log.csv", mode='a', newline='') as file:
|
| 36 |
+
writer = csv.writer(file)
|
| 37 |
+
if not file_exists:
|
| 38 |
+
writer.writerow(["Username", "Login Time", "Logout Time", "Duration"])
|
| 39 |
+
writer.writerow(row)
|
| 40 |
+
|
| 41 |
+
# Display session logs
|
| 42 |
+
def show_logs():
|
| 43 |
+
if os.path.exists("session_log.csv"):
|
| 44 |
+
df = pd.read_csv("session_log.csv")
|
| 45 |
+
st.subheader("Session Logs")
|
| 46 |
+
st.dataframe(df)
|
| 47 |
+
else:
|
| 48 |
+
st.info("No session logs found yet.")
|
| 49 |
+
|
| 50 |
+
# Load credentials once
|
| 51 |
+
USER_CREDENTIALS = load_users()
|
| 52 |
+
|
| 53 |
+
# Initialize session state
|
| 54 |
+
if 'logged_in' not in st.session_state:
|
| 55 |
+
st.session_state.logged_in = False
|
| 56 |
+
if 'current_user' not in st.session_state:
|
| 57 |
+
st.session_state.current_user = None
|
| 58 |
+
if 'start_time' not in st.session_state:
|
| 59 |
+
st.session_state.start_time = None
|
| 60 |
+
if 'end_time' not in st.session_state:
|
| 61 |
+
st.session_state.end_time = None
|
| 62 |
+
|
| 63 |
+
# Login function
|
| 64 |
+
def login():
|
| 65 |
+
st.title("Login")
|
| 66 |
+
|
| 67 |
+
username = st.text_input("Username")
|
| 68 |
+
password = st.text_input("Password", type="password")
|
| 69 |
+
|
| 70 |
+
if st.button("Login"):
|
| 71 |
+
if username in USER_CREDENTIALS and USER_CREDENTIALS[username] == password:
|
| 72 |
+
st.success("Login successful!")
|
| 73 |
+
st.session_state.logged_in = True
|
| 74 |
+
st.session_state.current_user = username
|
| 75 |
+
st.session_state.start_time = datetime.now()
|
| 76 |
+
st.rerun()
|
| 77 |
+
else:
|
| 78 |
+
st.error("Invalid username or password")
|
| 79 |
+
if st.button("Register"):
|
| 80 |
+
if username and password:
|
| 81 |
+
if username not in USER_CREDENTIALS:
|
| 82 |
+
add_user_to_csv(username, password)
|
| 83 |
+
st.success(f"User {username} successfully registered!")
|
| 84 |
+
st.session_state.logged_in = True
|
| 85 |
+
st.session_state.current_user = username
|
| 86 |
+
st.session_state.start_time = datetime.now()
|
| 87 |
+
|
| 88 |
+
st.rerun()
|
| 89 |
+
else:
|
| 90 |
+
st.error("Username already exists. Please choose another.")
|
| 91 |
+
else:
|
| 92 |
+
st.error("Both username and password are required.")
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
# Logout function
|
| 97 |
+
def logout():
|
| 98 |
+
st.session_state.end_time = datetime.now()
|
| 99 |
+
log_session_to_csv(
|
| 100 |
+
st.session_state.current_user,
|
| 101 |
+
st.session_state.start_time,
|
| 102 |
+
st.session_state.end_time
|
| 103 |
+
)
|
| 104 |
+
st.session_state.logged_in = False
|
| 105 |
+
st.session_state.current_user = None
|
| 106 |
+
st.rerun()
|
| 107 |
+
|
| 108 |
+
# Main app after login
|
| 109 |
+
def app():
|
| 110 |
+
st.title(f"Welcome, {st.session_state.current_user}!")
|
| 111 |
+
|
| 112 |
+
if st.button("Train Random Forest Model"):
|
| 113 |
+
iris = load_iris()
|
| 114 |
+
X_train, X_test, y_train, y_test = train_test_split(
|
| 115 |
+
iris.data, iris.target, test_size=0.3, random_state=42)
|
| 116 |
+
|
| 117 |
+
model = RandomForestClassifier()
|
| 118 |
+
model.fit(X_train, y_train)
|
| 119 |
+
predictions = model.predict(X_test)
|
| 120 |
+
acc = accuracy_score(y_test, predictions)
|
| 121 |
+
|
| 122 |
+
st.success(f"Model trained. Accuracy: {acc:.2f}")
|
| 123 |
+
|
| 124 |
+
if st.button("Logout"):
|
| 125 |
+
logout()
|
| 126 |
+
|
| 127 |
+
if st.session_state.start_time and st.session_state.end_time:
|
| 128 |
+
duration = st.session_state.end_time - st.session_state.start_time
|
| 129 |
+
# st.info(f"last Session Duration: {duration}")
|
| 130 |
+
|
| 131 |
+
if st.checkbox("Show session log"):
|
| 132 |
+
show_logs()
|
| 133 |
+
|
| 134 |
+
# Main controller
|
| 135 |
+
def main():
|
| 136 |
+
if st.session_state.logged_in:
|
| 137 |
+
app()
|
| 138 |
+
else:
|
| 139 |
+
login()
|
| 140 |
+
|
| 141 |
+
if __name__ == "__main__":
|
| 142 |
+
main()
|
main.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
class account_management:
|
| 3 |
+
database = {} # {name:[mail,pass]}
|
| 4 |
+
start={}
|
| 5 |
+
stop={}
|
| 6 |
+
def create_user(self):
|
| 7 |
+
name = input("please enter your name :")
|
| 8 |
+
mail = input("please enter your mail :")
|
| 9 |
+
password = input("please enter your password")
|
| 10 |
+
account_management.database[name] = [mail,password]
|
| 11 |
+
print("account has been created successfully")
|
| 12 |
+
|
| 13 |
+
def get_database(self):
|
| 14 |
+
return account_management.database
|
| 15 |
+
|
| 16 |
+
def login(self):
|
| 17 |
+
input1 = input("please enter the username :")
|
| 18 |
+
|
| 19 |
+
for key in account_management.database.keys():
|
| 20 |
+
if input1 == key:
|
| 21 |
+
input2 = input("please enter the password :")
|
| 22 |
+
if input2 == account_management.database[key][1]:
|
| 23 |
+
print("login successful")
|
| 24 |
+
time.localtime()
|
| 25 |
+
year = time.localtime()[0]
|
| 26 |
+
month = time.localtime()[1]
|
| 27 |
+
date = time.localtime()[2]
|
| 28 |
+
hour = time.localtime()[3]
|
| 29 |
+
minutes = time.localtime()[4]
|
| 30 |
+
seconds = time.localtime()[5]
|
| 31 |
+
with open("C:/Users/hp/Downloads/elite-28/elite-28/track.txt","a") as file:
|
| 32 |
+
file.write(f"{input1}---{date}/{month}/{year}---{hour}:{minutes}:{seconds} \n")
|
| 33 |
+
account_management.start[input1]=[date,month,year,hour,minutes,seconds]
|
| 34 |
+
file.close()
|
| 35 |
+
else:
|
| 36 |
+
print("please check the password")
|
| 37 |
+
else:
|
| 38 |
+
print("user not found")
|
| 39 |
+
|
| 40 |
+
def logout(self):
|
| 41 |
+
input3 = input("please enter the username :")
|
| 42 |
+
for key in account_management.database.keys():
|
| 43 |
+
if input3== key:
|
| 44 |
+
print("Logout successful")
|
| 45 |
+
time.localtime()
|
| 46 |
+
year = time.localtime()[0]
|
| 47 |
+
month = time.localtime()[1]
|
| 48 |
+
date = time.localtime()[2]
|
| 49 |
+
hour = time.localtime()[3]
|
| 50 |
+
minutes = time.localtime()[4]
|
| 51 |
+
seconds = time.localtime()[5]
|
| 52 |
+
with open("C:/Users/hp/Downloads/elite-28/elite-28/track.txt","a") as file:
|
| 53 |
+
file.write(f"{input3}---{date}/{month}/{year}---{hour}:{minutes}:{seconds} \n")
|
| 54 |
+
account_management.stop[input3]=[date,month,year,hour,minutes,seconds]
|
| 55 |
+
file.close()
|
| 56 |
+
for key in account_management.start.keys():
|
| 57 |
+
if input3== key:
|
| 58 |
+
for key in account_management.stop.keys():
|
| 59 |
+
if input3== key:
|
| 60 |
+
print(account_management.start[key][3]-account_management.stop[key][3],":",
|
| 61 |
+
account_management.start[key][4]-account_management.stop[key][4],":",
|
| 62 |
+
account_management.start[key][5]-account_management.stop[key][5])
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
# duration how long the user was using the account
|
run.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from main import account_management
|
| 2 |
+
|
| 3 |
+
innomatics = account_management()
|
| 4 |
+
|
| 5 |
+
conditon1 = True
|
| 6 |
+
|
| 7 |
+
while conditon1:
|
| 8 |
+
print("welcome to user creation section")
|
| 9 |
+
innomatics.create_user()
|
| 10 |
+
print("still want to create users - yes or no")
|
| 11 |
+
user_input1 = input("please enter your choice ")
|
| 12 |
+
if user_input1 == "yes":
|
| 13 |
+
innomatics.create_user()
|
| 14 |
+
else:
|
| 15 |
+
break
|
| 16 |
+
|
| 17 |
+
condition2 = True # flags
|
| 18 |
+
|
| 19 |
+
while condition2:
|
| 20 |
+
print("welcome to login section")
|
| 21 |
+
innomatics.login()
|
| 22 |
+
print("still want to continue - yes or no")
|
| 23 |
+
user_input2 = input("please enter your choice ")
|
| 24 |
+
if user_input2 == "yes":
|
| 25 |
+
innomatics.login()
|
| 26 |
+
else:
|
| 27 |
+
break
|
| 28 |
+
|
| 29 |
+
condition3 = True # flags
|
| 30 |
+
|
| 31 |
+
while condition3:
|
| 32 |
+
print("welcome to logout section")
|
| 33 |
+
innomatics.logout()
|
| 34 |
+
|
| 35 |
+
# create_user,get_database,login,logout
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
session_log.csv
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Username,Login Time,Logout Time,Duration
|
| 2 |
+
kitty,2025-05-05 22:39:35,2025-05-05 22:39:54,0:00:19.032589
|
| 3 |
+
abc,2025-05-05 22:40:33,2025-05-05 22:40:55,0:00:22.393435
|
| 4 |
+
kitty,2025-05-05 22:43:18,2025-05-05 22:43:33,0:00:14.964195
|
| 5 |
+
swetty,2025-05-05 23:10:27,2025-05-05 23:10:56,0:00:28.642088
|
track.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
vara---5/5/2025---13:15:5
|
| 2 |
+
vara---5/5/2025---13:15:10
|
| 3 |
+
vara---5/5/2025---13:18:50
|
| 4 |
+
vara---5/5/2025---13:18:59
|
users.csv
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
username,password
|
| 2 |
+
abc,123
|
| 3 |
+
kitty,abc
|
| 4 |
+
vv,abcswetty,abc
|