Spaces:
Runtime error
Runtime error
| # Import libraries | |
| import os | |
| import streamlit as st | |
| import pandas as pd | |
| import numpy as np | |
| from PIL import Image | |
| from streamlit_extras.switch_page_button import switch_page | |
| from baam_functions import * | |
| from pathlib import Path | |
| # Set parent direction as current folder | |
| sourceFileDir = Path(os.path.dirname(os.path.abspath(__file__))).parent.absolute() | |
| os.chdir(sourceFileDir) | |
| logo = Image.open('img/logo.png') | |
| st.set_page_config(page_title = "BAAM", page_icon = logo) | |
| def main(): | |
| # Get user_dict & location from previous page | |
| user_dict = st.session_state['user_dict'] | |
| location = st.session_state['location'] | |
| score_dict = st.session_state['score_dict'] | |
| risk_threshold = st.session_state['risk_threshold'] | |
| # Get username from user_dict | |
| username = user_dict.get('username', '') | |
| # Header of the page | |
| col1, col2, col3 = st.columns([6,6,2]) | |
| with col1: | |
| st.subheader("Welcome " + username) | |
| with col2: | |
| st.write(' ') | |
| with col3: | |
| st.image("img/Standard_Chartered.png", width=100) | |
| if not(score_dict): | |
| st.write('This is the 1st login time of this username.') | |
| else: | |
| device_score = score_dict.get('device_score', '') | |
| ip_score = score_dict.get('ip_score', '') | |
| location_score = score_dict.get('location_score', '') | |
| jump_score = score_dict.get('jump_score', '') | |
| vpn_score = score_dict.get('vpn_score', '') | |
| total_score = score_dict.get('total_score', '') | |
| # Show history | |
| col = ['login_time','device_name', 'device_uuid','mac_address', 'device_vendor', 'device_model', 'device_ram',\ | |
| 'ip_v4','ip_country', 'ip_region', 'ip_city', 'ip_lat', 'ip_lon', 'isp_name','isp_org',\ | |
| 'is_vpn', 'is_proxy', 'is_tor', 'is_relay', \ | |
| 'lat', 'lon','suburb', 'district', 'city', 'country'] | |
| user_db = pd.DataFrame(get_login_history(username)).T | |
| user_db.columns= col | |
| st.subheader("Historical data: ") | |
| st.write(user_db) | |
| print(user_db) | |
| # Display user's current information on the page | |
| st.subheader("Current login: ") | |
| show_test_data(user_dict, location) | |
| user_db['lat'] = pd.to_numeric(user_db['lat']) | |
| user_db['lon'] = pd.to_numeric(user_db['lon']) | |
| col1, col2 = st.columns([4,6]) | |
| with col1: | |
| st.write('Device score', round(device_score)) | |
| st.write('IP score', round(ip_score)) | |
| st.write('Location score', round(location_score)) | |
| st.write('Jump score', round(jump_score)) | |
| st.write('VPN score', round(vpn_score)) | |
| st.write('----------------------') | |
| st.write('Total score') | |
| st.write('device_score + ip_score + location_score - (jump_score + vpn_score)', round(total_score)) | |
| if total_score > risk_threshold: | |
| st.write('Total score > Risk threshold') | |
| st.image("img/passed_da.png", width=200) | |
| else: | |
| st.write('Total score < Risk threshold') | |
| st.image("img/failed_da.png", width=200) | |
| with col2: | |
| st.map(user_db[['lat', 'lon']]) | |
| if __name__ == '__main__': | |
| main() | |