Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,14 @@ import os
|
|
| 11 |
import sys
|
| 12 |
import pandas as pd
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
user_api_key = st.sidebar.text_input(
|
| 15 |
label="#### Your OpenAI API key π",
|
| 16 |
placeholder="Paste your openAI API key, sk-",
|
|
@@ -34,41 +42,35 @@ if user_api_key is not None:
|
|
| 34 |
llm = ChatOpenAI(temperature=0.0,model_name='gpt-3.5-turbo'),
|
| 35 |
retriever=vectorstore.as_retriever())
|
| 36 |
|
| 37 |
-
def conversational_chat(query):
|
| 38 |
-
result = chain({"question": query,
|
| 39 |
-
"chat_history": st.session_state['history']})
|
| 40 |
-
st.session_state['history'].append((query, result["answer"]))
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
if 'history' not in st.session_state:
|
| 45 |
-
st.session_state['history'] = []
|
| 46 |
-
|
| 47 |
-
if 'generated' not in st.session_state:
|
| 48 |
-
st.session_state['generated'] = ["Hello ! Ask me anything about " + " π€"]
|
| 49 |
-
|
| 50 |
-
if 'past' not in st.session_state:
|
| 51 |
-
st.session_state['past'] = ["Hey ! π"]
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
with container:
|
| 59 |
-
with st.form(key='my_form', clear_on_submit=True):
|
| 60 |
-
|
| 61 |
-
user_input = st.text_input("Query:", placeholder="Talk about your csv data here (:", key='input')
|
| 62 |
-
submit_button = st.form_submit_button(label='Send')
|
| 63 |
-
|
| 64 |
-
if submit_button and user_input:
|
| 65 |
-
output = conversational_chat(user_input)
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
import sys
|
| 12 |
import pandas as pd
|
| 13 |
|
| 14 |
+
def conversational_chat(query):
|
| 15 |
+
result = chain({"question": query,
|
| 16 |
+
"chat_history": st.session_state['history']})
|
| 17 |
+
st.session_state['history'].append((query, result["answer"]))
|
| 18 |
+
|
| 19 |
+
return result["answer"]
|
| 20 |
+
|
| 21 |
+
|
| 22 |
user_api_key = st.sidebar.text_input(
|
| 23 |
label="#### Your OpenAI API key π",
|
| 24 |
placeholder="Paste your openAI API key, sk-",
|
|
|
|
| 42 |
llm = ChatOpenAI(temperature=0.0,model_name='gpt-3.5-turbo'),
|
| 43 |
retriever=vectorstore.as_retriever())
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
if 'history' not in st.session_state:
|
| 47 |
+
st.session_state['history'] = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
if 'generated' not in st.session_state:
|
| 50 |
+
st.session_state['generated'] = ["Hello ! Ask me anything about " + " π€"]
|
| 51 |
+
|
| 52 |
+
if 'past' not in st.session_state:
|
| 53 |
+
st.session_state['past'] = ["Hey ! π"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
#container for the chat history
|
| 56 |
+
response_container = st.container()
|
| 57 |
+
#container for the user's text input
|
| 58 |
+
container = st.container()
|
| 59 |
+
|
| 60 |
+
with container:
|
| 61 |
+
with st.form(key='my_form', clear_on_submit=True):
|
| 62 |
+
|
| 63 |
+
user_input = st.text_input("Query:", placeholder="Talk about your csv data here (:", key='input')
|
| 64 |
+
submit_button = st.form_submit_button(label='Send')
|
| 65 |
+
|
| 66 |
+
if submit_button and user_input:
|
| 67 |
+
output = conversational_chat(user_input)
|
| 68 |
+
|
| 69 |
+
st.session_state['past'].append(user_input)
|
| 70 |
+
st.session_state['generated'].append(output)
|
| 71 |
+
|
| 72 |
+
if st.session_state['generated']:
|
| 73 |
+
with response_container:
|
| 74 |
+
for i in range(len(st.session_state['generated'])):
|
| 75 |
+
message(st.session_state["past"][i], is_user=True, key=str(i) + '_user', avatar_style="big-smile")
|
| 76 |
+
message(st.session_state["generated"][i], key=str(i), avatar_style="thumbs")
|