Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Changing Draft Demo to Chat Demo running on GPT 3.5
Browse files
pages/{7_βοΈ_Draft_Demo.py β 7_π¬οΈ_Chat_Demo.py}
RENAMED
@@ -3,6 +3,7 @@ import os
|
|
3 |
import streamlit as st
|
4 |
import streamlit_analytics
|
5 |
from utils import add_logo_to_sidebar, add_footer, add_email_signup_form
|
|
|
6 |
|
7 |
streamlit_analytics.start_tracking()
|
8 |
|
@@ -21,11 +22,39 @@ st.set_page_config(
|
|
21 |
add_logo_to_sidebar()
|
22 |
st.sidebar.success("π Select a demo above.")
|
23 |
|
24 |
-
st.title('
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
streamlit_analytics.stop_tracking(unsafe_password=os.environ["ANALYTICS_PASSWORD"])
|
|
|
3 |
import streamlit as st
|
4 |
import streamlit_analytics
|
5 |
from utils import add_logo_to_sidebar, add_footer, add_email_signup_form
|
6 |
+
from openai import OpenAI
|
7 |
|
8 |
streamlit_analytics.start_tracking()
|
9 |
|
|
|
22 |
add_logo_to_sidebar()
|
23 |
st.sidebar.success("π Select a demo above.")
|
24 |
|
25 |
+
st.title('π¬ Chat Demo')
|
26 |
+
|
27 |
+
client = OpenAI(api_key=st.secrets["OPENAI_API_KEY"], organization=st.secrets["OPENAI_ORG"])
|
28 |
+
|
29 |
+
if "openai_model" not in st.session_state:
|
30 |
+
st.session_state["openai_model"] = "gpt-3.5-turbo"
|
31 |
+
|
32 |
+
if "messages" not in st.session_state:
|
33 |
+
st.session_state.messages = []
|
34 |
+
|
35 |
+
for message in st.session_state.messages:
|
36 |
+
with st.chat_message(message["role"]):
|
37 |
+
st.markdown(message["content"])
|
38 |
+
|
39 |
+
if prompt := st.chat_input("What is up?"):
|
40 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
41 |
+
with st.chat_message("user"):
|
42 |
+
st.markdown(prompt)
|
43 |
+
|
44 |
+
with st.chat_message("assistant"):
|
45 |
+
message_placeholder = st.empty()
|
46 |
+
full_response = ""
|
47 |
+
for response in client.chat.completions.create(
|
48 |
+
model=st.session_state["openai_model"],
|
49 |
+
messages=[
|
50 |
+
{"role": m["role"], "content": m["content"]}
|
51 |
+
for m in st.session_state.messages
|
52 |
+
],
|
53 |
+
stream=True,
|
54 |
+
):
|
55 |
+
full_response += (response.choices[0].delta.content or "")
|
56 |
+
message_placeholder.markdown(full_response + "β")
|
57 |
+
message_placeholder.markdown(full_response)
|
58 |
+
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
59 |
|
60 |
streamlit_analytics.stop_tracking(unsafe_password=os.environ["ANALYTICS_PASSWORD"])
|
requirements.txt
CHANGED
@@ -27,6 +27,7 @@ mdurl==0.1.2
|
|
27 |
nltk==3.8.1
|
28 |
numba==0.56.4
|
29 |
numpy==1.23.5
|
|
|
30 |
packaging==23.0
|
31 |
pandas==1.5.3
|
32 |
Pillow==9.4.0
|
@@ -51,7 +52,7 @@ six==1.16.0
|
|
51 |
spacy==3.7.2
|
52 |
https://huggingface.co/spacy/en_core_web_md/resolve/main/en_core_web_md-any-py3-none-any.whl
|
53 |
smmap==5.0.0
|
54 |
-
streamlit==1.
|
55 |
streamlit-analytics==0.4.1
|
56 |
streamlit-toggle-switch==1.0.2
|
57 |
threadpoolctl==3.1.0
|
|
|
27 |
nltk==3.8.1
|
28 |
numba==0.56.4
|
29 |
numpy==1.23.5
|
30 |
+
openai
|
31 |
packaging==23.0
|
32 |
pandas==1.5.3
|
33 |
Pillow==9.4.0
|
|
|
52 |
spacy==3.7.2
|
53 |
https://huggingface.co/spacy/en_core_web_md/resolve/main/en_core_web_md-any-py3-none-any.whl
|
54 |
smmap==5.0.0
|
55 |
+
streamlit==1.29.0
|
56 |
streamlit-analytics==0.4.1
|
57 |
streamlit-toggle-switch==1.0.2
|
58 |
threadpoolctl==3.1.0
|
π‘_Home.py
CHANGED
@@ -38,7 +38,7 @@ st.markdown(
|
|
38 |
- π **Compare** - Using AI to **compare** passages of text
|
39 |
- π **Organise** - Using AI to **organise** a collection of texts
|
40 |
- π **Find** - Using AI to **find** relevant information from a collection of texts
|
41 |
-
-
|
42 |
- π **Summarise** - Using AI to **summarise** text
|
43 |
""")
|
44 |
|
|
|
38 |
- π **Compare** - Using AI to **compare** passages of text
|
39 |
- π **Organise** - Using AI to **organise** a collection of texts
|
40 |
- π **Find** - Using AI to **find** relevant information from a collection of texts
|
41 |
+
- π¬ **Chat** - Using AI to **chat**
|
42 |
- π **Summarise** - Using AI to **summarise** text
|
43 |
""")
|
44 |
|