forked from Snowflake-Labs/semantic-model-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
119 lines (101 loc) · 4.01 KB
/
app.py
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import streamlit as st
from snowflake.connector import DatabaseError
from snowflake.connector.connection import SnowflakeConnection
# set_page_config must be run as the first Streamlit command on the page, before any other streamlit imports.
st.set_page_config(layout="wide", page_icon="💬", page_title="Semantic Model Generator")
from app_utils.shared_utils import ( # noqa: E402
GeneratorAppScreen,
get_snowflake_connection,
set_sit_query_tag,
set_account_name,
set_host_name,
set_user_name,
set_streamlit_location,
set_snowpark_session,
)
from semantic_model_generator.snowflake_utils.env_vars import ( # noqa: E402
SNOWFLAKE_ACCOUNT_LOCATOR,
SNOWFLAKE_HOST,
SNOWFLAKE_USER,
)
@st.experimental_dialog(title="Connection Error")
def failed_connection_popup() -> None:
"""
Renders a dialog box detailing that the credentials provided could not be used to connect to Snowflake.
"""
st.markdown(
f"""It looks like the credentials provided could not be used to connect to the account."""
)
st.stop()
def verify_environment_setup() -> SnowflakeConnection:
"""
Ensures that the correct environment variables are set before proceeding.
"""
# Instantiate the Snowflake connection that gets reused throughout the app.
try:
with st.spinner(
"Validating your connection to Snowflake. If you are using MFA, please check your authenticator app for a push notification."
):
return get_snowflake_connection()
except DatabaseError:
failed_connection_popup()
if __name__ == "__main__":
from journeys import builder, iteration, partner
st.session_state["sis"] = set_streamlit_location()
def onboarding_dialog() -> None:
"""
Renders the initial screen where users can choose to create a new semantic model or edit an existing one.
"""
# Direct to specific page based instead of default onboarding if user comes from successful partner setup
st.markdown(
"""
<div style="text-align: center;">
<h1>Welcome to the Snowflake Semantic Model Generator! ❄️</h1>
<p>Let's get started. What would you like to do?</p>
</div>
""",
unsafe_allow_html=True,
)
st.markdown("<div style='margin: 60px;'></div>", unsafe_allow_html=True)
_, center, _ = st.columns([1, 2, 1])
with center:
if st.button(
"**🛠 Create a new semantic model**",
use_container_width=True,
type="primary",
):
builder.show()
st.markdown("")
if st.button(
"**✏️ Edit an existing semantic model**",
use_container_width=True,
type="primary",
):
iteration.show()
st.markdown("")
if st.button(
"**:package: Start with partner semantic model**",
use_container_width=True,
type="primary",
):
set_sit_query_tag(
get_snowflake_connection(),
vendor="",
action="start",
)
partner.show()
conn = verify_environment_setup()
set_snowpark_session(conn)
# Populating common state between builder and iteration apps.
set_account_name(conn, SNOWFLAKE_ACCOUNT_LOCATOR)
set_host_name(conn, SNOWFLAKE_HOST)
set_user_name(conn, SNOWFLAKE_USER)
# When the app first loads, show the onboarding screen.
if "page" not in st.session_state:
st.session_state["page"] = GeneratorAppScreen.ONBOARDING
# Depending on the page state, we either show the onboarding menu or the chat app flow.
# The builder flow is simply an intermediate dialog before the iteration flow.
if st.session_state["page"] == GeneratorAppScreen.ITERATION:
iteration.show()
else:
onboarding_dialog()