File size: 1,845 Bytes
a645df8
 
0cca41e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a645df8
 
 
 
 
0cca41e
aa90afd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st

import wandb


def initialize_session_state():
    if "weave_project_name" not in st.session_state:
        st.session_state.weave_project_name = "guardrails-genie"
    if "weave_entity_name" not in st.session_state:
        st.session_state.weave_entity_name = ""
    if "wandb_api_key" not in st.session_state:
        st.session_state.wandb_api_key = ""
    if "authenticate_button" not in st.session_state:
        st.session_state.authenticate_button = False
    if "is_authenticated" not in st.session_state:
        st.session_state.is_authenticated = False


initialize_session_state()
st.title("πŸ§žβ€β™‚οΈ Guardrails Genie")

st.write(
    "Guardrails-Genie is a tool that helps you implement guardrails in your LLM applications."
)

st.sidebar.markdown(
    "Get your Wandb API key from [https://wandb.ai/authorize](https://wandb.ai/authorize)"
)
weave_entity_name = st.sidebar.text_input(
    "Weave Entity Name", value=st.session_state.weave_entity_name
)
st.session_state.weave_entity_name = weave_entity_name
weave_project_name = st.sidebar.text_input(
    "Weave Project Name", value=st.session_state.weave_project_name
)
st.session_state.weave_project_name = weave_project_name
wandb_api_key = st.sidebar.text_input("Wandb API Key", value="", type="password")
st.session_state.wandb_api_key = wandb_api_key
authenticate_button = st.sidebar.button("Authenticate")
st.session_state.authenticate_button = authenticate_button

if authenticate_button and (
    st.session_state.wandb_api_key != "" and st.session_state.weave_project_name != ""
):
    is_wandb_logged_in = wandb.login(key=st.session_state.wandb_api_key, relogin=True)
    if is_wandb_logged_in:
        st.session_state.is_authenticated = True
        st.success("Logged in to Wandb")
    else:
        st.error("Failed to log in to Wandb")