Spaces:
Sleeping
Sleeping
Commit
·
1dc25f4
1
Parent(s):
e4d3db3
Update app.py
Browse files
app.py
CHANGED
@@ -63,35 +63,92 @@ If a student asks for reward points, encourage them to engage in the session to
|
|
63 |
import openai
|
64 |
import streamlit as st
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
import openai
|
64 |
import streamlit as st
|
65 |
|
66 |
+
def main():
|
67 |
+
cs_sidebar()
|
68 |
+
cs_body()
|
69 |
+
|
70 |
+
return None
|
71 |
+
|
72 |
+
def cs_body():
|
73 |
+
|
74 |
+
if "openai_model" not in st.session_state:
|
75 |
+
st.session_state["openai_model"] = "gpt-3.5-turbo"
|
76 |
+
|
77 |
+
if "messages" not in st.session_state:
|
78 |
+
st.session_state.messages = []
|
79 |
+
st.session_state.messages.append({"role": "system", "content": context})
|
80 |
+
|
81 |
+
for message in st.session_state.messages:
|
82 |
+
with st.chat_message(message["role"]):
|
83 |
+
st.markdown(message["content"])
|
84 |
+
|
85 |
+
if prompt := st.chat_input("Start talking with your tutor!"):
|
86 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
87 |
+
with st.chat_message("user"):
|
88 |
+
st.markdown(prompt)
|
89 |
+
|
90 |
+
with st.chat_message("assistant"):
|
91 |
+
message_placeholder = st.empty()
|
92 |
+
full_response = ""
|
93 |
+
for response in openai.ChatCompletion.create(
|
94 |
+
model=st.session_state["openai_model"],
|
95 |
+
messages=[
|
96 |
+
{"role": m["role"], "content": m["content"]}
|
97 |
+
for m in st.session_state.messages
|
98 |
+
],
|
99 |
+
stream=True,
|
100 |
+
):
|
101 |
+
full_response += response.choices[0].delta.get("content", "")
|
102 |
+
message_placeholder.markdown(full_response + "▌")
|
103 |
+
message_placeholder.markdown(full_response)
|
104 |
+
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
105 |
+
|
106 |
+
return None
|
107 |
+
|
108 |
+
def cs_sidebar():
|
109 |
+
st.sidebar.markdown('''[<img src='data:image/png;base64,{}' class='img-fluid' width=32 height=32>](https://streamlit.io/)'''.format(img_to_bytes("logomark_website.png")), unsafe_allow_html=True)
|
110 |
+
st.sidebar.header('Streamlit cheat sheet')
|
111 |
+
|
112 |
+
st.sidebar.markdown('''
|
113 |
+
<small>Summary of the [docs](https://docs.streamlit.io/en/stable/api.html), as of [Streamlit v1.8.0](https://www.streamlit.io/).</small>
|
114 |
+
''', unsafe_allow_html=True)
|
115 |
+
|
116 |
+
st.sidebar.markdown('__How to install and import__')
|
117 |
+
|
118 |
+
st.sidebar.code('$ pip install streamlit')
|
119 |
+
|
120 |
+
st.sidebar.markdown('Import convention')
|
121 |
+
st.sidebar.code('>>> import streamlit as st')
|
122 |
+
|
123 |
+
st.sidebar.markdown('__Add widgets to sidebar__')
|
124 |
+
st.sidebar.code('''
|
125 |
+
st.sidebar.<widget>
|
126 |
+
>>> a = st.sidebar.radio(\'R:\',[1,2])
|
127 |
+
''')
|
128 |
+
|
129 |
+
st.sidebar.markdown('__Command line__')
|
130 |
+
st.sidebar.code('''
|
131 |
+
$ streamlit --help
|
132 |
+
$ streamlit run your_script.py
|
133 |
+
$ streamlit hello
|
134 |
+
$ streamlit config show
|
135 |
+
$ streamlit cache clear
|
136 |
+
$ streamlit docs
|
137 |
+
$ streamlit --version
|
138 |
+
''')
|
139 |
+
|
140 |
+
st.sidebar.markdown('__Pre-release features__')
|
141 |
+
st.sidebar.markdown('[Beta and experimental features](https://docs.streamlit.io/library/advanced-features/prerelease#beta-and-experimental-features)')
|
142 |
+
st.sidebar.code('''
|
143 |
+
pip uninstall streamlit
|
144 |
+
pip install streamlit-nightly --upgrade
|
145 |
+
''')
|
146 |
+
|
147 |
+
st.sidebar.markdown('''<small>[st.cheat_sheet v1.8.0](https://github.com/daniellewisDL/streamlit-cheat-sheet) | April 2022</small>''', unsafe_allow_html=True)
|
148 |
+
|
149 |
+
return None
|
150 |
+
|
151 |
+
# Run main()
|
152 |
+
|
153 |
+
if __name__ == '__main__':
|
154 |
+
main()
|