import streamlit as st import pandas as pd import logging from deeploy import Client from utils import ChangeButtonColour from utils import get_input_values, get_texts, feature_texts, example_input, response, first_five_posneg_indices # reset Plotly theme after streamlit import import plotly.io as pio pio.templates.default = "plotly" logging.basicConfig(level=logging.INFO) st.set_page_config(layout="wide") st.title("Observing potential fraudulent transactions") st.write( "Fill in left hand side and click on button to observe a potential fraudulent transaction" ) st.divider() def get_model_url(): model_url = st.text_area( "Model URL (without the /explain endpoint, default is the demo deployment)", "https://api.app.deeploy.ml/workspaces/708b5808-27af-461a-8ee5-80add68384c7/deployments/dc8c359d-5f61-4107-8b0f-de97ec120289/", height=125, ) elems = model_url.split("/") try: workspace_id = elems[4] deployment_id = elems[6] except IndexError: workspace_id = "" deployment_id = "" return model_url, workspace_id, deployment_id st.markdown(""" """, unsafe_allow_html=True) with st.sidebar: # Add deeploy logo st.image("deeploy_logo.png", width=270) # Ask for model URL and token host = st.text_input("Host (Changing is optional)", "app.deeploy.ml") model_url, workspace_id, deployment_id = get_model_url() deployment_token = st.text_input("Deeploy Model Token", "my-secret-token") if deployment_token == "my-secret-token": button_clicked = st.button("Get suspicious transaction", key="get1", help="Click to get a suspicious transaction", use_container_width=True, on_click=lambda: st.experimental_rerun()) ChangeButtonColour("Get suspicious transaction", '#FFFFFF', "#00052D")#'#FFFFFF', "#00052D" positive_and_negative_indices = first_five_posneg_indices(response) positive_texts, negative_texts = get_texts(positive_and_negative_indices, feature_texts) positive_vals, negative_vals = get_input_values(positive_and_negative_indices, example_input) # Create a function to generate a table def create_table(texts, values, title): df = pd.DataFrame({"Feature Explanation": texts, 'Value': values}) st.markdown(f'### {title}') # Markdown for styling st.dataframe(df, hide_index=True) # Display a simple table # Arrange tables horizontally using Streamlit columns col1, col2 = st.columns(2) # Display tables in Streamlit columns with col1: create_table(positive_texts, positive_vals, 'Important Suspicious Variables') with col2: create_table(negative_texts, negative_vals, 'Important Unsuspicious Variables')