File size: 3,572 Bytes
3e7a501
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# source .venv/bin/activate
# streamlit run <>.py

import streamlit as st
import app_utils as util
from pathlib import Path
from PIL import Image
from io import BytesIO
import requests
import time

st.set_page_config(page_title="SAnDL", page_icon="🩴", layout="wide", initial_sidebar_state="collapsed")

# Example URL
image_url = "https://media.discordapp.net/attachments/1013678935231442944/1175575324210249740/sandll2.png?ex=656bbad6&is=655945d6&hm=d8f4a93a7c3ae90978f820093e2e7c17c18b6125546255afaaeca8ed6716bd4d&=&width=2268&height=486"

# Open image from URL
response = requests.get(image_url)
img = Image.open(BytesIO(response.content))

# close taskbar, page margin, ...
st.markdown("""
<style>
    .st-emotion-cache-1yeub2j {
      display: none;
    }
    .st-emotion-cache-79elbk {
      margin-top: -45px;
    }
    .slogan-font {
      font-size:18px !important;
      margin-bottom: 40px;
      margin-top: 0px;
      text-align: center;
    }
    .bolded {
      font-weight: 1000;   
    }
    [data-testid="stSidebarNav"] {
      background-image: url(https://media.discordapp.net/attachments/1013678935231442944/1175577023574454402/sandlsmall_2.png?ex=656bbc6b&is=6559476b&hm=c920463c2062c3c42e555224fb0dc0afc5188e9451b45c9eb62c64f297c1a1f1&=&width=596&height=127);
      background-repeat: no-repeat;
      margin-top: 20px;
      background-position: 20px 20px;
    }
    section[data-testid="stSidebar"][aria-expanded="true"]{
      display: none;
    }
</style>
""", unsafe_allow_html=True)

logincol1, logincol2, logincol3 = st.columns([1, 8, 1])

with logincol2:
    
    # logo
    st.image(img)
    # caption
    st.markdown('<p class="slogan-font">' + "Developing <span class = \"bolded\">anomaly detection</span> systems for filtration of <span class = \"bolded\">large language model</span> prompts." + '</p>', unsafe_allow_html=True)

    #login form
    profilecontainer = st.container()
    login_form = profilecontainer.form('Login')
    username = login_form.text_input('Username').lower()
    st.session_state['username'] = username
    password = login_form.text_input('Password', type='password')
    if login_form.form_submit_button('Login'):
        st.session_state.pop('FormSubmitter:Login-Login', None)

        # deletes all keys from previous logins
        for key in st.session_state.keys():
            if (key != 'username'):
                st.session_state.pop(key)

        res = requests.post("https://sandl-backend-ny3lmzb4dq-uc.a.run.app/login", json={"email": username, "password": password})
        error = res.status_code

        # login validation
        if error == 200:
          st.session_state['userdata'] = res.json()["jwt"]
          st.success('Login Successful!', icon="✅")
          util.switch_page("query")
        # username exists in db, but password is incorrect
        elif error == 400:
          st.error('Incorrect Password.', icon="🚨")
        # makes new account
        elif error == 500: 
          st.info('Account Not Found: New account created.', icon="ℹ️")
          res = requests.post("https://sandl-backend-ny3lmzb4dq-uc.a.run.app/sign_up", json={"email": username, "password": password})
          res = requests.post("https://sandl-backend-ny3lmzb4dq-uc.a.run.app/login", json={"email": username, "password": password})
          st.session_state['userdata'] = res.json()["jwt"]
          requests.post("https://sandl-backend-ny3lmzb4dq-uc.a.run.app/add_api_key", json={"jwt": st.session_state['userdata']})
          time.sleep(.5)
          util.switch_page("query")