-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreamlit_app.py
86 lines (66 loc) · 2.4 KB
/
streamlit_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
import streamlit as st
import numpy as np
from snowflake.snowpark.context import get_active_session
from snowflake.cortex import Complete
import pandas as pd
st.set_page_config(layout="wide")
def is_local() -> bool:
"""
Check if app is running locally, by checking if the user email is a local one.
Returns:
bool: True if running locally, else (if in SiS) False.
"""
return st.experimental_user.email in {"[email protected]", "[email protected]"}
@st.cache_data
def generate_fake_data_for_demo(seed=36) -> pd.DataFrame:
"""
Generates a dataframe of customers and views for
this demo, and caches it. If you are using this demo,
you ideally will replace this with your own data.
"""
df = pd.DataFrame(
{
"date": pd.date_range(start="1/1/2020", periods=100),
"customers": np.random.randint(100, 1000, 100),
}
)
df["customers"] = df["customers"].cumsum()
np.random.seed(seed)
df["views"] = np.random.randint(100, 1000, 100)
df["views"] = df["views"] * np.log(df.index) * np.random.uniform(1, 1.6, 100)
df["views"][0] = 0
return df
st.title(f"❄️ Streamlit in Snowflake Key Metrics (dummy data) ❄️")
st.sidebar.image(
"https://upload.wikimedia.org/wikipedia/commons/f/ff/Snowflake_Logo.svg"
)
if is_local():
conn = st.connection("snowflake")
session = conn.session()
else:
session = get_active_session()
df = generate_fake_data_for_demo()
col1, col2 = st.columns(2)
with col1:
st.subheader("Number of customers")
taba, tabb = st.tabs(["Chart", "Data"])
taba.line_chart(df.set_index("date")["customers"])
tabb.write(df)
with col2:
st.subheader("Views per day")
tabc, tabd = st.tabs(["Chart", "Data"])
tabc.line_chart(df.set_index("date")["views"])
tabd.write(df)
df["views_per_customer"] = df["views"] / df["customers"]
st.subheader("Views per customer")
st.line_chart(df.set_index("date")["views_per_customer"])
prompt = """
Please summarize the following feedback comments
in markdown from our streamlit in snowflake users,
just give the top 3 good things and 3 improvement areas about the product: '
"""
df_feedback = session.sql("select * from streamlit.public.feedback_table").to_pandas()
prompt += "\n\n".join(df_feedback["FEEDBACK"])
st.subheader("User Feedback")
response = Complete(model="mistral-large", prompt=prompt, session=session)
st.write(response)