| 1 | + | import streamlit as st |
| 2 | + | import pandas as pd |
| 3 | + | from streamlit_agraph import agraph, Config |
| 4 | + | from utils import build_agraph_components, get_edges_df, get_subgraph_df, get_nodes_df |
| 5 | + | |
| 6 | + | |
| 7 | + | st.set_page_config(layout="wide") |
| 8 | + | |
| 9 | + | |
| 10 | + | SLIDER_MIN = 1 |
| 11 | + | SLIDER_MAX = 100 |
| 12 | + | SLIDER_DEFAULT = 50 |
| 13 | + | |
| 14 | + | nodes = get_nodes_df() |
| 15 | + | edges = get_edges_df() |
| 16 | + | subgraphs = get_subgraph_df() |
| 17 | + | |
| 18 | + | with st.sidebar: |
| 19 | + | st.title("Corporate risks") |
| 20 | + | |
| 21 | + | weight_chains = st.slider( |
| 22 | + | "Long ownership chains", |
| 23 | + | min_value=SLIDER_MIN, |
| 24 | + | max_value=SLIDER_MAX, |
| 25 | + | value=SLIDER_DEFAULT, |
| 26 | + | ) |
| 27 | + | weight_cyclic = st.slider( |
| 28 | + | "Cyclic ownership", |
| 29 | + | min_value=SLIDER_MIN, |
| 30 | + | max_value=SLIDER_MAX, |
| 31 | + | value=SLIDER_DEFAULT, |
| 32 | + | ) |
| 33 | + | weight_psc_haven = st.slider( |
| 34 | + | "Persons of significant control associated with tax havens", |
| 35 | + | min_value=SLIDER_MIN, |
| 36 | + | max_value=SLIDER_MAX, |
| 37 | + | value=SLIDER_DEFAULT, |
| 38 | + | ) |
| 39 | + | weight_pep = st.slider( |
| 40 | + | "Officers/PSCs are politically exposed", |
| 41 | + | min_value=SLIDER_MIN, |
| 42 | + | max_value=SLIDER_MAX, |
| 43 | + | value=SLIDER_DEFAULT, |
| 44 | + | ) |
| 45 | + | weight_sanctions = st.slider( |
| 46 | + | "Officers/PSCs/Companies are sanctioned", |
| 47 | + | min_value=SLIDER_MIN, |
| 48 | + | max_value=SLIDER_MAX, |
| 49 | + | value=SLIDER_DEFAULT, |
| 50 | + | ) |
| 51 | + | weight_disqualified = st.slider( |
| 52 | + | "Officers are disqualified directors", |
| 53 | + | min_value=SLIDER_MIN, |
| 54 | + | max_value=SLIDER_MAX, |
| 55 | + | value=SLIDER_DEFAULT, |
| 56 | + | ) |
| 57 | + | |
| 58 | + | custom_names_a = st.multiselect( |
| 59 | + | label="Custom persons of interest", |
| 60 | + | options=nodes["node_id"], |
| 61 | + | default=None, |
| 62 | + | ) |
| 63 | + | custom_names_b = st.file_uploader(label="Custom persons of interest", type="csv") |
| 64 | + | |
| 65 | + | go = st.button("Go") |
| 66 | + | |
| 67 | + | |
| 68 | + | with st.container(): |
| 69 | + | st.write(subgraphs) |
| 70 | + | |
| 71 | + | selected_subgraph_hash = st.selectbox( |
| 72 | + | label="Select subgraph to explore", options=subgraphs.index |
| 73 | + | ) |
| 74 | + | |
| 75 | + | nodes_selected = nodes.loc[nodes["subgraph_hash"] == selected_subgraph_hash] |
| 76 | + | edges_selected = edges.loc[edges["subgraph_hash"] == selected_subgraph_hash] |
| 77 | + | |
| 78 | + | with st.container(): |
| 79 | + | |
| 80 | + | col1, col2 = st.columns(2) |
| 81 | + | |
| 82 | + | with col1: |
| 83 | + | (node_objects, edge_objects) = build_agraph_components( |
| 84 | + | nodes_selected, edges_selected |
| 85 | + | ) |
| 86 | + | agraph( |
| 87 | + | nodes=node_objects, |
| 88 | + | edges=edge_objects, |
| 89 | + | config=Config( |
| 90 | + | width=500, |
| 91 | + | height=500, |
| 92 | + | ), |
| 93 | + | ) |
| 94 | + | |
| 95 | + | with col2: |
| 96 | + | st.write(nodes_selected) |
| 97 | + | |