-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathstreamlit_demo.py
84 lines (55 loc) · 2.21 KB
/
streamlit_demo.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
"""Streamlit 101.
Docs:
- https://docs.streamlit.io/library/get-started
- https://docs.streamlit.io/library/api-reference/session-state
- https://discuss.streamlit.io/t/new-component-streamlit-chat-a-new-way-to-create-chatbots/20412
Examples:
$ streamlit hello
$ streamlit run chatefficient/streamlit_demo.py
Visit https://YOUR-CUSTOM-URL.sagemaker.aws/proxy/{YOUR-PROXY-HERE}/
e.g. https://obt-workshop.notebook.eu-west-2.sagemaker.aws/proxy/8501/
"""
import pandas as pd
import streamlit as st
df = pd.DataFrame({"first column": [1, 2, 3, 4], "second column": [10, 20, 30, 40]})
# ######### Part 1: st.write() #########
# st.write(df)
######### Part 2: Magic Commands #########
# df
######### Part 3: Plotting Charts #########
# import numpy as np
# chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])
# st.line_chart(chart_data)
######### Part 4: Maps #########
# old_street = [51.525, -0.088]
# map_data = pd.DataFrame(
# np.random.randn(50, 2) / [150, 150] + old_street,
# columns=["lat", "lon"]
# )
# st.map(map_data)
######### Part 5: Widgets #########
# x = st.slider("x") # 👈 this is a widget
# st.write(x, "squared is", x * x)
# df = pd.DataFrame({"first column": [1, 2, 3, 4], "second column": [10, 20, 30, 40]})
# option = st.selectbox("Which number do you like best?", df["first column"])
# st.write("You selected: ", option)
######### Part 6: Sidebar #########
# # Add a selectbox to the sidebar:
# add_selectbox = st.sidebar.selectbox(
# "How would you like to be contacted?",
# ("Email", "Home phone", "Mobile phone"),
# )
# # Add a slider to the sidebar:
# add_slider = st.sidebar.slider("Select a range of values", 0.0, 100.0, (25.0, 75.0))
######### Part 7: Session State #########
# # Initialization
# if "name" not in st.session_state:
# st.session_state["name"] = "DEFAULT NAME"
# st.sidebar.text_input("Your name", key="name")
# # You can access the value at any point with:
# st.session_state.name
######### Part 8: Streamlit Chat #########
st.chat_message("ai").write("Hello human 👋")
st.chat_message("human").write("Hey there bot!") # user input
st.chat_message("ai").write("I hope your talk is going OK?")
st.chat_message("human").write("Me too!")