-
Notifications
You must be signed in to change notification settings - Fork 0
/
g2.py
149 lines (115 loc) · 4.86 KB
/
g2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import streamlit as st
import pandas as pd
import pickle
page_bg_img = '''
<style>
.stApp {
background-image: url("https://cdn.pixabay.com/photo/2019/11/11/10/05/law-4617873_1280.jpg");
background-size: cover;
}
</style>
'''
st.markdown(page_bg_img, unsafe_allow_html=True)
# Security
#passlib,hashlib,bcrypt,scrypt
import hashlib
def make_hashes(password):
return hashlib.sha256(str.encode(password)).hexdigest()
def check_hashes(password,hashed_text):
if make_hashes(password) == hashed_text:
return hashed_text
return False
# DB Management
import sqlite3
conn = sqlite3.connect('data.db')
c = conn.cursor()
# DB Functions
def create_usertable():
c.execute('CREATE TABLE IF NOT EXISTS userstable(username TEXT,password TEXT)')
def add_userdata(username,password):
c.execute('INSERT INTO userstable(username,password) VALUES (?,?)',(username,password))
conn.commit()
def login_user(username,password):
c.execute('SELECT * FROM userstable WHERE username =? AND password = ?',(username,password))
data = c.fetchall()
return data
def view_all_users():
c.execute('SELECT * FROM userstable')
data = c.fetchall()
return data
def main():
"""Justice Through AI"""
st.title("Justice Through AI")
menu = ["Home","Login","SignUp"]
choice = st.sidebar.selectbox("Menu",menu)
if choice == "Home":
st.subheader("Home")
elif choice == "Login":
st.subheader("Login Section")
username = st.sidebar.text_input("User Name")
password = st.sidebar.text_input("Password",type='password')
if st.sidebar.checkbox("Login"):
create_usertable()
hashed_pswd = make_hashes(password)
result = login_user(username,check_hashes(password,hashed_pswd))
if result:
st.success("Logged In as {}".format(username))
task = st.selectbox("Task",["Recommend","Analytics","Profiles"])
if task == "Recommend":
st.subheader("Get Article Recommendation")
article_dict=pickle.load(open("article_dict.pkl","rb"))
articles=pd.DataFrame(article_dict)
st.title("Article Recommender System")
select_article_heading= st.selectbox(
'Heading Of The Article!',
articles["heading"].values)
similarity=pickle.load(open("similarity.pkl","rb"))
def recommend(article):
article_index=articles[articles["heading"]==article].index[0]
distances=similarity[article_index]
article_list=sorted(list(enumerate(distances)),reverse=True,key=lambda x:x[1])[1:6]
recommended_articles=[]
for i in article_list:
recommended_articles.append(articles.iloc[i[0]].heading)
recommended_articles.append(articles.iloc[i[0]].article_link)
return recommended_articles
if st.button("Recommend"):
recommendations=recommend(select_article_heading)
for i in recommendations:
st.write(i)
elif task == "Analytics":
st.subheader("Analytics")
elif task == "Profiles":
st.subheader("User Profiles")
user_result = view_all_users()
clean_db = pd.DataFrame(user_result,columns=["Username","Password"])
st.dataframe(clean_db)
else:
st.warning("Incorrect Username/Password")
elif choice == "SignUp":
st.subheader("Create New Account")
new_user = st.text_input("Username")
new_password = st.text_input("Password",type='password')
if st.button("Signup"):
create_usertable()
add_userdata(new_user,make_hashes(new_password))
st.success("You have successfully created a valid Account")
st.info("Go to Login Menu to login")
# # elif task == "Analytics":
# # st.subheader("Analytics")
# elif task == "Profiles":
# st.subheader("User Profiles")
# user_result = view_all_users()
# clean_db = pd.DataFrame(user_result,columns=["Username","Password"])
# st.dataframe(clean_db)
# else:
# st.warning("Incorrect Username/Password")
# elif choice == "SignUp":
# st.subheader("Create New Account")
# new_user = st.text_input("Username")
# new_password = st.text_input("Password",type='password')
# if st.button("Signup"):
# create_usertable()
# add_userdata(new_user,make_hashes(new_password))
# st.success("You have successfully created a valid Account")
# st.info("Go to Login Menu to login")