-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyapp.py
83 lines (62 loc) · 2.04 KB
/
myapp.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
import streamlit as st
import pandas as pd
# To make things easier later, we're also importing numpy and pandas for
# working with sample data.
import numpy as np
import plotly.express as px
# 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():
st.title("DATA VISUALIZATION")
menu = ["Home","Login"]
choice = st.sidebar.selectbox("Menu",menu)
if choice == "Home":
st.subheader("PUBLIC VIEW")
data = px.data.iris()
fig = px.scatter(data, x="sepal_width", y="sepal_length", color="species")
st.plotly_chart(fig)
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"):
# if password == '12345':
create_usertable()
hashed_pswd = make_hashes(password)
result = login_user(username,check_hashes(password,hashed_pswd))
if result:
data = px.data.iris()
fig = px.scatter(data, x="sepal_width", y="sepal_length", color="species")
st.plotly_chart(fig)
df = px.data.tips()
fig2 = px.bar(df, x="sex", y="total_bill", color="smoker", barmode="group")
st.plotly_chart(fig2)
else:
st.warning("Incorrect Username/Password")
if __name__ == '__main__':
main()