adollbo commited on
Commit
4071be5
·
1 Parent(s): a086192

added sidebar w button, configured table

Browse files
Files changed (1) hide show
  1. app.py +62 -10
app.py CHANGED
@@ -1,28 +1,80 @@
1
  import streamlit as st
2
  import pandas as pd
 
 
 
 
3
 
4
- # Mocking the lists
5
- positive_texts = ["Text A", "Text B", "Text C"]
6
- positive_values = [0.8365079365079348, 0.12222222222222279, 0.04603174603174587]
7
 
8
- negative_texts = ["Text X", "Text Y", "Text Z"]
9
- negative_values = [-0.12063492063492065, -0.16349206349206302, -0.053968253968253166]
10
 
11
- # Create a Streamlit app
12
- st.title('Important Variables Analysis')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  # Create a function to generate a table
15
  def create_table(texts, values, title):
16
  df = pd.DataFrame({"Feature Explanation": texts, 'Value': values})
17
  st.markdown(f'### {title}') # Markdown for styling
18
- st.table(df) # Display a simple table
19
 
20
  # Arrange tables horizontally using Streamlit columns
21
  col1, col2 = st.columns(2)
22
 
23
  # Display tables in Streamlit columns
24
  with col1:
25
- create_table(positive_texts, positive_values, 'Important Suspicious Variables')
26
 
27
  with col2:
28
- create_table(negative_texts, negative_values, 'Important Unsuspicious Variables')
 
 
1
  import streamlit as st
2
  import pandas as pd
3
+ import logging
4
+ from deeploy import Client
5
+ from utils import ChangeButtonColour
6
+ from utils import get_input_values, get_texts, feature_texts, example_input, response, first_five_posneg_indices
7
 
8
+ # reset Plotly theme after streamlit import
9
+ import plotly.io as pio
 
10
 
11
+ pio.templates.default = "plotly"
 
12
 
13
+ logging.basicConfig(level=logging.INFO)
14
+
15
+ st.set_page_config(layout="wide")
16
+
17
+ st.title("Observing potential fraudulent transactions")
18
+ st.write(
19
+ "Fill in left hand side and click on button to observe a potential fraudulent transaction"
20
+ )
21
+
22
+ st.divider()
23
+
24
+ def get_model_url():
25
+ model_url = st.text_area(
26
+ "Model URL (without the /explain endpoint, default is the demo deployment)",
27
+ "https://api.app.deeploy.ml/workspaces/708b5808-27af-461a-8ee5-80add68384c7/deployments/dc8c359d-5f61-4107-8b0f-de97ec120289/",
28
+ height=125,
29
+ )
30
+ elems = model_url.split("/")
31
+ try:
32
+ workspace_id = elems[4]
33
+ deployment_id = elems[6]
34
+ except IndexError:
35
+ workspace_id = ""
36
+ deployment_id = ""
37
+ return model_url, workspace_id, deployment_id
38
+
39
+ st.markdown("""
40
+ <style>
41
+ [data-testid=stSidebar] {
42
+ background-color: #E0E0E0; ##E5E6EA
43
+ }
44
+ </style>
45
+ """, unsafe_allow_html=True)
46
+
47
+ with st.sidebar:
48
+ # Add deeploy logo
49
+ st.image("deeploy_logo.png", width=270)
50
+ # Ask for model URL and token
51
+ host = st.text_input("Host (Changing is optional)", "app.deeploy.ml")
52
+ model_url, workspace_id, deployment_id = get_model_url()
53
+ deployment_token = st.text_input("Deeploy Model Token", "my-secret-token")
54
+ if deployment_token == "my-secret-token":
55
+ 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())
56
+
57
+
58
+ ChangeButtonColour("Get suspicious transaction", '#FFFFFF', "#00052D")#'#FFFFFF', "#00052D"
59
+
60
+
61
+ positive_and_negative_indices = first_five_posneg_indices(response)
62
+ positive_texts, negative_texts = get_texts(positive_and_negative_indices, feature_texts)
63
+ positive_vals, negative_vals = get_input_values(positive_and_negative_indices, example_input)
64
 
65
  # Create a function to generate a table
66
  def create_table(texts, values, title):
67
  df = pd.DataFrame({"Feature Explanation": texts, 'Value': values})
68
  st.markdown(f'### {title}') # Markdown for styling
69
+ st.dataframe(df, hide_index=True) # Display a simple table
70
 
71
  # Arrange tables horizontally using Streamlit columns
72
  col1, col2 = st.columns(2)
73
 
74
  # Display tables in Streamlit columns
75
  with col1:
76
+ create_table(positive_texts, positive_vals, 'Important Suspicious Variables')
77
 
78
  with col2:
79
+ create_table(negative_texts, negative_vals, 'Important Unsuspicious Variables')
80
+